mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor events
This commit is contained in:
parent
ae6edaa058
commit
6fdb591784
3 changed files with 52 additions and 46 deletions
|
@ -6,38 +6,11 @@ import { app } from "electron";
|
|||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
const sendEvent = (event: AppUpdaterEvents) => {
|
||||
WindowManager.splashWindow?.webContents.send("autoUpdaterEvent", event);
|
||||
};
|
||||
|
||||
autoUpdater
|
||||
.once("error", () => {
|
||||
sendEvent({ type: "error" });
|
||||
})
|
||||
.once("checking-for-update", () => {
|
||||
sendEvent({ type: "checking-for-updates" });
|
||||
})
|
||||
.once("update-not-available", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-not-available", info });
|
||||
})
|
||||
.once("update-available", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-available", info });
|
||||
})
|
||||
.once("update-downloaded", () => {
|
||||
sendEvent({ type: "update-downloaded" });
|
||||
})
|
||||
.addListener("download-progress", (info: ProgressInfo) => {
|
||||
sendEvent({ type: "download-progress", info });
|
||||
})
|
||||
.once("update-cancelled", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-cancelled", info });
|
||||
});
|
||||
|
||||
if (app.isPackaged) {
|
||||
autoUpdater.checkForUpdates();
|
||||
} else {
|
||||
// electron updater does not check for updates in dev build, so mocking here to test the ui
|
||||
const mockValuesForDebug = async () => {
|
||||
const sleep = (ms: number) =>
|
||||
new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
|
@ -47,7 +20,7 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
|||
sendEvent({
|
||||
type: "update-available",
|
||||
info: {
|
||||
version: "1.2.2",
|
||||
version: "1.2.3",
|
||||
files: [],
|
||||
releaseDate: "19/05/2024",
|
||||
path: "",
|
||||
|
@ -55,7 +28,7 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
|||
},
|
||||
});
|
||||
|
||||
await sleep(500);
|
||||
await sleep(1000);
|
||||
|
||||
const total = 123456;
|
||||
for (let i = 0; i <= 5; i++) {
|
||||
|
@ -73,6 +46,36 @@ const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
|||
}
|
||||
|
||||
sendEvent({ type: "update-downloaded" });
|
||||
};
|
||||
|
||||
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
autoUpdater
|
||||
.addListener("error", () => {
|
||||
sendEvent({ type: "error" });
|
||||
})
|
||||
.addListener("checking-for-update", () => {
|
||||
sendEvent({ type: "checking-for-updates" });
|
||||
})
|
||||
.addListener("update-not-available", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-not-available", info });
|
||||
})
|
||||
.addListener("update-available", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-available", info });
|
||||
})
|
||||
.addListener("update-downloaded", () => {
|
||||
sendEvent({ type: "update-downloaded" });
|
||||
})
|
||||
.addListener("download-progress", (info: ProgressInfo) => {
|
||||
sendEvent({ type: "download-progress", info });
|
||||
})
|
||||
.addListener("update-cancelled", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-cancelled", info });
|
||||
});
|
||||
|
||||
if (app.isPackaged) {
|
||||
autoUpdater.checkForUpdates();
|
||||
} else {
|
||||
await mockValuesForDebug();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { WindowManager } from "@main/services";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
|
||||
const continueToMainWindow = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
autoUpdater.removeAllListeners();
|
||||
WindowManager.splashWindow?.close();
|
||||
WindowManager.createMainWindow();
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
|
|||
if (app.isPackaged) {
|
||||
autoUpdater.quitAndInstall(true, true);
|
||||
} else {
|
||||
autoUpdater.removeAllListeners();
|
||||
WindowManager.splashWindow?.close();
|
||||
WindowManager.createMainWindow();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue