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