diff --git a/main.js b/main.js index 3e11431..1b5821a 100644 --- a/main.js +++ b/main.js @@ -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}); @@ -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. @@ -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 () { @@ -48,4 +59,22 @@ app.on('activate', function () { if (mainWindow === null) { createWindow(); } -}); \ No newline at end of file +}); + +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(); + } + }); +} \ No newline at end of file