@@ -35,11 +35,42 @@ const data = new Store({
35
35
"decks" : [ ]
36
36
}
37
37
} ) ;
38
+
39
+ const { autoUpdater } = require ( "electron-updater" ) ;
40
+
41
+ autoUpdater . on ( 'checking-for-update' , ( ) => {
42
+ sendStatusToWindow ( 'Checking for update...' , false ) ;
43
+ } ) ;
44
+ autoUpdater . on ( 'update-available' , info => {
45
+ sendStatusToWindow ( 'Update available.' , true ) ;
46
+ } ) ;
47
+ autoUpdater . on ( 'update-not-available' , info => {
48
+ sendStatusToWindow ( 'Update not available.' , false ) ;
49
+ } ) ;
50
+ autoUpdater . on ( 'error' , err => {
51
+ sendStatusToWindow ( `Error in auto-updater: ${ err . toString ( ) } ` , true ) ;
52
+ } ) ;
53
+ autoUpdater . on ( 'download-progress' , progressObj => {
54
+ sendStatusToWindow (
55
+ `Download speed: ${ progressObj . bytesPerSecond } - Downloaded ${ progressObj . percent } % (${ progressObj . transferred } + '/' + ${ progressObj . total } + )` , false
56
+ ) ;
57
+ } ) ;
58
+ autoUpdater . on ( 'update-downloaded' , info => {
59
+ sendStatusToWindow ( 'Update downloaded; will install now' , false ) ;
60
+ app . isQuiting = true ;
61
+ autoUpdater . quitAndInstall ( ) ;
62
+ } ) ;
63
+
64
+ const log = require ( "electron-log" ) ;
65
+ log . catchErrors ( ) ;
66
+
67
+ autoUpdater . logger = log
68
+ autoUpdater . logger . transports . file . level = "info"
69
+
38
70
const imgPath = path . join ( process . resourcesPath , 'icon.png' ) ;
39
71
const nativeImage = require ( 'electron' ) . nativeImage
40
72
let icon = nativeImage . createFromPath ( imgPath )
41
73
42
-
43
74
var trackerWindow , fullCardWindow , graveyardWindow , oppDeckWindow ;
44
75
45
76
const gotTheLock = app . requestSingleInstanceLock ( )
@@ -57,7 +88,6 @@ if (!gotTheLock) {
57
88
} )
58
89
}
59
90
60
-
61
91
function createWindow ( ) {
62
92
const tray = new Tray ( icon )
63
93
@@ -346,6 +376,7 @@ function createWindow () {
346
376
}
347
377
} ) ;
348
378
379
+ autoUpdater . checkForUpdates ( ) ;
349
380
}
350
381
351
382
app . whenReady ( ) . then ( createWindow )
@@ -359,8 +390,15 @@ app.on('activate', function () {
359
390
if ( BrowserWindow . getAllWindows ( ) . length === 0 ) createWindow ( )
360
391
} )
361
392
362
- const axios = require ( 'axios' ) ;
363
393
394
+ const sendStatusToWindow = ( text , alert ) => {
395
+ log . info ( text ) ;
396
+ if ( mainWindow && alert ) {
397
+ mainWindow . webContents . send ( 'message' , text ) ;
398
+ }
399
+ } ;
400
+
401
+ const axios = require ( 'axios' ) ;
364
402
365
403
async function httpGet ( theUrl )
366
404
{
0 commit comments