11// process.on('uncaughtException', (...args) => console.error(...args))
2- const { app, BrowserWindow, Tray, Menu, ipcMain} = require ( 'electron' )
2+ const { app, BrowserWindow, Tray, Menu, ipcMain, shell } = require ( 'electron' )
33const path = require ( 'path' )
44const AppSettings = require ( './utils/settings' )
55let microbreakIdeas = require ( './microbreakIdeas' )
@@ -15,6 +15,11 @@ let startMicrobreakTimer
1515let planMicrobreakTimer
1616let resumeMicrobreaksTimer
1717let settings
18+ let isPaused = false
19+
20+ global . shared = {
21+ isNewVersion : false
22+ }
1823
1924function createTrayIcon ( ) {
2025 if ( process . platform === 'darwin' ) {
@@ -23,7 +28,8 @@ function createTrayIcon () {
2328 const iconPath = path . join ( __dirname , 'images/stretchly_18x18.png' )
2429 appIcon = new Tray ( iconPath )
2530 appIcon . setToolTip ( 'stretchly - break time reminder app' )
26- appIcon . setContextMenu ( getTrayMenu ( false ) )
31+ isPaused = false
32+ appIcon . setContextMenu ( getTrayMenu ( ) )
2733}
2834
2935function startProcessWin ( ) {
@@ -32,6 +38,18 @@ function startProcessWin () {
3238 show : false
3339 } )
3440 processWin . loadURL ( modalPath )
41+ processWin . webContents . on ( 'did-finish-load' , ( ) => {
42+ planVersionCheck ( )
43+ } )
44+ }
45+
46+ function planVersionCheck ( seconds = 1 ) {
47+ setTimeout ( checkVersion , seconds * 1000 )
48+ }
49+
50+ function checkVersion ( ) {
51+ processWin . webContents . send ( 'checkVersion' , `v${ app . getVersion ( ) } ` )
52+ planVersionCheck ( 3600 * 5 )
3553}
3654
3755function showStartUpWindow ( ) {
@@ -90,6 +108,10 @@ ipcMain.on('save-setting', function (event, key, value) {
90108 settingsWin . webContents . send ( 'renderSettings' , settings . data )
91109} )
92110
111+ ipcMain . on ( 'update-tray' , function ( event ) {
112+ appIcon . setContextMenu ( getTrayMenu ( ) )
113+ } )
114+
93115let shouldQuit = app . makeSingleInstance ( function ( commandLine , workingDirectory ) {
94116 if ( appIcon ) {
95117 // Someone tried to run a second instance
@@ -127,12 +149,14 @@ function pauseMicrobreaks (seconds) {
127149 if ( seconds !== 1 ) {
128150 resumeMicrobreaksTimer = setTimeout ( resumeMicrobreaks , seconds )
129151 }
130- appIcon . setContextMenu ( getTrayMenu ( true ) )
152+ isPaused = true
153+ appIcon . setContextMenu ( getTrayMenu ( ) )
131154}
132155
133156function resumeMicrobreaks ( ) {
134157 clearTimeout ( resumeMicrobreaksTimer )
135- appIcon . setContextMenu ( getTrayMenu ( false ) )
158+ isPaused = false
159+ appIcon . setContextMenu ( getTrayMenu ( ) )
136160 planMicrobreak ( )
137161}
138162
@@ -141,7 +165,7 @@ function showAboutWindow () {
141165 aboutWin = new BrowserWindow ( {
142166 alwaysOnTop : true ,
143167 backgroundColor : settings . get ( 'mainColor' ) ,
144- title : ' About stretchly'
168+ title : ` About stretchly v ${ app . getVersion ( ) } `
145169 } )
146170 aboutWin . loadURL ( modalPath )
147171}
@@ -159,9 +183,30 @@ function showSettingsWindow () {
159183 } )
160184}
161185
162- function getTrayMenu ( MicrobreaksPaused ) {
186+ function getTrayMenu ( ) {
163187 let trayMenu = [ ]
188+ if ( global . shared . isNewVersion ) {
189+ trayMenu . push ( {
190+ label : 'Download latest version' ,
191+ click : function ( ) {
192+ shell . openExternal ( 'https://github.com/hovancik/stretchly/releases' )
193+ }
194+ } )
195+ }
164196
197+ trayMenu . push ( {
198+ label : 'About' ,
199+ click : function ( ) {
200+ showAboutWindow ( )
201+ }
202+ } , {
203+ type : 'separator'
204+ } , {
205+ label : 'Settings' ,
206+ click : function ( ) {
207+ showSettingsWindow ( )
208+ }
209+ } )
165210 if ( process . platform === 'darwin' || process . platform === 'win32' ) {
166211 let loginItemSettings = app . getLoginItemSettings ( )
167212 let openAtLogin = loginItemSettings . openAtLogin
@@ -175,11 +220,7 @@ function getTrayMenu (MicrobreaksPaused) {
175220 } )
176221 }
177222
178- trayMenu . push ( {
179- type : 'separator'
180- } )
181-
182- if ( MicrobreaksPaused ) {
223+ if ( isPaused ) {
183224 trayMenu . push ( {
184225 label : 'Resume' ,
185226 click : function ( ) {
@@ -214,19 +255,8 @@ function getTrayMenu (MicrobreaksPaused) {
214255 ]
215256 } )
216257 }
217-
218258 trayMenu . push ( {
219259 type : 'separator'
220- } , {
221- label : 'About' ,
222- click : function ( ) {
223- showAboutWindow ( )
224- }
225- } , {
226- label : 'Settings' ,
227- click : function ( ) {
228- showSettingsWindow ( )
229- }
230260 } , {
231261 label : 'Quit' ,
232262 click : function ( ) {
0 commit comments