From 9e020652c9b177564099dce5bb5f6be155f5f8f7 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 15:38:17 -0300 Subject: [PATCH] feat: implement launch minimized option --- src/main/events/user-preferences/auto-launch.ts | 5 +++-- src/preload/index.ts | 3 ++- src/renderer/src/declaration.d.ts | 4 +++- src/renderer/src/pages/settings/settings-behavior.tsx | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts index 1f4f9cc3..0b1bba21 100644 --- a/src/main/events/user-preferences/auto-launch.ts +++ b/src/main/events/user-preferences/auto-launch.ts @@ -16,15 +16,16 @@ const windowsStartupPath = path.join( const autoLaunch = async ( _event: Electron.IpcMainInvokeEvent, - enabled: boolean + autoLaunchProps: { enabled: boolean; minimized: boolean } ) => { if (!app.isPackaged) return; const appLauncher = new AutoLaunch({ name: app.getName(), + isHidden: autoLaunchProps.minimized, }); - if (enabled) { + if (autoLaunchProps.enabled) { appLauncher.enable().catch((err) => { logger.error(err); }); diff --git a/src/preload/index.ts b/src/preload/index.ts index 90c50763..9baa8325 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -101,7 +101,8 @@ contextBridge.exposeInMainWorld("electron", { getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), updateUserPreferences: (preferences: UserPreferences) => ipcRenderer.invoke("updateUserPreferences", preferences), - autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled), + autoLaunch: (autoLaunchProps: { enabled: boolean; minimized: boolean }) => + ipcRenderer.invoke("autoLaunch", autoLaunchProps), authenticateRealDebrid: (apiToken: string) => ipcRenderer.invoke("authenticateRealDebrid", apiToken), diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 929b00e9..a639bd15 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -114,7 +114,9 @@ declare global { updateUserPreferences: ( preferences: Partial ) => Promise; - autoLaunch: (enabled: boolean) => Promise; + autoLaunch: ( + autoLaunchProps: { enabled?: boolean; minimized?: boolean } + ) => Promise; authenticateRealDebrid: (apiToken: string) => Promise; /* Download sources */ diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index aabbe27d..c0be02d6 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -62,7 +62,7 @@ export function SettingsBehavior() { label={t("launch_with_system")} onChange={() => { handleChange({ runAtStartup: !form.runAtStartup }); - window.electron.autoLaunch(!form.runAtStartup); + window.electron.autoLaunch({ enabled: !form.runAtStartup }); }} checked={form.runAtStartup} /> @@ -77,6 +77,7 @@ export function SettingsBehavior() { disabled={!form.runAtStartup} onChange={() => { handleChange({ startMinimized: !form.startMinimized }); + window.electron.autoLaunch({ minimized: !form.startMinimized }); }} />