diff --git a/dev-app-update.yml b/dev-app-update.yml index 1155344..90bc5d9 100644 --- a/dev-app-update.yml +++ b/dev-app-update.yml @@ -1,4 +1,4 @@ owner: Tom4nt repo: Mega-Soundboard provider: github -updaterCacheDirName: mega-soundboard-updater \ No newline at end of file +updaterCacheDirName: mega-soundboard-updater diff --git a/src/main/updater.ts b/src/main/updater.ts index 25fd0d5..2b19514 100644 --- a/src/main/updater.ts +++ b/src/main/updater.ts @@ -16,7 +16,17 @@ export default class Updater { autoUpdater.on("update-downloaded", () => { this._state = "downloaded"; - EventSender.send("onUpdateReady"); + EventSender.send("onUpdateStateChanged", "downloaded"); + }); + + autoUpdater.on("update-available", () => { + this._state = "downloading"; + EventSender.send("onUpdateStateChanged", "downloading"); + }); + + autoUpdater.on("update-not-available", () => { + this._state = "upToDate"; + EventSender.send("onUpdateStateChanged", "upToDate"); }); const hour = 60 * 60 * 1000; @@ -29,12 +39,8 @@ export default class Updater { if (this._state === "downloading" || this._state === "downloaded") { return this.state; } - const result = await autoUpdater.checkForUpdates(); - if (result) { - this._state = "downloading"; - } else { - this._state = "upToDate"; - } - return this.state; + await autoUpdater.checkForUpdates(); + // FWIK, there is no way to get if the update is available or not from the return value. + return this.state; // The state is updated on the event handlers instead. } } diff --git a/src/renderer/index.ts b/src/renderer/index.ts index ee311a8..1da3a32 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -8,6 +8,7 @@ import AudioManager from "./audioManager"; import GlobalEvents from "./util/globalEvents"; import * as MessageQueue from "./messageQueue"; import Utils from "./util/utils"; +import { UpdaterState } from "../shared/interfaces"; //#region Elements @@ -366,9 +367,11 @@ function showSoundDragTutorial(): void { //#region Main Events -GlobalEvents.addHandler("onUpdateReady", () => { - updateButton.style.display = "inherit"; - console.log("READY TO UPDATE"); +GlobalEvents.addHandler("onUpdateStateChanged", (state: UpdaterState) => { + if (state == "downloaded") { + updateButton.style.display = "inherit"; + console.log("READY TO UPDATE"); + } }); GlobalEvents.addHandler("onWindowFocusChanged", s => { diff --git a/src/renderer/modals/msModal.ts b/src/renderer/modals/msModal.ts index 30f2d65..5477ae6 100644 --- a/src/renderer/modals/msModal.ts +++ b/src/renderer/modals/msModal.ts @@ -1,3 +1,4 @@ +import { UpdaterState } from "../../shared/interfaces"; import { Modal, NewsModal } from "../modals"; import GlobalEvents from "../util/globalEvents"; @@ -22,7 +23,7 @@ export default class MSModal extends Modal { protected override disconnectedCallback(): void { super.disconnectedCallback(); if (this.isListeningToUpdateReady) - GlobalEvents.removeHandler("onUpdateReady", this.handleUpdateReady); + GlobalEvents.removeHandler("onUpdateStateChanged", this.handleUpdateStateChanged); } getContent(): HTMLElement[] { @@ -90,13 +91,14 @@ export default class MSModal extends Modal { } private async checkUpdate(): Promise { - const state = await window.actions.checkUpdate(); + this.updateInfoElement.innerText = "Checking..."; this.updateInfoElement.style.display = ""; + const state = await window.actions.checkUpdate(); switch (state) { case "downloading": this.updateInfoElement.innerText = "The update is being downloaded..."; if (!this.isListeningToUpdateReady) - GlobalEvents.addHandler("onUpdateReady", this.handleUpdateReady); + GlobalEvents.addHandler("onUpdateStateChanged", this.handleUpdateStateChanged); this.isListeningToUpdateReady = true; break; case "downloaded": @@ -118,8 +120,10 @@ export default class MSModal extends Modal { this.updateButton.innerHTML = "Restart"; } - private handleUpdateReady = (): void => { - this.isUpdateReady = true; - this.showUpdateReady(); + private handleUpdateStateChanged = (state: UpdaterState): void => { + if (state == "downloaded") { + this.isUpdateReady = true; + this.showUpdateReady(); + } }; } diff --git a/src/shared/ipcEvents.ts b/src/shared/ipcEvents.ts index 0cb1e55..5be5153 100644 --- a/src/shared/ipcEvents.ts +++ b/src/shared/ipcEvents.ts @@ -5,6 +5,7 @@ import { SoundAddedArgs, SoundboardAddedArgs, SoundChangedArgs, + UpdaterState, WindowState } from "./interfaces"; import { Settings, Sound, Soundboard } from "./models"; @@ -27,7 +28,7 @@ class ConcreteEvents { onKeybindPressed: ExposedEvent | null = null; onCurrentSoundboardChanged: ExposedEvent | null = null; onMinToTrayChanged: ExposedEvent | null = null; - onUpdateReady: ExposedEvent | null = null; + onUpdateStateChanged: ExposedEvent | null = null; onSoundPlayRequested: ExposedEvent | null = null; onStopAllSounds: ExposedEvent | null = null; onZoomFactorChanged: ExposedEvent | null = null;