Skip to content

Commit 0b63fcb

Browse files
Updates settings at runtime
1 parent 7a38188 commit 0b63fcb

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

client/pages/main/script.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require("fs");
44
const path = require("path");
55
const crypto = require("crypto");
66
const childProcess = require("child_process");
7-
const peer = new Peer(null, {
7+
let peer = new Peer(null, {
88
host: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerHostname : process.env.DEFAULT_PEER_SERVER_HOSTNAME,
99
port: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerPort : process.env.DEFAULT_PEER_SERVER_PORT,
1010
path: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerPath : process.env.DEFAULT_PEER_SERVER_PATH,
@@ -318,6 +318,13 @@ window.addEventListener("message", ({ data: { type, deviceId, deviceName, usageD
318318
type: "debugLogs",
319319
debugLogs
320320
});
321+
} else if (type === "customServer") {
322+
peer = new Peer(null, {
323+
host: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerHostname : process.env.DEFAULT_PEER_SERVER_HOSTNAME,
324+
port: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerPort : process.env.DEFAULT_PEER_SERVER_PORT,
325+
path: (Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerPath : process.env.DEFAULT_PEER_SERVER_PATH,
326+
secure: ((Object.keys(JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8"))).length) ? JSON.parse(fs.readFileSync(path.join(process.resourcesPath, "customServer.json"), "utf8")).peerProtocol : process.env.DEFAULT_PEER_SERVER_PROTOCOL) === "wss:"
327+
});
321328
};
322329
});
323330

client/pages/settings/script.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Array.from(document.getElementsByClassName("slider")).forEach((slider) => {
4444
autoUpdate: !slider.previousElementSibling.checked
4545
}
4646
}));
47+
ipcRenderer.send("updateSettings", {
48+
type: "autoUpdate",
49+
value: !slider.previousElementSibling.checked
50+
});
4751
} else if (slider.parentElement.dataset.type === "customServer") {
4852
if (!slider.previousElementSibling.checked) {
4953
try {
@@ -101,6 +105,12 @@ Array.from(document.getElementsByClassName("slider")).forEach((slider) => {
101105
customServer: true
102106
}
103107
}));
108+
ipcRenderer.send("updateSettings", {
109+
type: "customServer"
110+
});
111+
parent.postMessage({
112+
type: "customServer"
113+
});
104114
} catch {
105115
document.getElementsByClassName("slider")[3].click();
106116
fs.writeFileSync(path.join(parent.process.resourcesPath, "customServer.json"), "{}", "utf8");
@@ -128,6 +138,12 @@ Array.from(document.getElementsByClassName("slider")).forEach((slider) => {
128138
customServer: false
129139
}
130140
}));
141+
ipcRenderer.send("updateSettings", {
142+
type: "customServer"
143+
});
144+
parent.postMessage({
145+
type: "customServer"
146+
});
131147
};
132148
} else if (slider.parentElement.dataset.type === "debugMode") {
133149
localStorage.setItem("settings", JSON.stringify({

0 commit comments

Comments
 (0)