diff --git a/src/main/ipc/setting.ts b/src/main/ipc/setting.ts index 75baed3..f0495d0 100644 --- a/src/main/ipc/setting.ts +++ b/src/main/ipc/setting.ts @@ -1,4 +1,4 @@ -import { ipcMain } from "electron"; +import { app, ipcMain } from "electron"; import { store } from "../store/store"; import { autoLauncher } from "../config"; import { EventsKeys } from "../../shared/constants/eventsKeys.constant"; @@ -9,26 +9,26 @@ ipcMain.handle(EventsKeys.SAVE_SETTINGS, function (event, data: Settings) { store.set("settings", data); return { success: true, data }; }); + ipcMain.handle(EventsKeys.TOGGLE_START_UP, async () => { - let startUp = await autoLauncher.isEnabled(); + try { + const setting = store.get("settings"); + + setting.startUp = !setting.startUp; //toggle + console.log(setting.startUp); + app.setLoginItemSettings({ + openAtLogin: setting.startUp, + path: app.getPath("exe"), + }); - if (startUp) { - await autoLauncher.disable(); - startUp = false; - } else { - await autoLauncher.enable(); - startUp = true; - } + store.set("settings", setting); - return startUp; + return setting.startUp; + } catch {} }); ipcMain.handle(EventsKeys.GET_SETTINGS, async () => { - const settings: Settings = { - startUp: false, - ...store.get("settings"), - }; - - settings.startUp = await autoLauncher.isEnabled(); + const settings: Settings = store.get("settings"); + console.log(settings); return settings; }); diff --git a/src/renderer/pages/setting.page.tsx b/src/renderer/pages/setting.page.tsx index d795fa5..8d0d457 100644 --- a/src/renderer/pages/setting.page.tsx +++ b/src/renderer/pages/setting.page.tsx @@ -66,7 +66,7 @@ export function SettingPage() {