From 1dad234dbc51d52a392729d21d52c602b841b8ff Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Thu, 12 Feb 2026 05:54:31 +0800 Subject: [PATCH 1/5] fix some feature cannot use on production build --- packages/ui/src/main/flow/OPEN_SETTING_WINDOW/ipc/index.ts | 4 +++- .../ui/src/main/flow/OPEN_SETTING_WINDOW/launch-daemon.ts | 5 +++-- packages/ui/src/main/window/browserDownloadProgressWindow.ts | 4 +++- packages/ui/src/main/window/cookieAssistantWindow.ts | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) 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 3eb9a96..bcafd3b 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 @@ -373,7 +373,9 @@ export default function initIpc() { } subProcessOfOpenBossSite = childProcess.spawn( process.argv[0], - [process.argv[1], `--mode=launchBossSite`], + process.env.NODE_ENV === 'development' + ? [process.argv[1], `--mode=launchBossSite`] + : [`--mode=launchBossSite`], { env: subProcessEnv, stdio: ['inherit', 'inherit', 'inherit', 'pipe'] diff --git a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/launch-daemon.ts b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/launch-daemon.ts index 0b6a543..ffd3714 100644 --- a/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/launch-daemon.ts +++ b/packages/ui/src/main/flow/OPEN_SETTING_WINDOW/launch-daemon.ts @@ -7,7 +7,6 @@ import { import { randomUUID } from 'node:crypto' import { connectToDaemon } from './connect-to-daemon' -const isUiDev = process.env.NODE_ENV === 'development' export async function ensureIpcPipeName({ isReset } = {}) { if (isReset) { await writeStorageFile('ipc-pipe-name', '', { isJson: false }) @@ -29,7 +28,9 @@ export async function launchDaemon() { // 添加参数使守护进程在后台运行,不显示 UI daemonProcess = spawn( process.argv[0], - isUiDev ? [process.argv[1], `--mode=launchDaemon`] : [`--mode=launchDaemon`], + process.env.NODE_ENV === 'development' + ? [process.argv[1], `--mode=launchDaemon`] + : [`--mode=launchDaemon`], { stdio: ['ignore', 'pipe', 'pipe', 'pipe'], detached: true, diff --git a/packages/ui/src/main/window/browserDownloadProgressWindow.ts b/packages/ui/src/main/window/browserDownloadProgressWindow.ts index e915568..00fed6a 100644 --- a/packages/ui/src/main/window/browserDownloadProgressWindow.ts +++ b/packages/ui/src/main/window/browserDownloadProgressWindow.ts @@ -62,7 +62,9 @@ export function createBrowserDownloadProgressWindow( } subProcessOfCheckAndDownloadDependencies = childProcess.spawn( process.argv[0], - [process.argv[1], `--mode=downloadDependenciesForInit`], + process.env.NODE_ENV === 'development' + ? [process.argv[1], `--mode=downloadDependenciesForInit`] + : [`--mode=downloadDependenciesForInit`], { stdio: [null, null, null, 'pipe', 'ipc'] } diff --git a/packages/ui/src/main/window/cookieAssistantWindow.ts b/packages/ui/src/main/window/cookieAssistantWindow.ts index 9631a48..6a27979 100644 --- a/packages/ui/src/main/window/cookieAssistantWindow.ts +++ b/packages/ui/src/main/window/cookieAssistantWindow.ts @@ -83,7 +83,9 @@ export function createCookieAssistantWindow( } subProcessOfBossZhipinLoginPageWithPreloadExtension = childProcess.spawn( process.argv[0], - [process.argv[1], `--mode=launchBossZhipinLoginPageWithPreloadExtension`], + process.env.NODE_ENV === 'development' + ? [process.argv[1], `--mode=launchBossZhipinLoginPageWithPreloadExtension`] + : [`--mode=launchBossZhipinLoginPageWithPreloadExtension`], { env: subProcessEnv, stdio: [null, null, null, 'pipe', 'ipc'] From b8f6042f36592367dbe0623a51d8b05326b9572b Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Thu, 12 Feb 2026 06:06:41 +0800 Subject: [PATCH 2/5] print log when launch with `process.env.NODE_ENV === 'development'` --- packages/ui/src/main/index.ts | 9 +++- packages/ui/src/main/utils/overrideConsole.ts | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 packages/ui/src/main/utils/overrideConsole.ts diff --git a/packages/ui/src/main/index.ts b/packages/ui/src/main/index.ts index dcf690f..d9592e6 100644 --- a/packages/ui/src/main/index.ts +++ b/packages/ui/src/main/index.ts @@ -1,8 +1,15 @@ +import overrideConsole from './utils/overrideConsole' import minimist from 'minimist' import { runCommon } from './features/run-common' import { launchDaemon } from './flow/OPEN_SETTING_WINDOW/launch-daemon' import { app } from 'electron' +const isUiDev = process.env.NODE_ENV === 'development' +const enableLogToFile = process.env.GEEKGEEKRUN_ENABLE_LOG_TO_FILE === String(1) +if (isUiDev || enableLogToFile) { + overrideConsole() +} + // 捕获未处理的 EPIPE 错误 process.on('uncaughtException', (err) => { if (err?.code === 'EPIPE' || err?.code === 'ERR_STREAM_DESTROYED') { @@ -11,7 +18,7 @@ process.on('uncaughtException', (err) => { throw err }) -const isUiDev = process.env.NODE_ENV === 'development' +console.log(process.argv) const commandlineArgs = minimist(isUiDev ? process.argv.slice(2) : process.argv.slice(1)) console.log(commandlineArgs) diff --git a/packages/ui/src/main/utils/overrideConsole.ts b/packages/ui/src/main/utils/overrideConsole.ts new file mode 100644 index 0000000..7e70c47 --- /dev/null +++ b/packages/ui/src/main/utils/overrideConsole.ts @@ -0,0 +1,42 @@ +import path from 'node:path' +import os from 'node:os' +import fs from 'node:fs' +import dayjs from 'dayjs' + +export default function overrideConsole() { + const originConsoleLog = console.log.bind(console) + const originConsoleWarn = console.warn.bind(console) + const originConsoleError = console.error.bind(console) + + const runtimeFolderPath = path.join(os.homedir(), '.geekgeekrun') + const logDirPath = path.join(runtimeFolderPath, 'log') + if (!fs.existsSync(logDirPath)) { + fs.mkdirSync(logDirPath, { recursive: true }) + } + + const logFileStream = fs.createWriteStream(path.join(logDirPath, `log.log`), { + flags: 'a' // 追加模式 + }) + const warnFileStream = fs.createWriteStream(path.join(logDirPath, `warn.log`), { + flags: 'a' // 追加模式 + }) + const errorFileStream = fs.createWriteStream(path.join(logDirPath, `error.log`), { + flags: 'a' // 追加模式 + }) + + console.log = (...args: any[]) => { + const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [log][PID=${process.pid}]` + originConsoleLog(lineHead, ...args) + logFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + } + console.warn = (...args: any[]) => { + const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [warn][PID=${process.pid}]` + originConsoleWarn(lineHead, ...args) + warnFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + } + console.error = (...args: any[]) => { + const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [warn][PID=${process.pid}]` + originConsoleError(lineHead, ...args) + errorFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + } +} From 01ce8c996d631752d7b97838b1701513320b08cb Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Thu, 12 Feb 2026 07:00:30 +0800 Subject: [PATCH 3/5] fix in production build `process.env.NODE_ENV` is still `development` --- packages/ui/electron.vite.config.ts | 85 ++++++++++++++++++----------- packages/ui/src/main/index.ts | 5 +- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/packages/ui/electron.vite.config.ts b/packages/ui/electron.vite.config.ts index eb529c4..2883f15 100644 --- a/packages/ui/electron.vite.config.ts +++ b/packages/ui/electron.vite.config.ts @@ -7,6 +7,56 @@ import transformerDirective from '@unocss/transformer-directives' import Replace from 'unplugin-replace/vite' process.env = { ...process.env, ...loadEnv(process.env.NODE_ENV!, process.cwd()) } +const mainPlugins = [ + externalizeDepsPlugin({ + exclude: [ + '@geekgeekrun/utils', + 'find-chrome-bin', + '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension' + ] + }), + Replace({ + delimiters: ['', ''], + sourcemap: true, + include: ['**/src/main/utils/gtag/Analytics.ts'], + values: [ + { + find: //g, + replacement: process.env.VITE_APP_GTAG_MEASUREMENT_ID as string + }, + { + find: //g, + replacement: process.env.VITE_APP_GTAG_API_SECRET as string + } + ] + }) +] +const preloadPlugins = [externalizeDepsPlugin()] +const rendererPlugins = [ + vue(), + UnoCSS({ + presets: [presetUno(), presetAttributify(), presetIcons()], + transformers: [transformerDirective()] + }) +] +if (process.env.NODE_ENV) { + ;[mainPlugins, preloadPlugins, rendererPlugins].forEach((pluginList) => { + pluginList.push( + Replace({ + delimiters: ['', ''], + sourcemap: true, + include: ['**'], + values: [ + { + find: /process.env.NODE_ENV/g, + replacement: `'${process.env.NODE_ENV}'` as string + } + ] + }) + ) + }) +} + export default defineConfig({ main: { build: { @@ -15,33 +65,10 @@ export default defineConfig({ }, minify: process.env.NODE_ENV === 'development' ? undefined : 'terser' }, - plugins: [ - externalizeDepsPlugin({ - exclude: [ - '@geekgeekrun/utils', - 'find-chrome-bin', - '@geekgeekrun/launch-bosszhipin-login-page-with-preload-extension' - ] - }), - Replace({ - delimiters: ['', ''], - sourcemap: true, - include: ['**/src/main/utils/gtag/Analytics.ts'], - values: [ - { - find: //g, - replacement: process.env.VITE_APP_GTAG_MEASUREMENT_ID as string - }, - { - find: //g, - replacement: process.env.VITE_APP_GTAG_API_SECRET as string - } - ] - }) - ] + plugins: mainPlugins }, preload: { - plugins: [externalizeDepsPlugin()], + plugins: preloadPlugins, build: { minify: process.env.NODE_ENV === 'development' ? undefined : 'terser' } @@ -52,13 +79,7 @@ export default defineConfig({ '@renderer': resolve('src/renderer/src') } }, - plugins: [ - vue(), - UnoCSS({ - presets: [presetUno(), presetAttributify(), presetIcons()], - transformers: [transformerDirective()] - }) - ], + plugins: rendererPlugins, build: { minify: process.env.NODE_ENV === 'development' ? undefined : 'terser' } diff --git a/packages/ui/src/main/index.ts b/packages/ui/src/main/index.ts index d9592e6..56c0e1c 100644 --- a/packages/ui/src/main/index.ts +++ b/packages/ui/src/main/index.ts @@ -9,6 +9,7 @@ const enableLogToFile = process.env.GEEKGEEKRUN_ENABLE_LOG_TO_FILE === String(1) if (isUiDev || enableLogToFile) { overrideConsole() } +console.log('NODE_ENV:', process.env.NODE_ENV) // 捕获未处理的 EPIPE 错误 process.on('uncaughtException', (err) => { @@ -18,9 +19,9 @@ process.on('uncaughtException', (err) => { throw err }) -console.log(process.argv) +console.log('argv:', process.argv) const commandlineArgs = minimist(isUiDev ? process.argv.slice(2) : process.argv.slice(1)) -console.log(commandlineArgs) +console.log('parsed commandline args:', commandlineArgs) const runMode = commandlineArgs['mode'] From 60928b618c09fca13eef54e26b76ef48d83ff7d1 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Thu, 12 Feb 2026 07:33:04 +0800 Subject: [PATCH 4/5] enhance log util about fail to JSON.stringify --- packages/ui/src/main/utils/overrideConsole.ts | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/main/utils/overrideConsole.ts b/packages/ui/src/main/utils/overrideConsole.ts index 7e70c47..2d4b97b 100644 --- a/packages/ui/src/main/utils/overrideConsole.ts +++ b/packages/ui/src/main/utils/overrideConsole.ts @@ -27,16 +27,49 @@ export default function overrideConsole() { console.log = (...args: any[]) => { const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [log][PID=${process.pid}]` originConsoleLog(lineHead, ...args) - logFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + logFileStream.write( + [ + lineHead, + args.map((arg) => { + try { + return JSON.stringify(arg) + } catch (err) { + return `[[${JSON.stringify(err?.toString())}]]` + } + }) + ].join(' ') + '\n' + ) } console.warn = (...args: any[]) => { const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [warn][PID=${process.pid}]` originConsoleWarn(lineHead, ...args) - warnFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + warnFileStream.write( + [ + lineHead, + args.map((arg) => { + try { + return JSON.stringify(arg) + } catch (err) { + return `[[${JSON.stringify(err?.toString())}]]` + } + }) + ].join(' ') + '\n' + ) } console.error = (...args: any[]) => { const lineHead = `${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} [warn][PID=${process.pid}]` originConsoleError(lineHead, ...args) - errorFileStream.write([lineHead, args.map((arg) => JSON.stringify(arg))].join(' ') + '\n') + errorFileStream.write( + [ + lineHead, + args.map((arg) => { + try { + return JSON.stringify(arg) + } catch (err) { + return `[[${JSON.stringify(err?.toString())}]]` + } + }) + ].join(' ') + '\n' + ) } } From 7aa2cc1485c895fe0c6e9fee7cd8e20c57dd6dc5 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Thu, 12 Feb 2026 07:33:15 +0800 Subject: [PATCH 5/5] enhance ui text --- .../src/page/MainLayout/GeekAutoStartChatWithBoss/index.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/renderer/src/page/MainLayout/GeekAutoStartChatWithBoss/index.vue b/packages/ui/src/renderer/src/page/MainLayout/GeekAutoStartChatWithBoss/index.vue index f43d83b..74ee323 100644 --- a/packages/ui/src/renderer/src/page/MainLayout/GeekAutoStartChatWithBoss/index.vue +++ b/packages/ui/src/renderer/src/page/MainLayout/GeekAutoStartChatWithBoss/index.vue @@ -323,7 +323,8 @@ >正则表达式,不区分大小写;输入框留空表示不筛选;优先级高于上方“期望投递公司”
小心验证你编写的正则,填写太过于宽泛的正则(例如`.*`)将导致任何职位都不会开聊