mirror of
https://github.com/cryptoadvance/specter-desktop.git
synced 2026-08-13 12:33:29 +02:00
Bugfix: Broken save button in Electron preferences (#2223)
This commit is contained in:
parent
69c836bd04
commit
89fc5649f3
2 changed files with 202 additions and 2 deletions
|
|
@ -19,6 +19,10 @@ const getDownloadLocation = downloadloc.getDownloadLocation
|
|||
const appName = downloadloc.appName()
|
||||
const appNameLower = appName.toLowerCase()
|
||||
|
||||
ipcMain.handle("showMessageBoxSync", (e, message, buttons) => {
|
||||
dialog.showMessageBoxSync(mainWindow, { message, buttons });
|
||||
});
|
||||
|
||||
// Helper
|
||||
const isMac = process.platform === 'darwin'
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,203 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<script src="./settings.js"/>
|
||||
|
||||
<script>
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { ipcRenderer } = require("electron");
|
||||
const helpers = require("./helpers");
|
||||
const getFileHash = helpers.getFileHash;
|
||||
const getAppSettings = helpers.getAppSettings;
|
||||
const appSettingsPath = helpers.appSettingsPath;
|
||||
const specterdDirPath = helpers.specterdDirPath;
|
||||
|
||||
function toggleAdvanced() {
|
||||
let advancedButton = document.getElementById("toggle_advanced");
|
||||
let advancedSettigns =
|
||||
document.getElementById("advanced_settings");
|
||||
if (advancedSettigns.style.display === "block") {
|
||||
advancedSettigns.style.display = "none";
|
||||
advancedButton.innerHTML = "Advanced ▶";
|
||||
if (isCoinSelectionActive()) {
|
||||
toggleExpand();
|
||||
}
|
||||
} else {
|
||||
advancedSettigns.style.display = "block";
|
||||
advancedButton.innerHTML = "Advanced ▼";
|
||||
}
|
||||
}
|
||||
|
||||
function toggleHWIBridgeView(isActive) {
|
||||
document.getElementById("hwibridge-mode-active").checked =
|
||||
isActive;
|
||||
document.getElementById(
|
||||
"hwibridge-mode-settings"
|
||||
).style.display = isActive ? "block" : "none";
|
||||
}
|
||||
|
||||
function signalSavePreferences() {
|
||||
ipcRenderer.send("request-mainprocess-action", {
|
||||
message: "save-preferences",
|
||||
});
|
||||
}
|
||||
|
||||
function savePreferences() {
|
||||
let specterdFile =
|
||||
document.getElementById("specterd-file").files[0];
|
||||
if (specterdFile) {
|
||||
let specterdPath = path.resolve(
|
||||
specterdDirPath,
|
||||
"specterd" +
|
||||
(specterdFile.path.endsWith(".exe") ? ".exe" : "")
|
||||
);
|
||||
fs.copyFileSync(specterdFile.path, specterdPath);
|
||||
} else if (
|
||||
document.getElementById("download-github-version-checkbox")
|
||||
.checked
|
||||
) {
|
||||
let specterdPath = path.resolve(
|
||||
specterdDirPath,
|
||||
"specterd" + (process.platform == "win32" ? ".exe" : "")
|
||||
);
|
||||
if (fs.existsSync(specterdPath)) {
|
||||
fs.unlinkSync(specterdPath);
|
||||
}
|
||||
document.getElementById("specterd-hash").value = "";
|
||||
}
|
||||
let hwiBridgeMode = document.getElementById(
|
||||
"hwibridge-mode-active"
|
||||
).checked;
|
||||
let remoteSpecterURL =
|
||||
document.getElementById("specter-url").value;
|
||||
if (hwiBridgeMode) {
|
||||
let hwiBridgeSettingsPath = path.resolve(
|
||||
require("os").homedir(),
|
||||
".specter/hwi_bridge_config.json"
|
||||
);
|
||||
let defaultHWIBridgeSettings = {
|
||||
whitelisted_domains: "http://127.0.0.1:25441/",
|
||||
};
|
||||
try {
|
||||
fs.writeFileSync(
|
||||
hwiBridgeSettingsPath,
|
||||
JSON.stringify(defaultHWIBridgeSettings),
|
||||
{ flag: "wx" }
|
||||
);
|
||||
} catch {
|
||||
// settings file already exists
|
||||
}
|
||||
let hwiBridgeSettings = require(hwiBridgeSettingsPath);
|
||||
if (hwiBridgeSettings) {
|
||||
hwiBridgeSettings.whitelisted_domains += `\n${remoteSpecterURL}`;
|
||||
}
|
||||
fs.writeFileSync(
|
||||
hwiBridgeSettingsPath,
|
||||
JSON.stringify(hwiBridgeSettings)
|
||||
);
|
||||
}
|
||||
let appSettings = getAppSettings();
|
||||
appSettings.mode = hwiBridgeMode ? "hwibridge" : "specterd";
|
||||
appSettings.specterURL = hwiBridgeMode
|
||||
? remoteSpecterURL
|
||||
: "http://localhost:25441";
|
||||
appSettings.basicAuth = document.getElementById(
|
||||
"basic-auth-checkbox"
|
||||
).checked;
|
||||
appSettings.basicAuthUser =
|
||||
document.getElementById("basic-auth-user").value;
|
||||
appSettings.basicAuthPass =
|
||||
document.getElementById("basic-auth-pass").value;
|
||||
appSettings.tor =
|
||||
document.getElementById("tor-checkbox").checked;
|
||||
appSettings.proxyURL =
|
||||
document.getElementById("proxy-url").value;
|
||||
appSettings.specterdVersion =
|
||||
document.getElementById("specterd-version").value;
|
||||
appSettings.specterdHash =
|
||||
document.getElementById("specterd-hash").value;
|
||||
appSettings.specterdCLIArgs =
|
||||
document.getElementById("specterd-cli-args").value;
|
||||
fs.writeFileSync(appSettingsPath, JSON.stringify(appSettings));
|
||||
ipcRenderer.invoke("showMessageBoxSync", "Specter settings were saved successfully!\nPlease reopen the app to activate the changes.", ["Continue"]);
|
||||
ipcRenderer.send("request-mainprocess-action", {
|
||||
message: "quit-app",
|
||||
});
|
||||
}
|
||||
|
||||
function toggleBasicAuth(basicAuthOn) {
|
||||
if (basicAuthOn) {
|
||||
document
|
||||
.getElementById("basic-auth-user")
|
||||
.classList.remove("hidden");
|
||||
document
|
||||
.getElementById("basic-auth-pass")
|
||||
.classList.remove("hidden");
|
||||
} else {
|
||||
document
|
||||
.getElementById("basic-auth-user")
|
||||
.classList.add("hidden");
|
||||
document
|
||||
.getElementById("basic-auth-pass")
|
||||
.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTorProxy(torOn) {
|
||||
if (torOn) {
|
||||
document
|
||||
.getElementById("proxy-url")
|
||||
.classList.remove("hidden");
|
||||
} else {
|
||||
document
|
||||
.getElementById("proxy-url")
|
||||
.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
let appSettings = getAppSettings();
|
||||
let hwiBridgeMode = appSettings.mode == "hwibridge";
|
||||
if (hwiBridgeMode) {
|
||||
document.getElementById("specter-url").value =
|
||||
appSettings.specterURL;
|
||||
}
|
||||
document.getElementById("basic-auth-user").value =
|
||||
appSettings.basicAuthUser;
|
||||
document.getElementById("basic-auth-pass").value =
|
||||
appSettings.basicAuthPass;
|
||||
document.getElementById("basic-auth-checkbox").checked =
|
||||
appSettings.basicAuth;
|
||||
toggleBasicAuth(appSettings.basicAuth);
|
||||
document.getElementById("proxy-url").value =
|
||||
appSettings.proxyURL;
|
||||
document.getElementById("tor-checkbox").checked =
|
||||
appSettings.tor;
|
||||
toggleTorProxy(appSettings.tor);
|
||||
document.getElementById("specterd-version").value =
|
||||
appSettings.specterdVersion;
|
||||
document.getElementById("specterd-hash").value =
|
||||
appSettings.specterdHash;
|
||||
document.getElementById("specterd-cli-args").value =
|
||||
appSettings.specterdCLIArgs;
|
||||
|
||||
toggleHWIBridgeView(hwiBridgeMode);
|
||||
document
|
||||
.getElementById("specterd-file")
|
||||
.addEventListener("change", (e) => {
|
||||
let specterdFile =
|
||||
document.getElementById("specterd-file").files[0];
|
||||
if (specterdFile) {
|
||||
getFileHash(
|
||||
specterdFile.path,
|
||||
function (specterdHash) {
|
||||
document.getElementById(
|
||||
"specterd-hash"
|
||||
).value = specterdHash;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue