1
- import { dialog , shell } from 'electron'
1
+ import { app , dialog , shell } from 'electron'
2
2
import { autoUpdater } from 'electron-updater'
3
3
import { t } from 'i18next'
4
4
5
- import { configStore , icon , isLinux , isMac } from './constants'
6
- import { logError , logInfo , LogPrefix } from './logger/logger'
5
+ import { configStore , icon , isLinux } from '. ./constants'
6
+ import { logError , logInfo , LogPrefix } from '.. /logger/logger'
7
7
import { captureException } from '@sentry/electron'
8
- import { getFileSize } from './utils'
8
+ import { getFileSize } from '.. /utils'
9
9
import { ClientUpdateStatuses } from '@hyperplay/utils'
10
- import { trackEvent } from './metrics/metrics'
11
- import { homedir } from 'os'
12
- import { join } from 'path'
13
- import { rm } from 'fs/promises'
10
+ import { trackEvent } from '../metrics/metrics'
11
+ import { getErrorMessage , removeCachedUpdatesFolder } from './utils'
14
12
// to test auto update on windows locally make sure you added the option verifyUpdateCodeSignature: false
15
13
// under build.win in electron-builder.yml and also change the app version to an old one there
16
14
@@ -23,11 +21,12 @@ autoUpdater.autoInstallOnAppQuit = true
23
21
24
22
let isAppUpdating = false
25
23
let hasUpdated = false
24
+
26
25
let updateAttempts = 0
27
26
const MAX_UPDATE_ATTEMPTS = 10
27
+ // check for updates every 3 hours
28
+ const checkUpdateInterval = 3 * 1000 * 60 * 60
28
29
29
- // check for updates every hour
30
- const checkUpdateInterval = 1 * 1000 * 60 * 60
31
30
setInterval ( async ( ) => {
32
31
if ( shouldCheckForUpdates && ! hasUpdated && ! isAppUpdating ) {
33
32
logInfo ( 'Checking for client updates...' , LogPrefix . AutoUpdater )
@@ -115,17 +114,18 @@ autoUpdater.on('update-downloaded', async () => {
115
114
116
115
autoUpdater . on ( 'error' , async ( error ) => {
117
116
isAppUpdating = false
117
+ const isNewVersion = newVersion !== app . getVersion ( )
118
118
119
119
// To avoid false positives, we should not show the error dialog if the app has already updated successfully
120
- if ( hasUpdated || ! newVersion ) {
120
+ if ( hasUpdated || ! isNewVersion ) {
121
121
return
122
122
}
123
123
124
124
const errorMessage = getErrorMessage ( error . message )
125
125
logError ( `Error updating HyperPlay: ${ errorMessage } ` , LogPrefix . AutoUpdater )
126
126
127
127
// will remove cached updates when it fails to avoid corrupted updates
128
- if ( updateAttempts > 2 ) {
128
+ if ( updateAttempts > 3 ) {
129
129
await removeCachedUpdatesFolder ( )
130
130
}
131
131
@@ -184,119 +184,3 @@ export function isClientUpdating(): ClientUpdateStatuses {
184
184
}
185
185
return isAppUpdating ? 'updating' : 'idle'
186
186
}
187
-
188
- async function removeCachedUpdatesFolder ( ) {
189
- // remove hyperplay-updates folder from cache directory
190
- // on macOS: /Users/<username>/Library/Caches/hyperplay-updates
191
- // on Windows: C:\Users\<username>\AppData\Local\hyperplay-updates
192
- const macOSPath = join ( homedir ( ) , 'Library' , 'Caches' , 'hyperplay-updates' )
193
- const windowsPath = join ( homedir ( ) , 'AppData' , 'Local' , 'hyperplay-updates' )
194
-
195
- try {
196
- await rm ( isMac ? macOSPath : windowsPath , { recursive : true } )
197
- } catch ( error ) {
198
- logError (
199
- `Error removing cached updates folder: ${ error } ` ,
200
- LogPrefix . AutoUpdater
201
- )
202
- }
203
- }
204
-
205
- const commonDownloadErrors : Record < string , ( ) => string > = {
206
- ERR_NETWORK_CHANGED : ( ) =>
207
- t (
208
- 'box.error.update.networkChanged' ,
209
- 'Network changed. Please check your internet connection.'
210
- ) ,
211
- ERR_INTERNET_DISCONNECTED : ( ) =>
212
- t (
213
- 'box.error.update.internetDisconnected' ,
214
- 'Internet disconnected. Please check your internet connection.'
215
- ) ,
216
- ERR_CONNECTION_RESET : ( ) =>
217
- t (
218
- 'box.error.update.connectionReset' ,
219
- 'Connection reset. Please check your internet connection.'
220
- ) ,
221
- ERR_CONNECTION_CLOSED : ( ) =>
222
- t (
223
- 'box.error.update.connectionClosed' ,
224
- 'Connection closed. Please check your internet connection.'
225
- ) ,
226
- ERR_CONNECTION_TIMED_OUT : ( ) =>
227
- t (
228
- 'box.error.update.connectionTimedOut' ,
229
- 'Connection timed out. Please check your internet connection.'
230
- ) ,
231
- ERR_NAME_NOT_RESOLVED : ( ) =>
232
- t (
233
- 'box.error.update.nameNotResolved' ,
234
- 'Name not resolved. Please check your internet connection.'
235
- ) ,
236
- ERR_CONNECTION_REFUSED : ( ) =>
237
- t (
238
- 'box.error.update.connectionRefused' ,
239
- 'Connection refused. Please check your internet connection.'
240
- ) ,
241
- ERR_SSL_PROTOCOL_ERROR : ( ) =>
242
- t (
243
- 'box.error.update.sslProtocolError' ,
244
- 'SSL protocol error. Please check your system time and date or open a ticket with HyperPlay support.'
245
- ) ,
246
- ERR_CERT_AUTHORITY_INVALID : ( ) =>
247
- t (
248
- 'box.error.update.certAuthorityInvalid' ,
249
- 'Certificate authority invalid. Please check your system time and date or open a ticket with HyperPlay support.'
250
- ) ,
251
- ERR_NETWORK_ACCESS_DENIED : ( ) =>
252
- t (
253
- 'box.error.update.networkAccessDenied' ,
254
- 'Network access denied. Please check your internet connection.'
255
- ) ,
256
- ERR_PROXY_CONNECTION_FAILED : ( ) =>
257
- t (
258
- 'box.error.update.proxyConnectionFailed' ,
259
- 'Proxy connection failed. Please check your proxy settings.'
260
- ) ,
261
- ERR_CONNECTION_ABORTED : ( ) =>
262
- t (
263
- 'box.error.update.connectionAborted' ,
264
- 'Connection aborted. Please check your internet connection.'
265
- ) ,
266
- ERR_ADDRESS_UNREACHABLE : ( ) =>
267
- t (
268
- 'box.error.update.addressUnreachable' ,
269
- 'Address unreachable. Please check your internet connection.'
270
- ) ,
271
- ERR_CERT_DATE_INVALID : ( ) =>
272
- t (
273
- 'box.error.update.certDateInvalid' ,
274
- 'Certificate date invalid. Please check your system time and date or open a ticket with HyperPlay support.'
275
- ) ,
276
- ERR_HTTP2_SERVER_REFUSED_STREAM : ( ) =>
277
- t (
278
- 'box.error.update.http2ServerRefusedStream' ,
279
- 'HTTP2 server refused stream. Please check your internet connection.'
280
- ) ,
281
- ERR_EMPTY_RESPONSE : ( ) =>
282
- t (
283
- 'box.error.update.emptyResponse' ,
284
- 'Empty response. Please check your internet connection.'
285
- ) ,
286
- ERR_FAILED : ( ) =>
287
- t (
288
- 'box.error.update.failed' ,
289
- 'Download Failed. Please check your internet connection.'
290
- )
291
- }
292
-
293
- function getErrorMessage ( error : string ) : string {
294
- const trimmedError = error . replace ( 'net::' , '' ) . trim ( )
295
- if (
296
- Object . prototype . hasOwnProperty . call ( commonDownloadErrors , trimmedError )
297
- ) {
298
- return commonDownloadErrors [ trimmedError ] ( )
299
- } else {
300
- return error
301
- }
302
- }
0 commit comments