partey_workadventure/desktop/electron/src/auto-launch.ts

36 lines
842 B
TypeScript
Raw Normal View History

2022-02-17 18:09:57 +01:00
import AutoLaunch from "auto-launch";
import { app } from "electron";
2022-02-22 10:05:21 +01:00
import electronIsDev from "electron-is-dev";
2022-02-17 18:09:57 +01:00
import settings from "./settings";
2022-02-22 10:05:21 +01:00
export async function updateAutoLaunch() {
2022-02-18 23:03:05 +01:00
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
// Don't run this in development
2022-02-22 10:05:21 +01:00
if (electronIsDev) {
2022-02-18 23:03:05 +01:00
return;
2022-02-17 18:09:57 +01:00
}
2022-02-18 23:03:05 +01:00
// `setLoginItemSettings` doesn't support linux
if (process.platform === "linux") {
const autoLauncher = new AutoLaunch({
name: "WorkAdventure",
isHidden: true,
});
if (isAutoLaunchEnabled) {
await autoLauncher.enable();
} else {
await autoLauncher.disable();
}
2022-02-17 18:09:57 +01:00
2022-02-18 23:03:05 +01:00
return;
}
app.setLoginItemSettings({
openAtLogin: isAutoLaunchEnabled,
openAsHidden: true,
});
2022-02-22 10:05:21 +01:00
}