1
1
var app = require ( 'app' ) ;
2
2
var path = require ( 'path' ) ;
3
3
var ipc = require ( 'ipc' ) ;
4
+ var ghReleases = require ( 'electron-gh-releases' ) ;
4
5
5
6
require ( 'crash-reporter' ) . start ( ) ;
6
7
7
8
var Menu = require ( 'menu' ) ;
8
9
var Tray = require ( 'tray' ) ;
9
- var BrowserWindow = require ( 'browser-window' ) ;
10
10
var AutoLaunch = require ( 'auto-launch' ) ;
11
+ var BrowserWindow = require ( 'browser-window' ) ;
12
+ var dialog = require ( 'dialog' ) ;
11
13
12
14
var iconIdle = path . join ( __dirname , 'images' , 'tray-idleTemplate.png' ) ;
13
15
var iconActive = path . join ( __dirname , 'images' , 'tray-active.png' ) ;
@@ -45,6 +47,7 @@ app.on('ready', function(){
45
47
appIcon . window . setVisibleOnAllWorkspaces ( true ) ;
46
48
47
49
initMenu ( ) ;
50
+ checkAutoUpdate ( ) ;
48
51
}
49
52
50
53
function showWindow ( bounds ) {
@@ -89,6 +92,55 @@ app.on('ready', function(){
89
92
appIcon . window . hide ( ) ;
90
93
}
91
94
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
+
92
144
ipc . on ( 'reopen-window' , function ( ) {
93
145
appIcon . window . show ( ) ;
94
146
} ) ;
@@ -113,6 +165,5 @@ app.on('ready', function(){
113
165
app . quit ( ) ;
114
166
} ) ;
115
167
116
- app . dock . hide ( ) ;
117
168
appIcon . setToolTip ( 'GitHub Notifications on your menu bar.' ) ;
118
169
} ) ;
0 commit comments