Files
kopia/app/public/auto-launch.js
Jarek Kowalski 2e16917518 chore(ci): enforce consistent formatting of KopiaUI code (#4586)
* chore(ci): enforce consistent formatting of KopiaUI code

* fix htmlui_changelog.sh

* fix
2025-05-20 22:33:54 -07:00

51 lines
1.0 KiB
JavaScript

import { ipcMain } from "electron";
import log from "electron-log";
import AutoLaunch from "auto-launch";
const autoLauncher = new AutoLaunch({
name: "Kopia",
mac: {
useLaunchAgent: true,
},
});
let enabled = false;
export function willLaunchAtStartup() {
return enabled;
}
export function toggleLaunchAtStartup() {
if (enabled) {
log.info("disabling autorun");
autoLauncher
.disable()
.then(() => {
enabled = false;
ipcMain.emit("launch-at-startup-updated");
})
.catch((err) => log.info(err));
} else {
log.info("enabling autorun");
autoLauncher
.enable()
.then(() => {
enabled = true;
ipcMain.emit("launch-at-startup-updated");
})
.catch((err) => log.info(err));
}
}
export function refreshWillLaunchAtStartup() {
autoLauncher
.isEnabled()
.then((isEnabled) => {
enabled = isEnabled;
ipcMain.emit("launch-at-startup-updated");
})
.catch(function (err) {
log.info("unable to get autoLauncher state", err);
});
}