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() {
Start up @@ -84,7 +84,7 @@ export function SettingPage() { className: "-mt-5 mr-2", }} onChange={toggleStartUp} - defaultChecked={startUp} + defaultChecked={settingState.startUp} /> Automatic Update @@ -122,7 +122,7 @@ export function SettingPage() {
Minimize to Tray @@ -150,7 +150,7 @@ export function SettingPage() {
Analytic diff --git a/src/shared/constants/default-setting.contant.ts b/src/shared/constants/default-setting.contant.ts index 36c88d8..b3fad5a 100644 --- a/src/shared/constants/default-setting.contant.ts +++ b/src/shared/constants/default-setting.contant.ts @@ -2,6 +2,7 @@ import { SettingInStore } from "../interfaces/settings.interface"; export const defaultSetting: SettingInStore = { lng: "eng", + startUp: false, autoUpdate: true, minimize_tray: false, network_interface: "Auto", diff --git a/src/shared/interfaces/settings.interface.ts b/src/shared/interfaces/settings.interface.ts index 95f704e..913b170 100644 --- a/src/shared/interfaces/settings.interface.ts +++ b/src/shared/interfaces/settings.interface.ts @@ -10,7 +10,7 @@ export interface Settings { use_analytic: boolean; } -export interface SettingInStore extends Omit {} +export type SettingInStore = Settings; export type StoreKey = { dnsList: ServerStore[];