Skip to content

Commit 0260ca7

Browse files
committed
Merge branch 'main' into quests/improve_logging
2 parents 392fe02 + a98744a commit 0260ca7

File tree

8 files changed

+243
-36
lines changed

8 files changed

+243
-36
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@hyperplay/chains": "^0.5.0",
7474
"@hyperplay/check-disk-space": "^3.5.2",
7575
"@hyperplay/quests-ui": "^0.1.25",
76-
"@hyperplay/ui": "^1.9.8",
76+
"@hyperplay/ui": "^1.9.9",
7777
"@hyperplay/utils": "^0.3.7",
7878
"@mantine/carousel": "^7.12.0",
7979
"@mantine/core": "^7.12.0",

pnpm-lock.yaml

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/locales/en/translation.json

+19-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,25 @@
8888
"title": "Ubisoft Connect"
8989
},
9090
"update": {
91-
"message": "Something went wrong with the update! Please manually uninstall and reinstall HyperPlay.",
92-
"title": "Update Error"
91+
"addressUnreachable": "Address unreachable. Please check your internet connection.",
92+
"body": "Something went wrong with the update after multiple attempts! Please check the error message below or reinstall HyperPlay. error: {{error}}",
93+
"certAuthorityInvalid": "Certificate authority invalid. Please check your system time and date or open a ticket with HyperPlay support.",
94+
"certDateInvalid": "Certificate date invalid. Please check your system time and date or open a ticket with HyperPlay support.",
95+
"connectionAborted": "Connection aborted. Please check your internet connection.",
96+
"connectionClosed": "Connection closed. Please check your internet connection.",
97+
"connectionRefused": "Connection refused. Please check your internet connection.",
98+
"connectionReset": "Connection reset. Please check your internet connection.",
99+
"connectionTimedOut": "Connection timed out. Please check your internet connection.",
100+
"emptyResponse": "Empty response. Please check your internet connection.",
101+
"failed": "Download Failed. Please check your internet connection.",
102+
"http2ServerRefusedStream": "HTTP2 server refused stream. Please check your internet connection.",
103+
"internetDisconnected": "Internet disconnected. Please check your internet connection.",
104+
"message": "Error Updating",
105+
"nameNotResolved": "Name not resolved. Please check your internet connection.",
106+
"networkAccessDenied": "Network access denied. Please check your internet connection.",
107+
"networkChanged": "Network changed. Please check your internet connection.",
108+
"proxyConnectionFailed": "Proxy connection failed. Please check your proxy settings.",
109+
"sslProtocolError": "SSL protocol error. Please check your system time and date or open a ticket with HyperPlay support."
93110
},
94111
"winetricks": {
95112
"message": "Winetricks returned the following error during execution:{{newLine}}{{error}}",

src/backend/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ import {
151151
checkWineBeforeLaunch,
152152
runWineCommandOnGame
153153
} from './utils/compatibility_layers'
154-
import { isClientUpdating } from 'backend/updater'
154+
import { isClientUpdating } from 'backend/updater/updater'
155155

156156
/*
157157
* INSERT OTHER IPC HANDLERS HERE

src/backend/metrics/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ export interface ClientUpdateNotified {
399399
sensitiveProperties?: never
400400
}
401401

402+
export interface ClientUpdateDownloading {
403+
event: 'Downloading Client Update'
404+
properties: {
405+
currentVersion: string
406+
newVersion: string
407+
}
408+
sensitiveProperties?: never
409+
}
410+
402411
export interface ClientUpdateError {
403412
event: 'Client Update Error'
404413
properties: {
@@ -460,6 +469,7 @@ export type PossibleMetricPayloads =
460469
| RewardClaimSuccess
461470
| RewardClaimError
462471
| ClientUpdateNotified
472+
| ClientUpdateDownloading
463473
| ClientUpdateError
464474
| ClientUpdateDownloaded
465475
| PatchingStarted

src/backend/updater.ts src/backend/updater/updater.ts

+83-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { dialog, shell } from 'electron'
1+
import { app, dialog, shell } from 'electron'
22
import { autoUpdater } from 'electron-updater'
33
import { t } from 'i18next'
44

5-
import { configStore, icon, isLinux } from './constants'
6-
import { logError, logInfo, LogPrefix } from './logger/logger'
7-
import { isOnline } from './online_monitor'
5+
import { configStore, icon, isLinux } from '../constants'
6+
import { logError, logInfo, LogPrefix } from '../logger/logger'
87
import { captureException } from '@sentry/electron'
9-
import { getFileSize } from './utils'
8+
import { getFileSize } from '../utils'
109
import { ClientUpdateStatuses } from '@hyperplay/utils'
11-
import { trackEvent } from './metrics/metrics'
12-
// to test auto update on windows locally make sure you added the option "verifyUpdateCodeSignature": false
13-
// under build.win in package.json and also change the app version to an old one there
10+
import { trackEvent } from '../metrics/metrics'
11+
import { getErrorMessage, removeCachedUpdatesFolder } from './utils'
12+
// to test auto update on windows locally make sure you added the option verifyUpdateCodeSignature: false
13+
// under build.win in electron-builder.yml and also change the app version to an old one there
1414

1515
const appSettings = configStore.get_nodefault('settings')
1616
const shouldCheckForUpdates = appSettings?.checkForUpdatesOnStartup === true
@@ -21,17 +21,35 @@ autoUpdater.autoInstallOnAppQuit = true
2121

2222
let isAppUpdating = false
2323
let hasUpdated = false
24+
let hasReportedDownloadStart = false
2425

25-
// check for updates every hour
26-
const checkUpdateInterval = 1 * 60 * 60 * 1000
27-
setInterval(() => {
28-
if (isOnline() && shouldCheckForUpdates) {
29-
autoUpdater.checkForUpdates()
26+
let updateAttempts = 0
27+
const MAX_UPDATE_ATTEMPTS = 10
28+
// check for updates every 3 hours
29+
const checkUpdateInterval = 3 * 1000 * 60 * 60
30+
31+
setInterval(async () => {
32+
if (shouldCheckForUpdates && !hasUpdated && !isAppUpdating) {
33+
logInfo('Checking for client updates...', LogPrefix.AutoUpdater)
34+
await autoUpdater.checkForUpdates()
3035
}
3136
}, checkUpdateInterval)
3237

3338
autoUpdater.on('update-available', async (info) => {
34-
if (!isOnline() || !shouldCheckForUpdates) {
39+
if (isAppUpdating && hasUpdated) {
40+
logInfo(
41+
'New update available, but user has already updated the app',
42+
LogPrefix.AutoUpdater
43+
)
44+
return
45+
}
46+
47+
if (!shouldCheckForUpdates) {
48+
logInfo(
49+
'New update available, but user has disabled auto updates',
50+
LogPrefix.AutoUpdater
51+
)
52+
3553
return
3654
}
3755
newVersion = info.version
@@ -56,6 +74,19 @@ autoUpdater.on('update-available', async (info) => {
5674
// log download progress
5775
autoUpdater.on('download-progress', (progress) => {
5876
isAppUpdating = true
77+
78+
// Track download start only once
79+
if (!hasReportedDownloadStart) {
80+
trackEvent({
81+
event: 'Downloading Client Update',
82+
properties: {
83+
currentVersion: autoUpdater.currentVersion.version,
84+
newVersion
85+
}
86+
})
87+
hasReportedDownloadStart = true
88+
}
89+
5990
logInfo(
6091
'Downloading HyperPlay update...' +
6192
`Download speed: ${progress.bytesPerSecond}, ` +
@@ -68,7 +99,10 @@ autoUpdater.on('download-progress', (progress) => {
6899
})
69100

70101
autoUpdater.on('update-downloaded', async () => {
71-
logInfo('App update is downloaded')
102+
logInfo('The App update was downloaded', LogPrefix.AutoUpdater)
103+
hasUpdated = true
104+
isAppUpdating = false
105+
hasReportedDownloadStart = false // Reset for potential future updates
72106

73107
trackEvent({
74108
event: 'Client Update Downloaded',
@@ -91,16 +125,38 @@ autoUpdater.on('update-downloaded', async () => {
91125
if (response === 1) {
92126
return autoUpdater.quitAndInstall()
93127
}
94-
hasUpdated = true
128+
logInfo('User chose not to update the app for now.', LogPrefix.AutoUpdater)
95129
})
96130

97131
autoUpdater.on('error', async (error) => {
98-
if (!isOnline()) {
132+
isAppUpdating = false
133+
const isNewVersion = newVersion !== app.getVersion()
134+
135+
// To avoid false positives, we should not show the error dialog if the app has already updated successfully
136+
if (hasUpdated || !isNewVersion) {
99137
return
100138
}
101139

102-
isAppUpdating = false
103-
logError(`Error updating HyperPlay: ${error.message}`, LogPrefix.AutoUpdater)
140+
const errorMessage = getErrorMessage(error.message)
141+
logError(`Error updating HyperPlay: ${errorMessage}`, LogPrefix.AutoUpdater)
142+
143+
// will remove cached updates when it fails to avoid corrupted updates
144+
if (updateAttempts > 3) {
145+
await removeCachedUpdatesFolder()
146+
}
147+
148+
updateAttempts++
149+
150+
if (updateAttempts < MAX_UPDATE_ATTEMPTS) {
151+
logInfo(
152+
`Retrying update attempt ${updateAttempts + 1}/${MAX_UPDATE_ATTEMPTS}`,
153+
LogPrefix.AutoUpdater
154+
)
155+
setTimeout(() => {
156+
autoUpdater.checkForUpdates()
157+
}, 6000)
158+
return
159+
}
104160

105161
trackEvent({
106162
event: 'Client Update Error',
@@ -115,17 +171,19 @@ autoUpdater.on('error', async (error) => {
115171
tags: {
116172
event: 'Client Update Error',
117173
currentVersion: autoUpdater.currentVersion.version,
118-
newVersion
174+
newVersion,
175+
totalAttempts: MAX_UPDATE_ATTEMPTS
119176
}
120177
})
121178

179+
updateAttempts = 0
180+
122181
const { response } = await dialog.showMessageBox({
123-
title: t('box.error.update.title', 'Error Updating'),
182+
title: t('box.error.update.message', 'Error Updating'),
124183
message: t(
125-
'box.error.update.message',
126-
`Something went wrong with the update after multiple attempts! Please manually uninstall and reinstall HyperPlay. error: ${JSON.stringify(
127-
error
128-
)}`
184+
'box.error.update.body',
185+
`Something went wrong with the update after multiple attempts! Please check the error message below or reinstall HyperPlay. error: {{error}}`,
186+
{ error: errorMessage }
129187
),
130188
type: 'error',
131189
buttons: [t('button.cancel', 'Cancel'), t('button.download', 'Download')]

0 commit comments

Comments
 (0)