mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-06-08 00:50:27 +08:00
add browser check and process continue run logic
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
getPublicDbFilePath
|
||||
} from '@geekgeekrun/geek-auto-start-chat-with-boss/runtime-file-utils.mjs'
|
||||
// import { pipeWriteRegardlessError } from '../utils/pipe'
|
||||
import { getAnyAvailablePuppeteerExecutable } from '../DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||
import { sleep } from '@geekgeekrun/utils/sleep.mjs'
|
||||
import { AUTO_CHAT_ERROR_EXIT_CODE } from '../../../common/enums/auto-start-chat'
|
||||
import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited'
|
||||
@@ -19,6 +18,8 @@ import { connectToDaemon, sendToDaemon } from '../OPEN_SETTING_WINDOW/connect-to
|
||||
import { checkShouldExit } from '../../utils/worker'
|
||||
import { CookieInvalidHandlePlugin } from '../../features/cookie-invalid-handle-plugin'
|
||||
import initPublicIpc from '../../utils/initPublicIpc'
|
||||
import { getLastUsedAndAvailableBrowser } from '../DOWNLOAD_DEPENDENCIES/utils/browser-history'
|
||||
import { configWithBrowserAssistant } from '../../features/config-with-browser-assistant'
|
||||
const { default: SqlitePlugin } = SqlitePluginModule
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
@@ -48,8 +49,21 @@ const initPlugins = (hooks) => {
|
||||
const runRecordId = minimist(process.argv.slice(2))['run-record-id'] ?? null
|
||||
const runAutoChat = async () => {
|
||||
app.dock?.hide()
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
let puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
if (!puppeteerExecutable) {
|
||||
try {
|
||||
await configWithBrowserAssistant({ autoFind: true })
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
}
|
||||
if (!puppeteerExecutable) {
|
||||
await dialog.showMessageBox({
|
||||
type: `error`,
|
||||
message: `未找到可用的浏览器`,
|
||||
detail: `请重新运行本程序,按照提示安装、配置浏览器`
|
||||
})
|
||||
sendToDaemon({
|
||||
type: 'worker-to-gui-message',
|
||||
data: {
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { app } from 'electron'
|
||||
import { main, loginEventBus } from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension'
|
||||
import { app, dialog } from 'electron'
|
||||
import {
|
||||
main,
|
||||
loginEventBus
|
||||
} from '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension'
|
||||
import { pipeWriteRegardlessError } from './utils/pipe'
|
||||
import fs from "node:fs";
|
||||
import fs from 'node:fs'
|
||||
import { getLastUsedAndAvailableBrowser } from './DOWNLOAD_DEPENDENCIES/utils/browser-history'
|
||||
import { configWithBrowserAssistant } from '../features/config-with-browser-assistant'
|
||||
|
||||
export const launchBossZhipinLoginPageWithPreloadExtension = async () => {
|
||||
process.on('disconnect', () => app.exit())
|
||||
@@ -18,6 +23,23 @@ export const launchBossZhipinLoginPageWithPreloadExtension = async () => {
|
||||
type: 'INITIALIZE_PUPPETEER'
|
||||
}) + '\r\n'
|
||||
)
|
||||
let puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
if (!puppeteerExecutable) {
|
||||
try {
|
||||
await configWithBrowserAssistant({ autoFind: true })
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
}
|
||||
if (!puppeteerExecutable) {
|
||||
await dialog.showMessageBox({
|
||||
type: `error`,
|
||||
message: `未找到可用的浏览器`,
|
||||
detail: `请重新运行本程序,按照提示安装、配置浏览器`
|
||||
})
|
||||
app.exit(1)
|
||||
}
|
||||
const { initPuppeteer } = await import('@geekgeekrun/geek-auto-start-chat-with-boss/index.mjs')
|
||||
try {
|
||||
await initPuppeteer()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ipcMain, shell, app } from 'electron'
|
||||
import { ipcMain, shell, app, dialog, BrowserWindow } from 'electron'
|
||||
import path from 'path'
|
||||
import * as childProcess from 'node:child_process'
|
||||
import {
|
||||
@@ -328,7 +328,7 @@ export default function initIpc() {
|
||||
|
||||
let subProcessOfOpenBossSiteDefer: null | PromiseWithResolvers<ChildProcess> = null
|
||||
let subProcessOfOpenBossSite: null | ChildProcess = null
|
||||
ipcMain.handle('open-site-with-boss-cookie', async (_, data) => {
|
||||
ipcMain.handle('open-site-with-boss-cookie', async (ev, data) => {
|
||||
const url = data.url
|
||||
if (
|
||||
!subProcessOfOpenBossSiteDefer ||
|
||||
@@ -336,7 +336,31 @@ export default function initIpc() {
|
||||
subProcessOfOpenBossSite.killed
|
||||
) {
|
||||
subProcessOfOpenBossSiteDefer = Promise.withResolvers()
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
let puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
if (!puppeteerExecutable) {
|
||||
try {
|
||||
const parent = BrowserWindow.fromWebContents(ev.sender) || undefined
|
||||
await configWithBrowserAssistant({
|
||||
autoFind: true,
|
||||
windowOption: {
|
||||
parent,
|
||||
modal: !!parent,
|
||||
show: true
|
||||
}
|
||||
})
|
||||
puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
}
|
||||
if (!puppeteerExecutable) {
|
||||
await dialog.showMessageBox({
|
||||
type: `error`,
|
||||
message: `未找到可用的浏览器`,
|
||||
detail: `请重新运行本程序,按照提示安装、配置浏览器`
|
||||
})
|
||||
return
|
||||
}
|
||||
const subProcessEnv = {
|
||||
...process.env,
|
||||
PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable!.executablePath
|
||||
|
||||
@@ -34,11 +34,12 @@ 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 '../DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||
import minimist from 'minimist'
|
||||
import { checkCookieListFormat } from '../../../common/utils/cookie'
|
||||
import { loginWithCookieAssistant } from '../../features/login-with-cookie-assistant'
|
||||
import initPublicIpc from '../../utils/initPublicIpc'
|
||||
import { getLastUsedAndAvailableBrowser } from '../DOWNLOAD_DEPENDENCIES/utils/browser-history'
|
||||
import { configWithBrowserAssistant } from '../../features/config-with-browser-assistant'
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('收到SIGTERM信号,正在退出')
|
||||
@@ -615,8 +616,21 @@ export async function runEntry() {
|
||||
runRecordId
|
||||
}
|
||||
})
|
||||
const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable()
|
||||
let puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
if (!puppeteerExecutable) {
|
||||
try {
|
||||
await configWithBrowserAssistant({ autoFind: true })
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
}
|
||||
if (!puppeteerExecutable) {
|
||||
await dialog.showMessageBox({
|
||||
type: `error`,
|
||||
message: `未找到可用的浏览器`,
|
||||
detail: `请重新运行本程序,按照提示安装、配置浏览器`
|
||||
})
|
||||
sendToDaemon({
|
||||
type: 'worker-to-gui-message',
|
||||
data: {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { ChildProcess } from 'child_process'
|
||||
import { BrowserWindow, ipcMain } from 'electron'
|
||||
import { BrowserWindow, dialog, ipcMain } from 'electron'
|
||||
import path from 'path'
|
||||
import { getAnyAvailablePuppeteerExecutable } from '../flow/DOWNLOAD_DEPENDENCIES/utils/puppeteer-executable'
|
||||
import * as childProcess from 'node:child_process'
|
||||
import * as JSONStream from 'JSONStream'
|
||||
import { getLastUsedAndAvailableBrowser } from '../flow/DOWNLOAD_DEPENDENCIES/utils/browser-history'
|
||||
import { configWithBrowserAssistant } from '../features/config-with-browser-assistant'
|
||||
|
||||
export let cookieAssistantWindow: BrowserWindow | null = null
|
||||
export function createCookieAssistantWindow(
|
||||
@@ -45,15 +46,40 @@ export function createCookieAssistantWindow(
|
||||
})
|
||||
|
||||
let subProcessOfBossZhipinLoginPageWithPreloadExtension: ChildProcess | null = null
|
||||
const launchHandler = async () => {
|
||||
const launchHandler = async (ev) => {
|
||||
try {
|
||||
subProcessOfBossZhipinLoginPageWithPreloadExtension?.kill()
|
||||
} catch {
|
||||
//
|
||||
}
|
||||
let puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
if (!puppeteerExecutable) {
|
||||
try {
|
||||
const parent = BrowserWindow.fromWebContents(ev.sender) || undefined
|
||||
await configWithBrowserAssistant({
|
||||
autoFind: true,
|
||||
windowOption: {
|
||||
parent,
|
||||
modal: !!parent,
|
||||
show: true
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
//
|
||||
}
|
||||
puppeteerExecutable = await getLastUsedAndAvailableBrowser()
|
||||
}
|
||||
if (!puppeteerExecutable) {
|
||||
await dialog.showMessageBox({
|
||||
type: `error`,
|
||||
message: `未找到可用的浏览器`,
|
||||
detail: `请重新运行本程序,按照提示安装、配置浏览器`
|
||||
})
|
||||
return
|
||||
}
|
||||
const subProcessEnv = {
|
||||
...process.env,
|
||||
PUPPETEER_EXECUTABLE_PATH: (await getAnyAvailablePuppeteerExecutable())!.executablePath
|
||||
PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable.executablePath
|
||||
}
|
||||
subProcessOfBossZhipinLoginPageWithPreloadExtension = childProcess.spawn(
|
||||
process.argv[0],
|
||||
|
||||
Reference in New Issue
Block a user