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

@ -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}
/>