Skip to content

Commit

Permalink
feat: add manual update check (#45757)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsakaimbo authored Sep 23, 2020
1 parent cad8210 commit 547b7ee
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
13 changes: 12 additions & 1 deletion client/desktop/app-handlers/updater/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` );
Expand All @@ -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 ) {
Expand Down Expand Up @@ -93,6 +103,7 @@ class AutoUpdater extends Updater {
}

onCancel() {
this.isUserRequested = false;
bumpStat( 'wpcom-desktop-update', `${ getStatsString( this.beta ) }-update-cancel` );
}

Expand Down
17 changes: 13 additions & 4 deletions client/desktop/app-handlers/updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
21 changes: 21 additions & 0 deletions client/desktop/lib/menu/app-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
}
Expand All @@ -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' );
}
}
11 changes: 11 additions & 0 deletions client/desktop/lib/updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 547b7ee

Please sign in to comment.