diff --git a/app/main.js b/app/main.js index 88a67c2..8affb20 100644 --- a/app/main.js +++ b/app/main.js @@ -5,15 +5,14 @@ var app = electron.app; var ipcMain = electron.ipcMain; var dialog = electron.dialog; -var autoUpdater = require('electron-updater').autoUpdater; -var autoUpdateMsg = ""; - var BrowserWindow = electron.BrowserWindow; var Menu = electron.Menu; var crashReporter = electron.crashReporter; var path = require('path'); +var updater = require('./updater'); + var mainWindow = null; // If someone tried to run a second instance, we should focus our window. @@ -110,7 +109,7 @@ var openAboutWindow = function () { aboutWindow.webContents.on('will-navigate', function(e,url) { handleUrl(e,url); } ); // aboutWindow.loadURL('data:text/html,' + info); - aboutWindow.loadURL( 'file://' + __dirname + '/about.html#'+autoUpdateMsg ); + aboutWindow.loadURL( 'file://' + __dirname + '/about.html') //+autoUpdateMsg ); return aboutWindow; }; @@ -145,31 +144,32 @@ var openHelpWindow = function() { helpWindow.loadURL( 'file://' + __dirname + '/help/index.html' ); }; -autoUpdater.on('checking-for-update', () => { - console.log('Checking for update...'); -}); -autoUpdater.on('update-available', (info) => { - console.log('Update available.'); -}); -autoUpdater.on('update-not-available', (info) => { - console.log('Update not available.'); -}); -autoUpdater.on('error', (err) => { - console.log('Error in auto-updater.'); -}); +// autoUpdater.on('checking-for-update', () => { +// console.log('Checking for update...'); +// }); +// autoUpdater.on('update-available', (info) => { +// console.log('Update available.'); +// }); +// autoUpdater.on('update-not-available', (info) => { +// console.log('Update not available.'); +// }); +// autoUpdater.on('error', (err) => { +// console.log('Error in auto-updater.'); +// }); // // the main deal // app.on('ready', function () { - autoUpdater.autoDownload = false; + // autoUpdater.autoDownload = false; // autoUpdater.checkForUpdates(); - var hideDockIcon = config.readSettings('startup:hideDockIcon'); - if( hideDockIcon && process.platform === 'darwin' ) { - app.dock.hide(); - } + var hideDockIcon = config.readSettings('startup:hideDockIcon'); + if( hideDockIcon && process.platform === 'darwin' ) { + app.dock.hide(); + } + var startMinimized = config.readSettings('startup:startMinimized'); if( !startMinimized ) { var splash = openAboutWindow(); @@ -178,7 +178,7 @@ app.on('ready', function () { mainWindow.show(); }, 3000 ); } - var showDebug = config.readSettings('logger.showDebug') || false; + var showDebug = config.readSettings('logger.showDebug') || false; // Install global shortcut key (see also MenuMaker) var globalShortcut = electron.globalShortcut; @@ -289,5 +289,8 @@ app.on('ready', function () { ipcMain.on('quitnow', function() { quit(); }); + ipcMain.on('checkForUpdates', function() { + updater.checkForUpdates(); + }) }); diff --git a/app/menuMaker.js b/app/menuMaker.js index c132b88..61952f8 100644 --- a/app/menuMaker.js +++ b/app/menuMaker.js @@ -100,7 +100,7 @@ var MenuMaker = { setupTrayMenu: function() { // var self = this; - console.log("resourcesPath:",process.resourcesPath, "appPath:",app.getAppPath()); + // console.log("resourcesPath:",process.resourcesPath, "appPath:",app.getAppPath()); if( process.platform === 'win32' ) { // FIXME: make this icon better for Windows tray = new Tray( app.getAppPath() + '/images/icons/blink1mk2-icon2-128px.ico' ); } @@ -160,6 +160,12 @@ var MenuMaker = { ipcRenderer.send('openAboutWindow'); } }, + { label: 'Check for Updates...', + click: function(menuItem) { + // console.log("MENUITEM:", menuItem); + ipcRenderer.send('checkForUpdates'); + } + }, { type: 'separator' }, { label: 'Preferences...', accelerator: "CommandOrControl+,", click: function() { @@ -204,6 +210,11 @@ var MenuMaker = { ipcRenderer.send('openAboutWindow'); } }, + { label: 'Check for updates', + click: function() { + ipcRenderer.send('checkForUpdates'); + } + }, { type: 'separator' }, { label: 'Preferences...', accelerator: "CommandOrControl+,", click: function() { diff --git a/app/package.json b/app/package.json index 461ef07..6d65d1d 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "Blink1Control2", - "version": "2.1.0", + "version": "2.1.1", "author": "ThingM (https://blink1.thingm.com/)", "description": "Blink1Control2 GUI app for blink(1) devices", "productName": "Blink1Control2", @@ -18,7 +18,7 @@ "events": "^1.1.1", "express": "^4.13.4", "imap": "^0.8.19", - "is-electron-renderer": "^2.0.0", + "is-electron-renderer": "^2.0.1", "moment": "^2.17.1", "nconf": "^0.10.0", "needle": "^1.5.1", diff --git a/app/updater.js b/app/updater.js new file mode 100644 index 0000000..4c521f5 --- /dev/null +++ b/app/updater.js @@ -0,0 +1,62 @@ +/** + * updater.js + * + * Please use manual update only when it is really required, otherwise please use recommended non-intrusive auto update. + * + * Import steps: + * 1. create `updater.js` for the code snippet + * 2. require `updater.js` for menu implementation, and set `checkForUpdates` callback from `updater` for the click property of `Check Updates...` MenuItem. + */ +const { dialog } = require('electron') +const { autoUpdater } = require('electron-updater') + +let updater = {} +autoUpdater.autoDownload = false + +autoUpdater.on('error', (error) => { + dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString()) +}) + +autoUpdater.on('update-available', () => { + dialog.showMessageBox({ + type: 'info', + title: 'Found Updates', + message: 'Found updates, do you want update now?', + buttons: ['Sure', 'No'] + }, (buttonIndex) => { + if (buttonIndex === 0) { + autoUpdater.downloadUpdate() + } + else { + updater.enabled = true + // updater = null + } + }) +}) + +autoUpdater.on('update-not-available', () => { + dialog.showMessageBox({ + title: 'No Updates', + message: 'Current version is up-to-date.' + }) + updater.enabled = true + // updater = null +}) + +autoUpdater.on('update-downloaded', () => { + dialog.showMessageBox({ + title: 'Install Updates', + message: 'Updates downloaded, application will be quit for update...' + }, () => { + setImmediate(() => autoUpdater.quitAndInstall()) + }) +}) + +// export this to MenuItem click callback +// function checkForUpdates (menuItem, focusedWindow, event) { +function checkForUpdates() { + // updater = menuItem + updater.enabled = false + autoUpdater.checkForUpdates() +} +module.exports.checkForUpdates = checkForUpdates diff --git a/package.json b/package.json index 04e009b..ad6096f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Blink1Control2", - "version": "2.1.0", + "version": "2.1.1", "author": "ThingM (https://blink1.thingm.com/)", "description": "Blink1Control2 GUI app for blink(1) devices", "keywords": [ @@ -31,6 +31,7 @@ "dist:test": "electron-builder --dir", "dist:draft": "electron-builder --publish=never", "dist": "electron-builder", + "release": "electron-builder", "dist:win32bit": "electron-builder --ia32 --win --publish=never", "clean": "rimraf app/node_modules node_modules package-lock.json app/package-lock.json", "env": "env",