mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 00:17:17 +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 { 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 { sendToDaemon } from "../flow/OPEN_SETTING_WINDOW/connect-to-daemon"
|
||||||
import { saveAndGetCurrentRunRecord } from "../flow/OPEN_SETTING_WINDOW/utils/db"
|
import { saveAndGetCurrentRunRecord } from "../flow/OPEN_SETTING_WINDOW/utils/db"
|
||||||
|
|
||||||
export async function runCommon ({ mode }) {
|
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 currentRunRecord = (await saveAndGetCurrentRunRecord())?.data
|
||||||
const subProcessEnv = {
|
const subProcessEnv = {
|
||||||
...process.env,
|
...process.env,
|
||||||
PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable.executablePath,
|
|
||||||
GEEKGEEKRUND_NO_AUTO_RESTART_EXIT_CODE: [
|
GEEKGEEKRUND_NO_AUTO_RESTART_EXIT_CODE: [
|
||||||
AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE,
|
AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE,
|
||||||
AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID,
|
AUTO_CHAT_ERROR_EXIT_CODE.LOGIN_STATUS_INVALID,
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ const initPlugins = (hooks) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const runAutoChat = async () => {
|
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(
|
const { initPuppeteer, mainLoop, closeBrowserWindow, autoStartChatEventBus } = await import(
|
||||||
'@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs'
|
'@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs'
|
||||||
)
|
)
|
||||||
@@ -45,20 +52,7 @@ const runAutoChat = async () => {
|
|||||||
closeBrowserWindow()
|
closeBrowserWindow()
|
||||||
app.exit()
|
app.exit()
|
||||||
})
|
})
|
||||||
app.dock?.hide()
|
await initPuppeteer()
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
const hooks = {
|
const hooks = {
|
||||||
puppeteerLaunched: new SyncHook(['browser']),
|
puppeteerLaunched: new SyncHook(['browser']),
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import cheerio from 'cheerio'
|
|||||||
import { connectToDaemon, sendToDaemon } from '../OPEN_SETTING_WINDOW/connect-to-daemon'
|
import { connectToDaemon, sendToDaemon } from '../OPEN_SETTING_WINDOW/connect-to-daemon'
|
||||||
import { pushCurrentPageScreenshot, SCREENSHOT_INTERVAL_MS } from '../../utils/screenshot'
|
import { pushCurrentPageScreenshot, SCREENSHOT_INTERVAL_MS } from '../../utils/screenshot'
|
||||||
import { checkShouldExit } from '../../utils/worker'
|
import { checkShouldExit } from '../../utils/worker'
|
||||||
|
import { getAnyAvailablePuppeteerExecutable } from '../CHECK_AND_DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||||
|
|
||||||
const throttleIntervalMinutes =
|
const throttleIntervalMinutes =
|
||||||
readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10
|
readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10
|
||||||
@@ -479,6 +480,11 @@ const rerunInterval = (() => {
|
|||||||
|
|
||||||
export async function runEntry() {
|
export async function runEntry() {
|
||||||
app.dock?.hide()
|
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 connectToDaemon()
|
||||||
await sendToDaemon({
|
await sendToDaemon({
|
||||||
type: 'ping'
|
type: 'ping'
|
||||||
@@ -519,7 +525,7 @@ export async function runEntry() {
|
|||||||
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.ACCESS_IS_DENIED)
|
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.ACCESS_IS_DENIED)
|
||||||
break
|
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)
|
process.exit(AUTO_CHAT_ERROR_EXIT_CODE.PUPPETEER_IS_NOT_EXECUTABLE)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user