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