From 1e836ee7f8d4670208e276912faf5c7d1fc1ad0f Mon Sep 17 00:00:00 2001 From: sekwah Date: Sun, 19 Nov 2023 23:11:21 +0000 Subject: [PATCH] fix(tauri): avoid setting open at login if already set --- .../contexts/connectors/TauriConnector.tsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) 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