added option to start hydra on system startup

This commit is contained in:
Hachi-R 2024-05-05 18:13:28 -03:00
parent 5b9af9e0ea
commit 970a3be280
9 changed files with 34 additions and 27 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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());

View file

@ -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",
});

View file

@ -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: (

View file

@ -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: (

View file

@ -74,6 +74,7 @@ declare global {
updateUserPreferences: (
preferences: Partial<UserPreferences>
) => Promise<void>;
autoLaunch: (enabled: boolean) => Promise<void>;
/* Hardware */
getDiskFreeSpace: (path: string) => Promise<DiskSpace>;

View file

@ -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));
}
}
}
);
};

View file

@ -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() {
/>
<CheckboxField
label={"autoLaunch"}
label={t("launch_with_system")}
onChange={() => {
updateUserPreferences("startWithSystem", !form.startWithSystem);
// autoLaunch();
window.electron.autoLaunch(!form.startWithSystem);
}}
checked={form.startWithSystem}
/>