mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 16:37:06 +08:00
add retry for browser download error
This commit is contained in:
@@ -11,6 +11,7 @@ export enum DOWNLOAD_ERROR_EXIT_CODE {
|
|||||||
|
|
||||||
export const checkAndDownloadDependenciesForInit = async () => {
|
export const checkAndDownloadDependenciesForInit = async () => {
|
||||||
process.on('disconnect', () => app.exit())
|
process.on('disconnect', () => app.exit())
|
||||||
|
process.on('uncaughtException', () => app.exit(DOWNLOAD_ERROR_EXIT_CODE.DOWNLOAD_ERROR))
|
||||||
app.dock?.hide()
|
app.dock?.hide()
|
||||||
let pipe: null | fs.WriteStream = null
|
let pipe: null | fs.WriteStream = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
+14
@@ -9,6 +9,7 @@ import {
|
|||||||
removeLastUsedAndAvailableBrowserPath
|
removeLastUsedAndAvailableBrowserPath
|
||||||
} from '../browser-history'
|
} from '../browser-history'
|
||||||
import gtag from '../../../../utils/gtag'
|
import gtag from '../../../../utils/gtag'
|
||||||
|
import { sleep } from '@geekgeekrun/utils/sleep.mjs';
|
||||||
|
|
||||||
const getPuppeteerManagerModule = async () => {
|
const getPuppeteerManagerModule = async () => {
|
||||||
const puppeteerManager = await import('@puppeteer/browsers')
|
const puppeteerManager = await import('@puppeteer/browsers')
|
||||||
@@ -64,6 +65,9 @@ export const checkAndDownloadPuppeteerExecutable = async (
|
|||||||
} catch {
|
} catch {
|
||||||
throw new Error('USER_CANCEL_DOWNLOAD_PUPPETEER')
|
throw new Error('USER_CANCEL_DOWNLOAD_PUPPETEER')
|
||||||
}
|
}
|
||||||
|
let restRetriedTime = 10
|
||||||
|
while (restRetriedTime > 0) {
|
||||||
|
try {
|
||||||
// maybe the exist installation is broken.
|
// maybe the exist installation is broken.
|
||||||
await puppeteerManager.uninstall({
|
await puppeteerManager.uninstall({
|
||||||
cacheDir,
|
cacheDir,
|
||||||
@@ -77,6 +81,16 @@ export const checkAndDownloadPuppeteerExecutable = async (
|
|||||||
downloadProgressCallback: options.downloadProgressCallback,
|
downloadProgressCallback: options.downloadProgressCallback,
|
||||||
baseUrl: `https://registry.npmmirror.com/-/binary/chrome-for-testing`
|
baseUrl: `https://registry.npmmirror.com/-/binary/chrome-for-testing`
|
||||||
})
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
restRetriedTime--
|
||||||
|
await sleep(5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!installedBrowser) {
|
||||||
|
throw new Error(`浏览器下载失败`)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
gtag('use_installed_browser')
|
gtag('use_installed_browser')
|
||||||
installedBrowser = (
|
installedBrowser = (
|
||||||
|
|||||||
Reference in New Issue
Block a user