feat: refactors

This commit is contained in:
Zamitto
2024-05-31 15:03:29 -03:00
parent 45f30a9208
commit 2038bd1fbe
6 changed files with 72 additions and 34 deletions

View File

@@ -10,8 +10,11 @@ const sendEvent = (event: AppUpdaterEvents) => {
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
};
const sendEventsForDebug = false;
const mockValuesForDebug = () => {
sendEvent({ type: "update-available", info: { version: "1.3.0" } });
sendEvent({ type: "update-downloaded" });
};
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
@@ -19,15 +22,9 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
sendEvent({ type: "update-available", info });
});
if (process.platform !== "darwin") {
autoUpdater.once("update-downloaded", () => {
sendEvent({ type: "update-downloaded" });
});
}
if (app.isPackaged) {
autoUpdater.checkForUpdates();
} else {
} else if (sendEventsForDebug) {
mockValuesForDebug();
}
};

View File

@@ -1,18 +1,13 @@
import { app } from "electron";
import { registerEvent } from "../register-event";
import updater from "electron-updater";
import { releasesPageUrl } from "@main/constants";
const { autoUpdater } = updater;
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
autoUpdater.removeAllListeners();
if (app.isPackaged) {
if (process.platform === "darwin") {
open(`${releasesPageUrl}`);
} else {
autoUpdater.quitAndInstall(true, true);
}
autoUpdater.quitAndInstall(true, true);
}
};