mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 13:56:16 +00:00
37 lines
914 B
TypeScript
37 lines
914 B
TypeScript
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
|
|
) => {
|
|
if (!app.isPackaged) return;
|
|
|
|
if (process.platform == "win32") {
|
|
const destination = path.join(windowsStartupPath, "hydralauncher.vbs");
|
|
|
|
if (enabled) {
|
|
const scriptPath = path.join(process.resourcesPath, "hydralauncher.vbs");
|
|
|
|
fs.copyFileSync(scriptPath, destination);
|
|
} else {
|
|
fs.rmSync(destination);
|
|
}
|
|
} else {
|
|
const appLauncher = new AutoLaunch({
|
|
name: app.getName(),
|
|
});
|
|
if (enabled) {
|
|
appLauncher.enable().catch();
|
|
} else {
|
|
appLauncher.disable().catch();
|
|
}
|
|
}
|
|
};
|
|
|
|
registerEvent("autoLaunch", autoLaunch);
|