From fd97576611ae80b959ffe7984e88ddc8d28a1ffc Mon Sep 17 00:00:00 2001 From: TC Date: Thu, 3 Dec 2020 22:29:46 +0100 Subject: [PATCH] Option to restart the app on config changes --- config/defaults.js | 1 + config/index.js | 5 ++++- index.js | 9 ++++++--- menu.js | 8 ++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index ad4e5772..df94cadf 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -11,6 +11,7 @@ const defaultConfig = { hideMenu: false, startAtLogin: false, disableHardwareAcceleration: false, + restartOnConfigChanges: false, }, plugins: { // Enabled plugins diff --git a/config/index.js b/config/index.js index 31f787e8..8b4e5c79 100644 --- a/config/index.js +++ b/config/index.js @@ -13,6 +13,9 @@ module.exports = { get, set, edit: () => store.openInEditor(), - watch: (cb) => store.onDidAnyChange(cb), + watch: (cb) => { + store.onDidChange("options", cb); + store.onDidChange("plugins", cb); + }, plugins, }; diff --git a/index.js b/index.js index fd35b2e0..bf3663ec 100644 --- a/index.js +++ b/index.js @@ -189,9 +189,12 @@ app.on("activate", () => { app.on("ready", () => { mainWindow = createMainWindow(); setApplicationMenu(mainWindow); - config.watch(() => { - setApplicationMenu(mainWindow); - }); + if (config.get("options.restartOnConfigChanges")) { + config.watch(() => { + app.relaunch(); + app.exit(); + }); + } setUpTray(app, mainWindow); // Autostart at login diff --git a/menu.js b/menu.js index 9107854f..6f932e49 100644 --- a/menu.js +++ b/menu.js @@ -50,6 +50,14 @@ const mainMenuTemplate = (win) => [ config.set("options.disableHardwareAcceleration", item.checked); }, }, + { + label: "Restart on config changes", + type: "checkbox", + checked: config.get("options.restartOnConfigChanges"), + click: (item) => { + config.set("options.restartOnConfigChanges", item.checked); + }, + }, ...(is.windows() || is.linux() ? [ {