diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index b6d1b882..ccc31520 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -138,7 +138,8 @@ "telemetry": "Telemetry", "telemetry_description": "Enable anonymous usage statistics", "behavior": "Behavior", - "quit_app_instead_hiding": "Close app instead of minimizing to tray" + "quit_app_instead_hiding": "Close app instead of minimizing to tray", + "launch_with_system": "Launch app on system start-up" }, "notifications": { "download_complete": "Download complete", diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index fce8eb36..c5e66c02 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -134,7 +134,8 @@ "telemetry": "Telemetria", "telemetry_description": "Habilitar estatísticas de uso anônimas", "behavior": "Comportamento", - "quit_app_instead_hiding": "Fechar o aplicativo em vez de minimizá-lo" + "quit_app_instead_hiding": "Fechar o aplicativo em vez de minimizá-lo", + "launch_with_system": "Iniciar aplicativo na inicialização do sistema" }, "notifications": { "download_complete": "Download concluído", diff --git a/src/main/events/index.ts b/src/main/events/index.ts index 1a08f636..822cb9d5 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -26,6 +26,7 @@ import "./torrenting/resume-game-download"; import "./torrenting/start-game-download"; import "./user-preferences/get-user-preferences"; import "./user-preferences/update-user-preferences"; +import "./user-preferences/auto-launch"; ipcMain.handle("ping", () => "pong"); ipcMain.handle("getVersion", () => app.getVersion()); diff --git a/src/main/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts new file mode 100644 index 00000000..5687f59d --- /dev/null +++ b/src/main/events/user-preferences/auto-launch.ts @@ -0,0 +1,24 @@ +import { registerEvent } from "../register-event"; +import AutoLaunch from "auto-launch"; + +const autoLaunch = async ( + _event: Electron.IpcMainInvokeEvent, + enabled: boolean +) => { + const appLauncher = new AutoLaunch({ + name: "Hydra", + }); + if (enabled) { + appLauncher + .enable() + .catch((err) => console.error("Error enabling auto-launch:", err)); + } else { + appLauncher + .disable() + .catch((err) => console.error("Error disabling auto-launch:", err)); + } +}; + +registerEvent(autoLaunch, { + name: "autoLaunch", +}); diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index 26e38813..51163f1a 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -48,6 +48,7 @@ contextBridge.exposeInMainWorld("electron", { getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), updateUserPreferences: (preferences: UserPreferences) => ipcRenderer.invoke("updateUserPreferences", preferences), + autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled), /* Library */ addGameToLibrary: ( diff --git a/src/preload/index.ts b/src/preload/index.ts index 948c1e8a..7d5eb7fe 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -57,6 +57,7 @@ contextBridge.exposeInMainWorld("electron", { getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), updateUserPreferences: (preferences: UserPreferences) => ipcRenderer.invoke("updateUserPreferences", preferences), + autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled), /* Library */ addGameToLibrary: ( diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 5ea29ca5..c20afe66 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -74,6 +74,7 @@ declare global { updateUserPreferences: ( preferences: Partial ) => Promise; + autoLaunch: (enabled: boolean) => Promise; /* Hardware */ getDiskFreeSpace: (path: string) => Promise; diff --git a/src/renderer/src/pages/settings/auto-launch.ts b/src/renderer/src/pages/settings/auto-launch.ts deleted file mode 100644 index 0d6eea81..00000000 --- a/src/renderer/src/pages/settings/auto-launch.ts +++ /dev/null @@ -1,22 +0,0 @@ -import AutoLaunch from "auto-launch"; - -export const autoLaunch = () => { - Promise.all([window.electron.getUserPreferences()]).then( - (userPreferences) => { - if (userPreferences && userPreferences.length > 0) { - const appLauncher = new AutoLaunch({ - name: "Hydra", - }); - if (userPreferences[0]?.startWithSystem) { - appLauncher - .enable() - .catch((err) => console.error("Error enabling auto-launch:", err)); - } else { - appLauncher - .disable() - .catch((err) => console.error("Error disabling auto-launch:", err)); - } - } - } - ); -}; diff --git a/src/renderer/src/pages/settings/settings.tsx b/src/renderer/src/pages/settings/settings.tsx index e1a95b20..fe1c744c 100644 --- a/src/renderer/src/pages/settings/settings.tsx +++ b/src/renderer/src/pages/settings/settings.tsx @@ -4,7 +4,6 @@ import { Button, CheckboxField, TextField } from "@renderer/components"; import * as styles from "./settings.css"; import { useTranslation } from "react-i18next"; import { UserPreferences } from "@types"; -// import { autoLaunch } from "./auto-launch"; export function Settings() { const [form, setForm] = useState({ @@ -128,10 +127,10 @@ export function Settings() { /> { updateUserPreferences("startWithSystem", !form.startWithSystem); - // autoLaunch(); + window.electron.autoLaunch(!form.startWithSystem); }} checked={form.startWithSystem} />