mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-07 05:02:50 +08:00
move find browser logic into util process
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import { AUTO_CHAT_ERROR_EXIT_CODE } from "../../common/enums/auto-start-chat"
|
||||
import { getAnyAvailablePuppeteerExecutable } from "../flow/CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable"
|
||||
import { sendToDaemon } from "../flow/OPEN_SETTING_WINDOW/connect-to-daemon"
|
||||
import { saveAndGetCurrentRunRecord } from "../flow/OPEN_SETTING_WINDOW/utils/db"
|
||||
|
||||
export async function runCommon ({ mode }) {
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
if (!puppeteerExecutable) {
|
||||
return Promise.reject('NEED_TO_CHECK_RUNTIME_DEPENDENCIES')
|
||||
}
|
||||
const currentRunRecord = (await saveAndGetCurrentRunRecord())?.data
|
||||
const subProcessEnv = {
|
||||
...process.env,
|
||||
PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable.executablePath,
|
||||
GEEKGEEKRUND_NO_AUTO_RESTART_EXIT_CODE: [
|
||||
AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE,
|
||||
AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID,
|
||||
|
||||
@@ -38,6 +38,13 @@ const initPlugins = (hooks) => {
|
||||
}
|
||||
|
||||
const runAutoChat = async () => {
|
||||
app.dock?.hide()
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
if (!puppeteerExecutable) {
|
||||
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||
return
|
||||
}
|
||||
process.env.PUPPETEER_EXECUTABLE_PATH = puppeteerExecutable.executablePath
|
||||
const { initPuppeteer, mainLoop, closeBrowserWindow, autoStartChatEventBus } = await import(
|
||||
'@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs'
|
||||
)
|
||||
@@ -45,20 +52,7 @@ const runAutoChat = async () => {
|
||||
closeBrowserWindow()
|
||||
app.exit()
|
||||
})
|
||||
app.dock?.hide()
|
||||
try {
|
||||
await initPuppeteer()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||
return
|
||||
}
|
||||
|
||||
const isPuppeteerExecutable = !!(await getAnyAvailablePuppeteerExecutable())
|
||||
if (!isPuppeteerExecutable) {
|
||||
app.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||
return
|
||||
}
|
||||
await initPuppeteer()
|
||||
|
||||
const hooks = {
|
||||
puppeteerLaunched: new SyncHook(['browser']),
|
||||
|
||||
@@ -27,6 +27,7 @@ import cheerio from 'cheerio'
|
||||
import { connectToDaemon, sendToDaemon } from '../OPEN_SETTING_WINDOW/connect-to-daemon'
|
||||
import { pushCurrentPageScreenshot, SCREENSHOT_INTERVAL_MS } from '../../utils/screenshot'
|
||||
import { checkShouldExit } from '../../utils/worker'
|
||||
import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||
|
||||
const throttleIntervalMinutes =
|
||||
readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10
|
||||
@@ -479,6 +480,11 @@ const rerunInterval = (() => {
|
||||
|
||||
export async function runEntry() {
|
||||
app.dock?.hide()
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
if (!puppeteerExecutable) {
|
||||
throw new Error(`PUPPETEER_IS_NOT_EXECUTABLE`)
|
||||
}
|
||||
process.env.PUPPETEER_EXECUTABLE_PATH = puppeteerExecutable.executablePath
|
||||
await connectToDaemon()
|
||||
await sendToDaemon({
|
||||
type: 'ping'
|
||||
@@ -519,7 +525,7 @@ export async function runEntry() {
|
||||
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.ACCESS_IS_DENIED)
|
||||
break
|
||||
}
|
||||
if (err.message.includes(`Could not find Chrome`) || err.message.includes(`no executable was found`)) {
|
||||
if (err.message.includes(`PUPPETEER_IS_NOT_EXECUTABLE`) || err.message.includes(`Could not find Chrome`) || err.message.includes(`no executable was found`)) {
|
||||
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user