Add updater to apps

This commit is contained in:
Joel Collins 2019-05-28 11:59:46 +01:00
parent a4a2ada99b
commit ad805b91c0
2 changed files with 71 additions and 7 deletions

View file

@ -1,15 +1,70 @@
//handle setupevents as quickly as possible
const setupEvents = require('./setupEvents')
if (setupEvents.handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
// Required packages
const electron = require('electron')
const { dialog } = require('electron')
const updater = require("electron-updater");
const autoUpdater = updater.autoUpdater;
const contextMenu = require('electron-context-menu')
const path = require('path')
// Auto upadater
autoUpdater.autoDownload = false;
autoUpdater.setFeedURL({
provider: "generic",
url: "https://gitlab.com/openflexure/openflexure-microscope-jsclient/-/jobs/artifacts/master/raw?job=package"
});
autoUpdater.on('checking-for-update', function () {
sendStatusToWindow('Checking for update...');
});
autoUpdater.on('update-available', function (info) {
sendStatusToWindow('Update available.' + info)
dialog.showMessageBox(mainWindow, {
type: 'info',
title: 'Update available',
message: 'A new version of OpenFlexure eV is available.',
buttons: ['Download', 'Later']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
}
})
});
autoUpdater.on('update-downloaded', function (info) {
sendStatusToWindow('Update downloaded.' + info)
dialog.showMessageBox(mainWindow, {
type: 'info',
title: "Update downloaded",
message: 'Please restart the application to apply the update.',
buttons: ['Update', 'Later']
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.quitAndInstall();
}
})
});
autoUpdater.on('update-not-available', function (info) {
sendStatusToWindow('Update not available.');
});
autoUpdater.on('error', function (err) {
sendStatusToWindow('Error in auto-updater.');
});
autoUpdater.on('download-progress', function (progressObj) {
let log_message = "Download speed: " + progressObj.bytesPerSecond;
log_message = log_message + ' - Downloaded ' + parseInt(progressObj.percent) + '%';
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
sendStatusToWindow(log_message);
});
function sendStatusToWindow(message) {
console.log(message);
}
// Set up the app
const app = electron.app
const BrowserWindow = electron.BrowserWindow
@ -36,6 +91,7 @@ function createWindow() {
});
mainWindow.loadURL(url)
autoUpdater.checkForUpdates();
// Emitted when the window is closed.
mainWindow.on('closed', function() {

View file

@ -1,4 +1,6 @@
const { app, Menu } = require('electron')
const updater = require("electron-updater");
const autoUpdater = updater.autoUpdater;
const path = require('path')
const openAboutWindow = require('about-window').default
@ -47,6 +49,12 @@ const template = [
homepage: "https://gitlab.com/openflexure/openflexure-microscope-jsclient",
})
}
},
{
label: 'Check for Updates',
click () {
autoUpdater.checkForUpdates();
}
}
]
}