diff --git a/client/desktop/app-handlers/updater/auto-updater/index.js b/client/desktop/app-handlers/updater/auto-updater/index.js index 1d80a336246793..050c81abbb57a3 100644 --- a/client/desktop/app-handlers/updater/auto-updater/index.js +++ b/client/desktop/app-handlers/updater/auto-updater/index.js @@ -47,17 +47,23 @@ class AutoUpdater extends Updater { autoUpdater.allowPrerelease = true; autoUpdater.allowDowngrade = false; } + + // Tracks whether an auto-update check was initiated via menu selection. + this.isUserRequested = false; } - ping() { + ping( isUserRequested ) { if ( process.env.DEBUG ) { dialogDebug( 'DEBUG is set: skipping auto-update check' ); return; } dialogDebug( 'Checking for update' ); autoUpdater.checkForUpdates(); + this.isUserRequested = isUserRequested; } + // ignore (available), confirm (available), cancel (available) + // not available ( do nothing ) - user initiated onAvailable( info ) { log.info( 'New update is available: ', info.version ); bumpStat( 'wpcom-desktop-update-check', `${ getStatsString( this.beta ) }-needs-update` ); @@ -66,6 +72,10 @@ class AutoUpdater extends Updater { onNotAvailable() { log.info( 'No update is available' ); bumpStat( 'wpcom-desktop-update-check', `${ getStatsString( this.beta ) }-no-update` ); + if ( this.isUserRequested ) { + this.notifyNotAvailable(); + } + this.isUserRequested = false; } onDownloaded( info ) { @@ -93,6 +103,7 @@ class AutoUpdater extends Updater { } onCancel() { + this.isUserRequested = false; bumpStat( 'wpcom-desktop-update', `${ getStatsString( this.beta ) }-update-cancel` ); } diff --git a/client/desktop/app-handlers/updater/index.js b/client/desktop/app-handlers/updater/index.js index 3b8632863b7f92..062185e6cf4c55 100644 --- a/client/desktop/app-handlers/updater/index.js +++ b/client/desktop/app-handlers/updater/index.js @@ -15,19 +15,19 @@ const log = require( 'desktop/lib/logger' )( 'desktop:updater' ); let updater = false; -module.exports = function () { +function init() { log.info( 'Updater config: ', Config.updater ); if ( Config.updater ) { app.on( 'will-finish-launching', function () { const beta = settings.getSetting( 'release-channel' ) === 'beta'; log.info( `Update channel: '${ settings.getSetting( 'release-channel' ) }'` ); if ( platform.isOSX() || platform.isWindows() || process.env.APPIMAGE ) { - log.info( 'Auto Update' ); + log.info( 'Initializing auto updater...' ); updater = new AutoUpdater( { beta, } ); } else { - log.info( 'Manual Update' ); + log.info( 'Initializing manual updater...' ); updater = new ManualUpdater( { downloadUrl: Config.updater.downloadUrl, apiUrl: Config.updater.apiUrl, @@ -47,4 +47,13 @@ module.exports = function () { } else { log.info( 'Skipping Update – no configuration' ); } -}; +} + +function getUpdater() { + return updater; +} + +// !! Syntax: assignment via intermediary module const is +// necessary to support both unnamed (default) and named exports !! +const main = ( module.exports = init ); +main.getUpdater = getUpdater; diff --git a/client/desktop/lib/menu/app-menu.js b/client/desktop/lib/menu/app-menu.js index d848ccc5bf59f4..28804293c24648 100644 --- a/client/desktop/lib/menu/app-menu.js +++ b/client/desktop/lib/menu/app-menu.js @@ -13,6 +13,8 @@ const WindowManager = require( 'desktop/lib/window-manager' ); const platform = require( 'desktop/lib/platform' ); const AppQuit = require( 'desktop/lib/app-quit' ); const debugMenu = require( './debug-menu' ); +const { getUpdater } = require( 'desktop/app-handlers/updater' ); +const log = require( 'desktop/lib/logger' )( 'desktop:menu' ); /** * Module variables @@ -118,6 +120,15 @@ module.exports = function ( app, mainWindow ) { label: 'Show All', role: 'unhide', }, + { + type: 'separator', + }, + { + label: 'Check For Updates', + click: function () { + checkForUpdates(); + }, + }, { type: 'separator', } @@ -126,3 +137,13 @@ module.exports = function ( app, mainWindow ) { return menuItems; }; + +function checkForUpdates() { + log.info( `User clicked 'Check For Updates'` ); + const updater = getUpdater(); + if ( updater ) { + updater.ping( true ); + } else { + log.error( 'Updater not set' ); + } +} diff --git a/client/desktop/lib/updater/index.js b/client/desktop/lib/updater/index.js index 2a67407b177ba9..f228b667fb4376 100644 --- a/client/desktop/lib/updater/index.js +++ b/client/desktop/lib/updater/index.js @@ -75,6 +75,17 @@ class Updater extends EventEmitter { } } + notifyNotAvailable() { + const mainWindow = BrowserWindow.getFocusedWindow(); + + const notAvailableDialogOptions = { + buttons: [ 'OK' ], + message: 'There are currently no updates available.', + }; + + dialog.showMessageBox( mainWindow, notAvailableDialogOptions ); + } + setVersion( version ) { this._version = version; }