Skip to content

Commit

Permalink
Merge pull request #27 from rezk2ll/manual-update-check-notif
Browse files Browse the repository at this point in the history
🌟 Added manual update check result notification
  • Loading branch information
rezk2ll authored Jul 8, 2022
2 parents 43f5e02 + 8dcbde6 commit fe44147
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/services/main/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../utils/server";
import { DomainType, ProtocolType, Template } from "./types";
import { download } from "electron-dl";
import { autoUpdater } from "electron-updater"
import { AppUpdater, autoUpdater } from "electron-updater"

type CustomBrowserWindowEntriesType = {
config_disable_buttons?: boolean;
Expand Down Expand Up @@ -186,7 +186,7 @@ class MainService {
);
}

this.currentWindow?.setTitle("Twake");
this.currentWindow?.setTitle(`Twake ${autoUpdater.currentVersion ?? ''}`);

this.currentWindow?.setBackgroundColor("#0d0f38");

Expand Down Expand Up @@ -259,7 +259,7 @@ class MainService {
{
label: "Check for updates",
accelerator: "CmdOrCtrl+Alt+U",
click: () => autoUpdater.checkForUpdatesAndNotify(),
click: () => this.handleUpdateCheck(),
},
],
},
Expand Down Expand Up @@ -385,6 +385,47 @@ class MainService {
console.error(e);
}
}

/**
* handle manual update check
*
* @private
* @memberof MainService
* @returns {Promise<void>}
*/
private handleUpdateCheck = (): void => {
autoUpdater.autoDownload = false;

autoUpdater.checkForUpdates()
.then(checkResult => {
if (checkResult) {
dialog.showMessageBox(this.currentWindow as BrowserWindow, {
type: "info",
title: "Update available",
message: `A new version of Twake is available: ${checkResult.updateInfo.version}.\n\n Would you like to download it now?`,
buttons: ["Download", "Cancel"],
}).then(result => {
if (result.response === 0) {
autoUpdater.downloadUpdate();
}
});
} else {
dialog.showMessageBox(this.currentWindow as BrowserWindow, {
type: "info",
title: "No update available",
message: "You are running the latest version of Twake",
});
}
})
.catch(err => {
console.error(err);
dialog.showMessageBox(this.currentWindow as BrowserWindow, {
type: "error",
title: "Error",
message: "An error occurred while checking for updates.",
});
});
}
}

export default new MainService();

0 comments on commit fe44147

Please sign in to comment.