Skip to content

Commit c12102d

Browse files
Merge pull request #89 from ekonstantinidis/auto-update
Auto Update
2 parents 39c5313 + 40397d3 commit c12102d

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

main.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
var app = require('app');
22
var path = require('path');
33
var ipc = require('ipc');
4+
var ghReleases = require('electron-gh-releases');
45

56
require('crash-reporter').start();
67

78
var Menu = require('menu');
89
var Tray = require('tray');
9-
var BrowserWindow = require('browser-window');
1010
var AutoLaunch = require('auto-launch');
11+
var BrowserWindow = require('browser-window');
12+
var dialog = require('dialog');
1113

1214
var iconIdle = path.join(__dirname, 'images', 'tray-idleTemplate.png');
1315
var iconActive = path.join(__dirname, 'images', 'tray-active.png');
@@ -45,6 +47,7 @@ app.on('ready', function(){
4547
appIcon.window.setVisibleOnAllWorkspaces(true);
4648

4749
initMenu();
50+
checkAutoUpdate();
4851
}
4952

5053
function showWindow (bounds) {
@@ -89,6 +92,55 @@ app.on('ready', function(){
8992
appIcon.window.hide();
9093
}
9194

95+
function checkAutoUpdate() {
96+
97+
var autoUpdateOptions = {
98+
repo: 'ekonstantinidis/gitify',
99+
currentVersion: app.getVersion()
100+
};
101+
102+
var update = new ghReleases(autoUpdateOptions, function (autoUpdater) {
103+
autoUpdater
104+
.on('error', function(event, message) {
105+
console.log('ERRORED.');
106+
console.log('Event: ' + JSON.stringify(event) + '. MESSAGE: ' + message);
107+
})
108+
.on('update-downloaded', function (event, releaseNotes, releaseName,
109+
releaseDate, updateUrl, quitAndUpdate) {
110+
console.log('Update downloaded');
111+
confirmAutoUpdate(quitAndUpdate);
112+
});
113+
});
114+
115+
// Check for updates
116+
update.check(function (err, status) {
117+
if (err || !status) {
118+
app.dock.hide();
119+
}
120+
121+
if (!err && status) {
122+
update.download();
123+
}
124+
});
125+
}
126+
127+
function confirmAutoUpdate(quitAndUpdate) {
128+
dialog.showMessageBox({
129+
type: 'question',
130+
buttons: ['Update & Restart', 'Cancel'],
131+
title: 'Update Available',
132+
cancelId: 99,
133+
message: 'There is an update available. Would you like to update Gitify now?'
134+
}, function (response) {
135+
console.log('Exit: ' + response);
136+
app.dock.hide();
137+
if (response === 0) {
138+
quitAndUpdate();
139+
}
140+
}
141+
);
142+
}
143+
92144
ipc.on('reopen-window', function() {
93145
appIcon.window.show();
94146
});
@@ -113,6 +165,5 @@ app.on('ready', function(){
113165
app.quit();
114166
});
115167

116-
app.dock.hide();
117168
appIcon.setToolTip('GitHub Notifications on your menu bar.');
118169
});

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitify",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"description": "GitHub Notifications on your menu bar.",
55
"main": "main.js",
66
"scripts": {
@@ -9,7 +9,7 @@
99
"watch-js": "watchify -t babelify src/js/app.js -o build/js/app.js -v",
1010
"watch": "npm run build && grunt build && npm run watch-js & grunt watch",
1111
"start": "electron .",
12-
"dist": "electron-packager . Gitify --overwrite --platform=darwin --arch=x64 --version=0.31.0 --asar=true --icon=images/app-icon.icns --prune --ignore='src' --ignore='coverage'",
12+
"dist": "electron-packager . Gitify --overwrite --platform=darwin --arch=x64 --version=0.31.0 --asar=true --icon=images/app-icon.icns --prune --ignore='src' --ignore='coverage' && bash scripts/codesign.bash",
1313
"lint": "eslint 'src/js/' 'src/js/app.js' 'main.js'",
1414
"test": "npm run lint && jest"
1515
},
@@ -78,6 +78,7 @@
7878
"babelify": "=6.1.3",
7979
"bootstrap": "=3.3.5",
8080
"browserify": "=11.0.1",
81+
"electron-gh-releases": "=1.0.1",
8182
"font-awesome": "=4.4.0",
8283
"octicons": "=2.4.1",
8384
"react": "=0.13.3",

scripts/codesign.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codesign --verbose --deep --force --sign "Developer ID Application: Emmanouil KONSTANTINIDIS" Gitify-darwin-x64/Gitify.app

0 commit comments

Comments
 (0)