add puppeteer download finish and error status

This commit is contained in:
bossgeekgo
2024-02-16 07:53:25 +08:00
parent 962e47486f
commit 5bcfb280e8
5 changed files with 39 additions and 23 deletions

View File

@@ -15,17 +15,31 @@ export const checkAndDownloadDependenciesForInit = async () => {
}) + '\r\n'
)
const browser = await checkAndDownloadPuppeteer({
downloadProgressCallback(downloadedBytes: number, totalBytes: number) {
pipe?.write(
JSON.stringify({
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
totalBytes,
downloadedBytes
})
) + '\r\n'
}
})
let browser
try {
browser = await checkAndDownloadPuppeteer({
downloadProgressCallback(downloadedBytes: number, totalBytes: number) {
pipe?.write(
JSON.stringify({
type: 'PUPPETEER_DOWNLOAD_PROGRESS',
totalBytes,
downloadedBytes
})
) + '\r\n'
}
})
pipe?.write(
JSON.stringify({
type: 'PUPPETEER_DOWNLOAD_FINISHED'
})
) + '\r\n'
} catch (err) {
pipe?.write(
JSON.stringify({
type: 'PUPPETEER_DOWNLOAD_ERROR'
})
) + '\r\n'
}
console.log(browser)
}

View File

@@ -68,10 +68,9 @@ export const runAutoChat = async () => {
(raw) => {
const data = raw
switch (data.type) {
case 'NEED_RESETUP_DEPENDENCIES': {
pipe?.write(JSON.stringify(data) + '\r\n')
break
}
case 'NEED_RESETUP_DEPENDENCIES':
case 'PUPPETEER_DOWNLOAD_ERROR':
case 'PUPPETEER_DOWNLOAD_FINISHED':
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
pipe?.write(JSON.stringify(data) + '\r\n')
break

View File

@@ -112,12 +112,10 @@ export function createMainWindow(): void {
resolve(data)
break
}
case 'NEED_RESETUP_DEPENDENCIES': {
mainWindow.webContents.send('NEED_RESETUP_DEPENDENCIES', data)
break
}
case 'NEED_RESETUP_DEPENDENCIES':
case 'PUPPETEER_DOWNLOAD_FINISHED':
case 'PUPPETEER_DOWNLOAD_PROGRESS': {
mainWindow.webContents.send('PUPPETEER_DOWNLOAD_PROGRESS', data)
mainWindow.webContents.send(data.type, data)
break
}
default: {

View File

@@ -13,6 +13,6 @@ const handleProgress = (ev, { downloadedBytes, totalBytes }) => {
}
electron.ipcRenderer.on('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress)
onUnmounted(
() => electron.ipcRenderer.off('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress)
() => electron.ipcRenderer.removeListener('PUPPETEER_DOWNLOAD_PROGRESS', handleProgress)
)
</script>

View File

@@ -122,10 +122,15 @@ const shouldShowDependenciesWarmingUpDialog = ref(false)
const needWarmingUpDenpendenciesHandler = () => {
shouldShowDependenciesWarmingUpDialog.value = true
const handlePuppeteerDownloadFinished = () => {
shouldShowDependenciesWarmingUpDialog.value = false
}
electron.ipcRenderer.once('PUPPETEER_DOWNLOAD_FINISHED', handlePuppeteerDownloadFinished)
}
electron.ipcRenderer.on('NEED_CONFIGURATE_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
electron.ipcRenderer.on('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
onUnmounted(
() => electron.ipcRenderer.off('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
() => electron.ipcRenderer.removeListener('NEED_RESETUP_DEPENDENCIES', needWarmingUpDenpendenciesHandler)
)
</script>