mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-08-29 03:56:51 +08:00
add chrome for puppeteer downloader
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
import * as path from 'node:path'
|
||||
import * as os from 'node:os'
|
||||
import * as fs from 'node:fs'
|
||||
import type { InstalledBrowser } from '@puppeteer/browsers'
|
||||
|
||||
const expectBuildId = process.env.EXPECT_CHROME_FOR_PUPPETEER_BUILD_ID || '121.0.6167.85'
|
||||
const cacheDir = path.join(
|
||||
os.homedir(),
|
||||
'.bossgeekgo',
|
||||
'external-node-runtime-dependencies',
|
||||
'static'
|
||||
)
|
||||
|
||||
const checkAndDownloadPuppeteer = async (options: {
|
||||
downloadProgressCallback?: (downloadedBytes: number, totalBytes: number) => void
|
||||
}) => {
|
||||
const puppeteerManager = await import('@puppeteer/browsers')
|
||||
const executablePath = puppeteerManager.computeExecutablePath({
|
||||
browser: puppeteerManager.Browser.CHROME,
|
||||
cacheDir,
|
||||
buildId: expectBuildId
|
||||
})
|
||||
let installedBrowser: InstalledBrowser
|
||||
if (!fs.existsSync(executablePath)) {
|
||||
// maybe the exist installation is broken.
|
||||
await puppeteerManager.uninstall({
|
||||
cacheDir,
|
||||
buildId: expectBuildId,
|
||||
browser: puppeteerManager.Browser.CHROME,
|
||||
})
|
||||
installedBrowser = await puppeteerManager.install({
|
||||
browser: puppeteerManager.Browser.CHROME,
|
||||
cacheDir,
|
||||
buildId: expectBuildId,
|
||||
downloadProgressCallback: options.downloadProgressCallback
|
||||
})
|
||||
} else {
|
||||
installedBrowser = (
|
||||
await puppeteerManager.getInstalledBrowsers({
|
||||
cacheDir
|
||||
})
|
||||
).find((it) => it.buildId === expectBuildId)!
|
||||
}
|
||||
|
||||
return installedBrowser
|
||||
}
|
||||
|
||||
export default checkAndDownloadPuppeteer
|
||||
@@ -0,0 +1,11 @@
|
||||
import checkAndDownloadPuppeteer from './check-and-download-puppeteer'
|
||||
|
||||
export const checkAndDownloadDependenciesForInit = async () => {
|
||||
const browser = await checkAndDownloadPuppeteer({
|
||||
downloadProgressCallback(downloadedBytes: number, totalBytes: number) {
|
||||
console.log(`${downloadedBytes} / ${totalBytes}`)
|
||||
}
|
||||
})
|
||||
|
||||
console.log(browser)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { runAutoChat } from './flow/GEEK_AUTO_START_CHAT_WITH_BOSS'
|
||||
import { openSettingWindow } from './flow/OPEN_SETTING_WINDOW'
|
||||
import { checkAndDownloadDependenciesForInit } from './flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/index';
|
||||
|
||||
const runMode = process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE
|
||||
switch (runMode) {
|
||||
@@ -7,6 +8,10 @@ switch (runMode) {
|
||||
runAutoChat()
|
||||
break
|
||||
}
|
||||
case 'checkAndDownloadDependenciesForInit': {
|
||||
checkAndDownloadDependenciesForInit()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
openSettingWindow()
|
||||
break
|
||||
|
||||
@@ -96,6 +96,7 @@ export function createMainWindow(): void {
|
||||
env: {
|
||||
...process.env,
|
||||
MAIN_BOSSGEEKGO_UI_RUN_MODE: 'geekAutoStartWithBoss'
|
||||
// PUPPETEER_EXECUTABLE_PATH: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'
|
||||
}
|
||||
})
|
||||
ipcMain.emit('geek-auto-start-chat-with-boss-started')
|
||||
|
||||
Reference in New Issue
Block a user