Skip to content

Commit

Permalink
Merge pull request #97 from mtgto/updater_dialog
Browse files Browse the repository at this point in the history
Show update notify and dialog + Linux icons
  • Loading branch information
mtgto committed Feb 16, 2020
2 parents 4e09711 + fe9e452 commit aca1b7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ linux:
target:
- AppImage
category: Utility
icon: build/icon.icns
4 changes: 3 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import electron from "electron";
import path from "path";
import { updater } from "./updater";
import { initMenu } from "./menu";
import logger from "./logger";

const app = electron.app;
let mainWindow: electron.BrowserWindow | null;
export let mainWindow: electron.BrowserWindow | null;

process.on("uncaughtException", err => {
logger.error(err);
Expand All @@ -20,6 +21,7 @@ async function createWindow() {
width: 1280,
height: 780,
title: "Bdash",
icon: path.join(__dirname, "..", "icon.png"),
webPreferences: {
nodeIntegration: true
}
Expand Down
25 changes: 20 additions & 5 deletions src/main/updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { autoUpdater, AppUpdater, UpdateCheckResult } from "electron-updater";
import { dialog } from "electron";
import { autoUpdater, AppUpdater, UpdateCheckResult, UpdateInfo } from "electron-updater";
import isDev from "electron-is-dev";
import logger from "./logger";
import { mainWindow } from ".";

autoUpdater.logger = logger;

Expand All @@ -17,14 +19,27 @@ export class Updater {

constructor(autoUpdater: AppUpdater) {
this.autoUpdater = autoUpdater;
this.autoUpdater.on("update-downloaded", () => {
this.autoUpdater.on("update-downloaded", (info: UpdateInfo) => {
this.state = UpdateState.UpdateDownloaded;
if (mainWindow) {
dialog
.showMessageBox(mainWindow, {
type: "info",
buttons: ["Restart", "Later"],
title: "Bdash Update",
message: process.platform === "win32" ? (info.releaseNotes as string) : info.releaseName!,
detail: "A new version has been downloaded. Restart the application to apply the updates."
})
.then(returnValue => {
if (returnValue.response === 0) autoUpdater.quitAndInstall();
});
}
});
}

async check(): Promise<UpdateCheckResult | void> {
if (isDev) return Promise.resolve();
return this.autoUpdater.checkForUpdates();
async check(): Promise<UpdateCheckResult | null> {
if (isDev) return Promise.resolve(null);
return this.autoUpdater.checkForUpdatesAndNotify();
}

async watch(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = (env, argv) => {
"static/index.js",
"static/RictyDiminished-Regular.ttf",
"static/scatter.svg",
"build/icon.png",
"package.json",
"yarn.lock"
];
Expand Down

0 comments on commit aca1b7c

Please sign in to comment.