Skip to content

Commit

Permalink
Fix autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanouil Konstantinidis committed May 29, 2016
1 parent 77a574f commit 4eb63ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Binary file modified images/press.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 16 additions & 17 deletions main.js
Expand Up @@ -8,7 +8,7 @@ const app = electron.app;
const dialog = electron.dialog;
const ipc = electron.ipcMain;

var ghReleases = require('electron-gh-releases');
const GhReleases = require('electron-gh-releases');
var Positioner = require('electron-positioner');

var AutoLaunch = require('auto-launch');
Expand All @@ -31,7 +31,7 @@ app.on('ready', function() {
var appIcon = new Tray(iconIdle);
var windowPosition = (isWindows) ? 'trayBottomCenter' : 'trayCenter';

function confirmAutoUpdate(quitAndUpdate) {
function confirmAutoUpdate(installUpdate) {
dialog.showMessageBox({
type: 'question',
buttons: ['Update & Restart', 'Cancel'],
Expand All @@ -42,33 +42,32 @@ app.on('ready', function() {
console.log('Exit: ' + response);
app.dock.hide();
if (response === 0) {
quitAndUpdate();
installUpdate();
}
} );
}

function checkAutoUpdate(showAlert) {

var autoUpdateOptions = {
let autoUpdateOptions = {
repo: 'ekonstantinidis/gitify',
currentVersion: app.getVersion()
};

var update = new ghReleases(autoUpdateOptions, function (autoUpdater) {
autoUpdater
.on('error', function(event, message) {
console.log('ERRORED.');
console.log('Event: ' + JSON.stringify(event) + '. MESSAGE: ' + message);
})
.on('update-downloaded', function (event, releaseNotes, releaseName,
releaseDate, updateUrl, quitAndUpdate) {
console.log('Update downloaded');
confirmAutoUpdate(quitAndUpdate);
});
const updater = new GhReleases(autoUpdateOptions);

updater.on('error', (event, message) => {
console.log('ERRORED.');
console.log('Event: ' + JSON.stringify(event) + '. MESSAGE: ' + message);
});

updater.on('update-downloaded', (info) => {
console.log('Update downloaded');
confirmAutoUpdate(updater.install);
});

// Check for updates
update.check(function (err, status) {
updater.check((err, status) => {
if (err || !status) {
if (showAlert) {
dialog.showMessageBox({
Expand All @@ -82,7 +81,7 @@ app.on('ready', function() {
}

if (!err && status) {
update.download();
updater.download();
}
});
}
Expand Down

0 comments on commit 4eb63ac

Please sign in to comment.