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

42 lines
982 B
TypeScript
Raw Normal View History

2022-02-17 18:09:57 +01:00
import AutoLaunch from "auto-launch";
import * as isDev from "electron-is-dev";
import { app } from "electron";
import settings from "./settings";
export default async () => {
2022-02-18 23:03:05 +01:00
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
// set default to enabled
if (isAutoLaunchEnabled === null) {
settings.set("auto_launch_enabled", true);
isAutoLaunchEnabled = true;
}
2022-02-17 18:09:57 +01:00
2022-02-18 23:03:05 +01:00
// Don't run this in development
if (isDev) {
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-17 18:09:57 +01:00
};