@@ -4,13 +4,17 @@ const i18n = require('i18next')
4
4
const logger = require ( '../common/logger' )
5
5
const { notify } = require ( '../common/notify' )
6
6
const { showDialog } = require ( '../dialogs' )
7
- const quitAndInstall = require ( './quit-and-install' )
7
+ const macQuitAndInstall = require ( './macos-quit-and-install' )
8
+ const { IS_MAC } = require ( '../common/consts' )
8
9
9
10
let feedback = false
10
11
11
12
function setup ( ctx ) {
13
+ // we download manually in 'update-available'
12
14
autoUpdater . autoDownload = false
13
- autoUpdater . autoInstallOnAppQuit = true
15
+
16
+ // mac requires manual upgrade, other platforms work out of the box
17
+ autoUpdater . autoInstallOnAppQuit = ! IS_MAC
14
18
15
19
autoUpdater . on ( 'error' , err => {
16
20
logger . error ( `[updater] ${ err . toString ( ) } ` )
@@ -31,7 +35,7 @@ function setup (ctx) {
31
35
} )
32
36
33
37
autoUpdater . on ( 'update-available' , async ( { version, releaseNotes } ) => {
34
- logger . info ( ' [updater] update available, download will start' )
38
+ logger . info ( ` [updater] update to ${ version } available, download will start` )
35
39
36
40
try {
37
41
await autoUpdater . downloadUpdate ( )
@@ -80,11 +84,15 @@ function setup (ctx) {
80
84
} )
81
85
82
86
autoUpdater . on ( 'update-downloaded' , ( { version } ) => {
83
- logger . info ( ' [updater] update downloaded' )
87
+ logger . info ( ` [updater] update to ${ version } downloaded` )
84
88
89
+ const { autoInstallOnAppQuit } = autoUpdater
85
90
const doIt = ( ) => {
91
+ // Do nothing if install is handled by upstream logic
92
+ if ( autoInstallOnAppQuit ) return
93
+ // Else, do custom install handling
86
94
setImmediate ( ( ) => {
87
- quitAndInstall ( ctx )
95
+ if ( IS_MAC ) macQuitAndInstall ( ctx )
88
96
} )
89
97
}
90
98
@@ -102,7 +110,7 @@ function setup (ctx) {
102
110
message : i18n . t ( 'updateDownloadedDialog.message' , { version } ) ,
103
111
type : 'info' ,
104
112
buttons : [
105
- i18n . t ( 'updateDownloadedDialog.action' )
113
+ ( autoInstallOnAppQuit ? i18n . t ( 'ok' ) : i18n . t ( ' updateDownloadedDialog.action') )
106
114
]
107
115
} )
108
116
@@ -120,23 +128,23 @@ async function checkForUpdates () {
120
128
121
129
module . exports = async function ( ctx ) {
122
130
if ( process . env . NODE_ENV === 'development' ) {
123
- ctx . checkForUpdates = ( ) => {
131
+ ctx . manualCheckForUpdates = ( ) => {
124
132
showDialog ( {
125
133
title : 'Not available in development' ,
126
134
message : 'Yes, you called this function successfully.' ,
127
135
buttons : [ i18n . t ( 'close' ) ]
128
136
} )
129
137
}
130
-
131
138
return
132
139
}
133
140
134
141
setup ( ctx )
135
142
136
- await checkForUpdates ( )
143
+ checkForUpdates ( ) // background check
144
+
137
145
setInterval ( checkForUpdates , 43200000 ) // every 12 hours
138
146
139
- ctx . checkForUpdates = ( ) => {
147
+ ctx . manualCheckForUpdates = ( ) => {
140
148
feedback = true
141
149
checkForUpdates ( )
142
150
}
0 commit comments