Skip to content

Commit

Permalink
Added ability to manually check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Mar 30, 2018
1 parent 0b4ded2 commit 7b94448
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions menu.js
Expand Up @@ -4,6 +4,7 @@ const electron = require('electron');
const os = require('os');
const fs = require('fs-extra');
const config = require('./config');
const update = require('./update');

const join = path.join;
const app = electron.app;
Expand Down Expand Up @@ -106,6 +107,11 @@ const helpSubmenu = [{
click() {
shell.openExternal(homepageURL);
}
}, {
label: `Check for Update`,
click() {
update.manualUpdateCheck();
}
}, {
type: 'separator'
}, {
Expand Down
30 changes: 30 additions & 0 deletions update.js
Expand Up @@ -24,6 +24,18 @@ function displayAvailableUpdate(latestVersion) {
return result;
}

function displayUnavailableUpdate(installedVersion) {
// Display unavailable update info-window
const result = dialog.showMessageBox({
icon: path.join(__dirname, 'static/Icon.png'),
title: 'No Update Available',
message: 'No update available',
detail: 'Version ' + installedVersion + ' is the latest version'
});
console.log('You are on the latest version', installedVersion);
return result;
}

function getLatestVersion(err, res, data) {
if (err) {
console.log('Update error.');
Expand Down Expand Up @@ -52,6 +64,19 @@ function response(result) {
}
}

function manualUpdateCheck(err, res, data) {
// Manually check for updates
const latestVersion = getLatestVersion(err, res, data);
if (latestVersion === installedVersion) {
// No updates available
displayUnavailableUpdate(installedVersion);
} else {
// Set out update notification & get user response
const result = displayAvailableUpdate(latestVersion);
response(result);
}
}

function autoUpdateCheck(err, res, data) {
// Automatically check for updates
const latestVersion = getLatestVersion(err, res, data);
Expand Down Expand Up @@ -101,3 +126,8 @@ module.exports.autoUpdateCheck = () => {
get.concat(updateURL, autoUpdateCheck);
}
};

module.exports.manualUpdateCheck = () => {
// Check for updates manually
get.concat(updateURL, manualUpdateCheck);
};

0 comments on commit 7b94448

Please sign in to comment.