2022-02-17 18:09:57 +01:00
|
|
|
import AutoLaunch from "auto-launch";
|
2022-02-19 01:48:56 +01:00
|
|
|
import isDev from "electron-is-dev";
|
2022-02-17 18:09:57 +01:00
|
|
|
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
|
2022-02-19 01:48:56 +01:00
|
|
|
if (isAutoLaunchEnabled === undefined) {
|
2022-02-18 23:03:05 +01:00
|
|
|
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
|
|
|
};
|