diff --git a/.nvmrc b/.nvmrc index b6a7d89c..3c032078 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16 +18 diff --git a/app/electron/src/main.ts b/app/electron/src/main.ts index b7bd3603..a0735f5b 100644 --- a/app/electron/src/main.ts +++ b/app/electron/src/main.ts @@ -442,11 +442,16 @@ ipcMain.on(TRAY_ICON_UPDATE, (e, dataUrl) => { }); ipcMain.on(SET_OPEN_AT_LOGIN, (e, { openAtLogin }) => { - store.safeSet("openAtLogin", openAtLogin); - app.setLoginItemSettings({ - openAtLogin: openAtLogin, - openAsHidden: openAtLogin, - }); + const storeOpenAtLogin = store.safeGet("openAtLogin"); + + if (storeOpenAtLogin !== openAtLogin) { + store.safeSet("openAtLogin", openAtLogin); + + app.setLoginItemSettings({ + openAtLogin: openAtLogin, + openAsHidden: openAtLogin, + }); + } }); app.on("window-all-closed", () => { diff --git a/app/renderer/src/contexts/connectors/TauriConnector.tsx b/app/renderer/src/contexts/connectors/TauriConnector.tsx index 7200ae49..a4c7be93 100644 --- a/app/renderer/src/contexts/connectors/TauriConnector.tsx +++ b/app/renderer/src/contexts/connectors/TauriConnector.tsx @@ -93,17 +93,25 @@ export const TauriConnectorProvider: React.FC = ({ children }) => { }, []); useEffect(() => { - if (settings.openAtLogin) { - enable().catch((err) => console.error(err)); - } else { - // The autostart-plugin fails when trying to disble if it is already disabled - // https://github.com/tauri-apps/plugins-workspace/issues/24#issuecomment-1528958008 - isEnabled() - .then((enabled) => { - if (enabled) disable().catch((err) => console.error(err)); - }) - .catch((err) => console.error(err)); - } + // The autostart-plugin fails when trying to disble if it is already disabled + // https://github.com/tauri-apps/plugins-workspace/issues/24#issuecomment-1528958008 + isEnabled().then((enabled) => { + if (settings.openAtLogin) { + if (!enabled) + enable() + .then(() => { + console.log("Enabled autostart"); + }) + .catch((err) => console.error(err)); + } else { + if (enabled) + disable() + .then(() => { + console.log("Disabled autostart"); + }) + .catch((err) => console.error(err)); + } + }); }, [settings.openAtLogin]); // TODO do logic to switch out the connectors based on the platform