@@ -7,36 +7,13 @@ require('crash-reporter').start();
77
88var Menu = require ( 'menu' ) ;
99var Tray = require ( 'tray' ) ;
10- var BrowserWindow = require ( 'browser-window' ) ;
1110var AutoLaunch = require ( 'auto-launch' ) ;
11+ var BrowserWindow = require ( 'browser-window' ) ;
12+ var dialog = require ( 'dialog' ) ;
1213
1314var iconIdle = path . join ( __dirname , 'images' , 'tray-idleTemplate.png' ) ;
1415var iconActive = path . join ( __dirname , 'images' , 'tray-active.png' ) ;
1516
16- autoUpdater
17- . on ( 'error' , function ( event , message ) {
18- console . log ( 'ERRORED.' ) ;
19- console . log ( 'Event: ' + JSON . stringify ( event ) + '. MESSAGE: ' + message ) ;
20- } )
21- . on ( 'checking-for-update' , function ( ) {
22- console . log ( 'Checking for update' ) ;
23- } )
24- . on ( 'update-available' , function ( ) {
25- console . log ( 'Update available' ) ;
26- } )
27- . on ( 'update-not-available' , function ( ) {
28- console . log ( 'Update not available' ) ;
29- } )
30- . on ( 'update-downloaded' , function ( event , releaseNotes , releaseName ,
31- releaseDate , updateUrl , quitAndUpdate ) {
32- console . log ( 'Update downloaded' ) ;
33- quitAndUpdate ( ) ;
34- } ) ;
35-
36- autoUpdater . setFeedUrl ( 'https://raw.githubusercontent.com/' +
37- 'ekonstantinidis/gitify/master/auto-update.json' ) ;
38- autoUpdater . checkForUpdates ( ) ;
39-
4017var autoStart = new AutoLaunch ( {
4118 name : 'Gitify' ,
4219 path : process . execPath . match ( / .* ?\. a p p / ) [ 0 ]
@@ -70,6 +47,7 @@ app.on('ready', function(){
7047 appIcon . window . setVisibleOnAllWorkspaces ( true ) ;
7148
7249 initMenu ( ) ;
50+ checkAutoUpdate ( ) ;
7351 }
7452
7553 function showWindow ( bounds ) {
@@ -114,6 +92,51 @@ app.on('ready', function(){
11492 appIcon . window . hide ( ) ;
11593 }
11694
95+ function checkAutoUpdate ( ) {
96+
97+ autoUpdater
98+ . on ( 'error' , function ( event , message ) {
99+ console . log ( 'ERRORED.' ) ;
100+ console . log ( 'Event: ' + JSON . stringify ( event ) + '. MESSAGE: ' + message ) ;
101+ } )
102+ . on ( 'checking-for-update' , function ( ) {
103+ console . log ( 'Checking for update' ) ;
104+ } )
105+ . on ( 'update-available' , function ( ) {
106+ console . log ( 'Update available' ) ;
107+ } )
108+ . on ( 'update-not-available' , function ( ) {
109+ console . log ( 'Update not available' ) ;
110+ app . dock . hide ( ) ;
111+ } )
112+ . on ( 'update-downloaded' , function ( event , releaseNotes , releaseName ,
113+ releaseDate , updateUrl , quitAndUpdate ) {
114+ console . log ( 'Update downloaded' ) ;
115+ confirmAutoUpdate ( quitAndUpdate ) ;
116+ } ) ;
117+
118+ autoUpdater . setFeedUrl ( 'https://raw.githubusercontent.com/' +
119+ 'ekonstantinidis/gitify/master/auto-update.json' ) ;
120+ autoUpdater . checkForUpdates ( ) ;
121+ }
122+
123+ function confirmAutoUpdate ( quitAndUpdate ) {
124+ dialog . showMessageBox ( {
125+ type : 'question' ,
126+ buttons : [ 'Update & Restart' , 'Cancel' ] ,
127+ title : 'Update Available' ,
128+ cancelId : 99 ,
129+ message : 'There is an update available. Would you like to update the app now?'
130+ } , function ( response ) {
131+ console . log ( 'Exit: ' + response ) ;
132+ app . dock . hide ( ) ;
133+ if ( response === 0 ) {
134+ quitAndUpdate ( ) ;
135+ }
136+ }
137+ ) ;
138+ }
139+
117140 ipc . on ( 'reopen-window' , function ( ) {
118141 appIcon . window . show ( ) ;
119142 } ) ;
@@ -138,6 +161,5 @@ app.on('ready', function(){
138161 app . quit ( ) ;
139162 } ) ;
140163
141- app . dock . hide ( ) ;
142164 appIcon . setToolTip ( 'GitHub Notifications on your menu bar.' ) ;
143165} ) ;
0 commit comments