fix: add script to auto launch hydra on startup

This commit is contained in:
Zamitto 2024-06-27 18:50:18 -03:00
parent 82f72071f9
commit 9c99e56b70
3 changed files with 35 additions and 6 deletions

3
resources/hydra.vbs Normal file
View File

@ -0,0 +1,3 @@
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run """%localappdata%\Programs\Hydra\Hydra.exe""", 0 'Must quote command if it has spaces; must escape quotes
Set WshShell = Nothing

View File

@ -14,3 +14,12 @@ export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");
export const seedsPath = app.isPackaged
? path.join(process.resourcesPath, "seeds")
: path.join(__dirname, "..", "..", "seeds");
export const windowsStartupPath = path.join(
app.getPath("appData"),
"Microsoft",
"Windows",
"Start Menu",
"Programs",
"Startup"
);

View File

@ -1,18 +1,35 @@
import { windowsStartupPath } from "@main/constants";
import { registerEvent } from "../register-event";
import AutoLaunch from "auto-launch";
import { app } from "electron";
import fs from "node:fs";
import path from "node:path";
const autoLaunch = async (
_event: Electron.IpcMainInvokeEvent,
enabled: boolean
) => {
const appLauncher = new AutoLaunch({
name: app.getName(),
});
if (enabled) {
appLauncher.enable().catch();
if (!app.isPackaged) return;
if (process.platform == "win32") {
const destination = path.join(windowsStartupPath, "hydra.vbs");
if (enabled) {
const scriptPath = path.join(process.resourcesPath, "hydra.vbs");
fs.copyFileSync(scriptPath, destination);
} else {
fs.rmSync(destination);
}
} else {
appLauncher.disable().catch();
const appLauncher = new AutoLaunch({
name: app.getName(),
});
if (enabled) {
appLauncher.enable().catch();
} else {
appLauncher.disable().catch();
}
}
};