Skip to content

Commit

Permalink
implement auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelknoch committed Apr 9, 2016
1 parent b944bee commit a2a47a4
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

const autoUpdater = require('auto-updater');
const appVersion = require('./package.json').version;
const os = require('os').platform();
const dialog = require('electron').dialog;


// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;

function createWindow () {
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});

Expand All @@ -21,7 +27,7 @@ function createWindow () {
mainWindow.webContents.openDevTools();

// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
Expand All @@ -31,7 +37,12 @@ function createWindow () {

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', createWindow);
app.on('ready', function () {
createWindow();
autoUpdater.setFeedURL('http://localhost:3000/release');
autoUpdater.checkForUpdates();

});

// Quit when all windows are closed.
app.on('window-all-closed', function () {
Expand All @@ -48,4 +59,22 @@ app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
});

autoUpdater.on('update-downloaded', notifyUserAboutUpdate);

function notifyUserAboutUpdate() {
let buttons = ['Sure, get me a new version!', 'Nah, I\'m good, I can wait.'];
let options = {
type: 'question',
message: 'Hey, new version of app is downloaded! Do you want to restart it now and get the newest version?',
cancelId: -1,
buttons
};

dialog.showMessageBox(options, function (response) {
if (response == 0) {
autoUpdater.quitAndInstall();
}
});
}

0 comments on commit a2a47a4

Please sign in to comment.