Skip to content

Commit

Permalink
add autoupdater as menu option, version bump to test
Browse files Browse the repository at this point in the history
  • Loading branch information
todbot committed Jan 25, 2018
1 parent 5be8861 commit 9c9c47b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 26 deletions.
47 changes: 25 additions & 22 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -289,5 +289,8 @@ app.on('ready', function () {
ipcMain.on('quitnow', function() {
quit();
});
ipcMain.on('checkForUpdates', function() {
updater.checkForUpdates();
})

});
13 changes: 12 additions & 1 deletion app/menuMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blink1Control2",
"version": "2.1.0",
"version": "2.1.1",
"author": "ThingM <blink1@thingm.com> (https://blink1.thingm.com/)",
"description": "Blink1Control2 GUI app for blink(1) devices",
"productName": "Blink1Control2",
Expand All @@ -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",
Expand Down
62 changes: 62 additions & 0 deletions app/updater.js
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Blink1Control2",
"version": "2.1.0",
"version": "2.1.1",
"author": "ThingM <blink1@thingm.com> (https://blink1.thingm.com/)",
"description": "Blink1Control2 GUI app for blink(1) devices",
"keywords": [
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9c9c47b

Please sign in to comment.