diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 675b939..3a6256f 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -46,7 +46,6 @@ industryFilterExemption.forEach(item => { ensureConfigFileExist() ensureStorageFileExist() -const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) const isUiDev = process.env.NODE_ENV === 'development' export const autoStartChatEventBus = new EventEmitter() diff --git a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs index cecd3cd..2d67930 100644 --- a/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs +++ b/packages/launch-bosszhipin-login-page-with-preload-extension/index.mjs @@ -17,7 +17,6 @@ import { runtimeFolderPath, ensureEditThisCookie, editThisCookieExtensionPath, - isRunFromUi, } from './utils.mjs' import { EventEmitter } from 'node:events' @@ -56,10 +55,8 @@ export async function main() { page.once('close', async () => { browser.close() - if (isRunFromUi) { - const electron = await import('electron') - electron.app.quit() - } + const electron = await import('electron') + electron.app.quit() }) const { dispose: disposeNavigationLock } = await blockNavigation(page, (req) => !req.url().startsWith('https://www.zhipin.com')) diff --git a/packages/launch-bosszhipin-login-page-with-preload-extension/utils.mjs b/packages/launch-bosszhipin-login-page-with-preload-extension/utils.mjs index da1f6f8..aa66d5d 100644 --- a/packages/launch-bosszhipin-login-page-with-preload-extension/utils.mjs +++ b/packages/launch-bosszhipin-login-page-with-preload-extension/utils.mjs @@ -4,7 +4,6 @@ import os from 'node:os' import extractZip from 'extract-zip' import packageJson from './package.json' assert {type: 'json'} -export const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) const isUiDev = process.env.NODE_ENV === 'development' export const runtimeFolderPath = path.join(os.homedir(), '.geekgeekrun') @@ -28,12 +27,8 @@ async function getEditThisCookieZipPath () { if (editThisCookieZipPath) { return editThisCookieZipPath } - if (isRunFromUi) { - const { app } = await import('electron') - editThisCookieZipPath = path.join(app.getAppPath(), './node_modules', packageJson.name, 'extensions', 'EditThisCookie.zip') - } else { - editThisCookieZipPath = path.join(__dirname, 'extensions', 'EditThisCookie.zip') - } + const { app } = await import('electron') + editThisCookieZipPath = path.join(app.getAppPath(), './node_modules', packageJson.name, 'extensions', 'EditThisCookie.zip') return editThisCookieZipPath } diff --git a/packages/sqlite-plugin/src/utils/module-loader.ts b/packages/sqlite-plugin/src/utils/module-loader.ts index 43a8b05..ff7ea5d 100644 --- a/packages/sqlite-plugin/src/utils/module-loader.ts +++ b/packages/sqlite-plugin/src/utils/module-loader.ts @@ -1,7 +1,3 @@ -import * as path from 'node:path'; -const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) -const isUiDev = process.env.NODE_ENV === 'development' - export function requireTypeorm () { const importResult = require('typeorm') return importResult diff --git a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_DAEMON/index.ts b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_DAEMON/index.ts index cabd96d..0427f07 100644 --- a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_DAEMON/index.ts +++ b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_DAEMON/index.ts @@ -25,14 +25,10 @@ function runWithDaemon({ runRecordId, runMode, parentProcessPipe }) { const subProcessOfCore = childProcess.spawn( process.argv[0], isUiDev - ? [...process.argv.slice(1), `--run-record-id=${runRecordId}`] - : [`--run-record-id=${runRecordId}`], + ? [process.argv[1], `--run-record-id=${runRecordId}`, `--mode=${runMode}`] + : [`--run-record-id=${runRecordId}`, `--mode=${runMode}`], { - stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'ipc'], - env: { - ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: runMode - } + stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'ipc'] } ) diff --git a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/ipc/index.ts b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/ipc/index.ts index bb7e1cb..6d07658 100644 --- a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/ipc/index.ts +++ b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/ipc/index.ts @@ -151,12 +151,15 @@ export default function initIpc() { } const subProcessEnv = { ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: 'geekAutoStartWithBossDaemon', PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable.executablePath } subProcessOfPuppeteer = childProcess.spawn( process.argv[0], - [...process.argv.slice(1), '--mode-to-daemon=geekAutoStartWithBossMain'], + [ + ...process.argv.slice(1), + `--mode=geekAutoStartWithBossDaemon`, + `--mode-to-daemon=geekAutoStartWithBossMain` + ], { env: subProcessEnv, stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'ipc'] @@ -205,13 +208,16 @@ export default function initIpc() { } const subProcessEnv = { ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: 'readNoReplyAutoReminder', PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable.executablePath } - subProcessOfPuppeteer = childProcess.spawn(process.argv[0], process.argv.slice(1), { - env: subProcessEnv, - stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'ipc'] - }) + subProcessOfPuppeteer = childProcess.spawn( + process.argv[0], + [...process.argv.slice(1), `--mode=readNoReplyAutoReminder`], + { + env: subProcessEnv, + stdio: ['inherit', 'inherit', 'inherit', 'pipe', 'ipc'] + } + ) // console.log(subProcessOfPuppeteer) return new Promise((resolve, reject) => { subProcessOfPuppeteer!.stdio[3]!.pipe(JSONStream.parse()).on('data', async (raw) => { @@ -264,15 +270,10 @@ export default function initIpc() { if (subProcessOfCheckAndDownloadDependencies) { return } - const subProcessEnv = { - ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: 'checkAndDownloadDependenciesForInit' - } subProcessOfCheckAndDownloadDependencies = childProcess.spawn( process.argv[0], - process.argv.slice(1), + [...process.argv.slice(1), `--mode="checkAndDownloadDependenciesForInit"`], { - env: subProcessEnv, stdio: [null, null, null, 'pipe', 'ipc'] } ) @@ -334,12 +335,11 @@ export default function initIpc() { } const subProcessEnv = { ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: 'launchBossZhipinLoginPageWithPreloadExtension', PUPPETEER_EXECUTABLE_PATH: (await getAnyAvailablePuppeteerExecutable())!.executablePath } subProcessOfBossZhipinLoginPageWithPreloadExtension = childProcess.spawn( process.argv[0], - process.argv.slice(1), + [...process.argv.slice(1), `--mode=launchBossZhipinLoginPageWithPreloadExtension`], { env: subProcessEnv, stdio: [null, null, null, 'pipe', 'ipc'] @@ -415,13 +415,16 @@ export default function initIpc() { const puppeteerExecutable = await getAnyAvailablePuppeteerExecutable() const subProcessEnv = { ...process.env, - MAIN_BOSSGEEKGO_UI_RUN_MODE: 'launchBossSite', PUPPETEER_EXECUTABLE_PATH: puppeteerExecutable!.executablePath } - subProcessOfOpenBossSite = childProcess.spawn(process.argv[0], process.argv.slice(1), { - env: subProcessEnv, - stdio: ['inherit', 'inherit', 'inherit', 'pipe'] - }) + subProcessOfOpenBossSite = childProcess.spawn( + process.argv[0], + [...process.argv.slice(1), `--mode=launchBossSite`], + { + env: subProcessEnv, + stdio: ['inherit', 'inherit', 'inherit', 'pipe'] + } + ) subProcessOfOpenBossSite.once('exit', () => { subProcessOfOpenBossSiteDefer = null }) diff --git a/packages/ui/src/main/index.ts b/packages/ui/src/main/index.ts index 4d1665d..f41dd58 100644 --- a/packages/ui/src/main/index.ts +++ b/packages/ui/src/main/index.ts @@ -1,4 +1,9 @@ -const runMode = process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE +import minimist from 'minimist' +const isUiDev = process.env.NODE_ENV === 'development' +const commandlineArgs = minimist(isUiDev ? process.argv.slice(2) : process.argv.slice(1)) +console.log(commandlineArgs) + +const runMode = commandlineArgs['mode']; ;(async () => { switch (runMode) {