()
| 247 | } |
| 248 | |
| 249 | export async function checkForAppUpdates(): Promise<AppUpdateState> { |
| 250 | initAppUpdater() |
| 251 | if (!updater) return getAppUpdateState() |
| 252 | if (updateState.phase === 'checking') return getAppUpdateState() |
| 253 | |
| 254 | setUpdateState( |
| 255 | nextStateFromInfo('checking', lastInfo, 'Checking GitHub releases for updates…') |
| 256 | ) |
| 257 | |
| 258 | for (let attempt = 1; attempt <= UPDATE_CHECK_MAX_ATTEMPTS; attempt += 1) { |
| 259 | try { |
| 260 | await updater.checkForUpdates() |
| 261 | return getAppUpdateState() |
| 262 | } catch (error) { |
| 263 | const retryable = isRetryableUpdateError(error) |
| 264 | const hasAttemptsLeft = attempt < UPDATE_CHECK_MAX_ATTEMPTS |
| 265 | if (retryable && hasAttemptsLeft) { |
| 266 | setUpdateState( |
| 267 | nextStateFromInfo( |
| 268 | 'checking', |
| 269 | lastInfo, |
| 270 | `GitHub update check hit a temporary server error. Retrying (${attempt + 1}/${UPDATE_CHECK_MAX_ATTEMPTS})…` |
| 271 | ) |
| 272 | ) |
| 273 | await sleep(UPDATE_CHECK_RETRY_DELAY_MS) |
| 274 | continue |
| 275 | } |
| 276 | |
| 277 | setUpdateState( |
| 278 | nextStateFromInfo('error', lastInfo, humanizeUpdateError(error)) |
| 279 | ) |
| 280 | break |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return getAppUpdateState() |
| 285 | } |
| 286 | |
| 287 | export function scheduleBackgroundAppUpdateCheck( |
| 288 | delayMs: number = BACKGROUND_UPDATE_CHECK_DELAY_MS |
no test coverage detected