mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-30 12:39:58 +08:00
make puppeteer can run from homedir rather than current project node_modules
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
} from '@bossgeekgo/utils/sleep.mjs'
|
||||
|
||||
import fs from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import { get__dirname } from '@bossgeekgo/utils/legacy-path.mjs';
|
||||
import path from 'node:path';
|
||||
import JSON5 from 'json5'
|
||||
@@ -11,20 +12,35 @@ import JSON5 from 'json5'
|
||||
import { readConfigFile, ensureConfigFileExist } from './runtime-file-utils.mjs'
|
||||
ensureConfigFileExist()
|
||||
|
||||
let puppeteer
|
||||
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||
let puppeteer, StealthPlugin
|
||||
async function initPuppeteer () {
|
||||
const [
|
||||
puppeteerModule,
|
||||
StealthPluginModule,
|
||||
] = await Promise.all(
|
||||
[
|
||||
import('puppeteer-extra'),
|
||||
import('puppeteer-extra-plugin-stealth')
|
||||
]
|
||||
)
|
||||
|
||||
puppeteerModule.default.use(StealthPluginModule.default())
|
||||
puppeteer = puppeteerModule.default
|
||||
// production
|
||||
if (
|
||||
isRunFromUi
|
||||
// &&
|
||||
// process.mainModule.filename.indexOf('app.asar') !== -1
|
||||
) {
|
||||
const runtimeDependencies = await import(
|
||||
path.join(
|
||||
os.homedir(),
|
||||
'.bossgeekgo',
|
||||
'external-node-runtime-dependencies/index.mjs'
|
||||
)
|
||||
)
|
||||
puppeteer = runtimeDependencies.puppeteerExtra.default
|
||||
StealthPlugin = runtimeDependencies.PuppeteerExtraPluginStealth.default
|
||||
} else {
|
||||
const importResult = await Promise.all(
|
||||
[
|
||||
import('puppeteer-extra'),
|
||||
import('puppeteer-extra-plugin-stealth')
|
||||
]
|
||||
)
|
||||
puppeteer = importResult[0].default
|
||||
StealthPlugin = importResult[1].default
|
||||
}
|
||||
puppeteer.use(StealthPlugin())
|
||||
}
|
||||
|
||||
const { cookies: bossCookies } = readConfigFile('boss.json')
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"start": "electron-vite preview",
|
||||
"dev": "electron-vite dev",
|
||||
"dev:geek-auto-start-chat-with-boss-only": "MAIN_BOSSGEEKGO_RUN_MODE=geekAutoStartWithBoss electron-vite dev",
|
||||
"dev:geek-auto-start-chat-with-boss-only": "MAIN_BOSSGEEKGO_UI_RUN_MODE=geekAutoStartWithBoss electron-vite dev",
|
||||
"build": "electron-vite build",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { runAutoChat } from './flow/GEEK_AUTO_START_CHAT_WITH_BOSS'
|
||||
import { openSettingWindow } from './flow/OPEN_SETTING_WINDOW'
|
||||
|
||||
const runMode = process.env.MAIN_BOSSGEEKGO_RUN_MODE
|
||||
const runMode = process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE
|
||||
switch (runMode) {
|
||||
case 'geekAutoStartWithBoss': {
|
||||
runAutoChat()
|
||||
|
||||
@@ -87,7 +87,7 @@ export function createMainWindow(): void {
|
||||
}
|
||||
try {
|
||||
await import('@bossgeekgo/geek-auto-start-chat-with-boss/index.mjs')
|
||||
} catch (err){
|
||||
} catch (err) {
|
||||
console.log(err) // TODO: what's the error?
|
||||
throw new Error('PUPPETEER_MAY_NOT_INSTALLED')
|
||||
}
|
||||
@@ -95,7 +95,7 @@ export function createMainWindow(): void {
|
||||
subProcessOfPuppeteer = childProcess.spawn(process.argv[0], process.argv.slice(1), {
|
||||
env: {
|
||||
...process.env,
|
||||
MAIN_BOSSGEEKGO_RUN_MODE: 'geekAutoStartWithBoss'
|
||||
MAIN_BOSSGEEKGO_UI_RUN_MODE: 'geekAutoStartWithBoss'
|
||||
}
|
||||
})
|
||||
ipcMain.emit('geek-auto-start-chat-with-boss-started')
|
||||
|
||||
Reference in New Issue
Block a user