Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Updater for Electron #105

Merged
merged 1 commit into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
owner: josephdadams
repo: TallyArbiter
provider: github
36 changes: 35 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This is the electron startup script
const { app, BrowserWindow, Tray, Menu } = require('electron');
const { app, BrowserWindow, Tray, Menu, dialog } = require('electron');
const { autoUpdater } = require("electron-updater");
const path = require("path");

let mainWindow;
Expand Down Expand Up @@ -63,13 +64,46 @@ function createTrayIcon() {
});
}

function checkForUpdates() {
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.checkForUpdates();
autoUpdater.on("update-available", () => {
dialog.showMessageBox(mainWindow, {
title: "Update Available",
message: "There's an update available for TallyArbiter. Do you want to download and install it?",
buttons: ["Update", "Cancel"],
}).then((v) => {
if (v.response == 0) {
dialog.showMessageBox(mainWindow, {
title: "Downloading update",
message: "The update is being downloaded in the background. Once finished, you will be prompted to save your work and restart TallyArbiter."
});
autoUpdater.downloadUpdate();
}
});
});
autoUpdater.on("update-downloaded", () => {
dialog.showMessageBox(null, {
title: "Update downloaded",
message: "The update has been downloaded. Save your work and then press the Update button.",
buttons: ["Update"],
}).then((r) => {
if (r.response == 0) {
autoUpdater.quitAndInstall();
}
});
});
}


if (!gotTheLock) {
app.quit();
} else {
app.whenReady().then(() => {
createWindow();
createTrayIcon();
checkForUpdates();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
Expand Down
102 changes: 91 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"blink1",
"roland",
"tricaster",
"gpio"
"gpio"
],
"license": "MIT",
"author": "Joseph Adams",
Expand Down Expand Up @@ -51,6 +51,7 @@
"axios": "^0.21.1",
"cli-color": "^2.0.0",
"detect-rpi": "^1.4.0",
"electron-updater": "^4.3.9",
"esm": "^3.2.25",
"express": "^4.17.1",
"jquery": "^3.6.0",
Expand Down