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

36 lines
844 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-22 20:07:36 +01:00
const isAutoLaunchEnabled = settings.get("auto_launch_enabled");
2022-02-18 23:03:05 +01:00
// 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
}