partey_workadventure/desktop/src/update-auto-launch.ts
2022-02-19 01:48:56 +01:00

42 lines
982 B
TypeScript

import AutoLaunch from "auto-launch";
import isDev from "electron-is-dev";
import { app } from "electron";
import settings from "./settings";
export default async () => {
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
// set default to enabled
if (isAutoLaunchEnabled === undefined) {
settings.set("auto_launch_enabled", true);
isAutoLaunchEnabled = true;
}
// Don't run this in development
if (isDev) {
return;
}
// `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();
}
return;
}
app.setLoginItemSettings({
openAtLogin: isAutoLaunchEnabled,
openAsHidden: true,
});
};