Skip to content

Commit

Permalink
fixed: Startup #66
Browse files Browse the repository at this point in the history
  • Loading branch information
sajjadmrx committed Jan 28, 2024
1 parent 02cc28c commit 80d9d2c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
32 changes: 16 additions & 16 deletions src/main/ipc/setting.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
});
10 changes: 5 additions & 5 deletions src/renderer/pages/setting.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function SettingPage() {
<div>
<Typography
color="blue-gray"
className="font-medium dark:text-white font-[Inter] flex flex-row items-center gap-1"
className="font-medium dark:text-gray-400 font-[Inter] flex flex-row items-center gap-2"
>
<VscRunAbove />
Start up
Expand All @@ -84,7 +84,7 @@ export function SettingPage() {
className: "-mt-5 mr-2",
}}
onChange={toggleStartUp}
defaultChecked={startUp}
defaultChecked={settingState.startUp}
/>
<Switch
id={"autoUP"}
Expand All @@ -94,7 +94,7 @@ export function SettingPage() {
<div>
<Typography
color="blue-gray"
className="font-medium dark:text-white font-[Inter] flex flex-row items-center gap-1"
className="font-medium dark:text-gray-400 font-[Inter] flex flex-row items-center gap-2"
>
<MdBrowserUpdated />
Automatic Update
Expand Down Expand Up @@ -122,7 +122,7 @@ export function SettingPage() {
<div>
<Typography
color="blue-gray"
className="font-medium dark:text-white font-[Inter] flex flex-row items-center gap-1"
className="font-medium dark:text-gray-400 font-[Inter] flex flex-row items-center gap-2"
>
<TbWindowMinimize />
Minimize to Tray
Expand Down Expand Up @@ -150,7 +150,7 @@ export function SettingPage() {
<div>
<Typography
color="blue-gray"
className="font-medium dark:text-white font-[Inter] flex flex-row items-center gap-1"
className="font-medium dark:text-gray-400 font-[Inter] flex flex-row items-center gap-2"
>
<MdBugReport />
Analytic
Expand Down
1 change: 1 addition & 0 deletions src/shared/constants/default-setting.contant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/shared/interfaces/settings.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Settings {
use_analytic: boolean;
}

export interface SettingInStore extends Omit<Settings, "startUp"> {}
export type SettingInStore = Settings;

export type StoreKey = {
dnsList: ServerStore[];
Expand Down

0 comments on commit 80d9d2c

Please sign in to comment.