fix: App Autostart (#68)
Signed-off-by: Mihai <cristian@mihaimuresan.com> Co-authored-by: Mihai <cristian@mihaimuresan.com>
This commit is contained in:
+16
-12
@@ -8,16 +8,20 @@ export const autoLaunch = new AutoLaunch({
|
||||
name: "Stoat",
|
||||
});
|
||||
|
||||
ipcMain.on("isAutostart?", () =>
|
||||
autoLaunch
|
||||
.isEnabled()
|
||||
.then((enabled) => mainWindow.webContents.send("isAutostart", enabled)),
|
||||
);
|
||||
|
||||
ipcMain.on("setAutostart", (_event, state: boolean) => {
|
||||
if (state) {
|
||||
autoLaunch.enable();
|
||||
} else {
|
||||
autoLaunch.disable();
|
||||
}
|
||||
ipcMain.handle("getAutostart", async () => {
|
||||
const enabled = await autoLaunch.isEnabled();
|
||||
return enabled;
|
||||
});
|
||||
|
||||
ipcMain.handle("setAutostart", async (_event, state: boolean) => {
|
||||
if (state) {
|
||||
await autoLaunch.enable();
|
||||
console.log("Received new configuration autoStart: true");
|
||||
} else {
|
||||
await autoLaunch.disable();
|
||||
console.log("Received new configuration autoStart: false");
|
||||
}
|
||||
|
||||
const enabled = await autoLaunch.isEnabled();
|
||||
return enabled;
|
||||
});
|
||||
|
||||
+2
-3
@@ -8,10 +8,9 @@ contextBridge.exposeInMainWorld("desktopConfig", {
|
||||
get: () => config,
|
||||
set: (config: DesktopConfig) => ipcRenderer.send("config", config),
|
||||
getAutostart() {
|
||||
ipcRenderer.send("isAutostart?");
|
||||
return new Promise((resolve) => ipcRenderer.once("isAutostart", resolve));
|
||||
return ipcRenderer.invoke("getAutostart") as Promise<boolean>;
|
||||
},
|
||||
setAutostart(value: boolean) {
|
||||
ipcRenderer.send("setAutostart", value);
|
||||
return ipcRenderer.invoke("setAutostart", value) as Promise<boolean>;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user