99const { app, ipcMain } = require ( 'electron' ) ;
1010const { spawn } = require ( 'child_process' ) ;
1111const readline = require ( 'readline' ) ;
12+ const path = require ( 'path' ) ;
1213const { productName } = require ( './package.json' ) ;
1314
1415let processInstanceId = 0 ;
16+
17+ // Path to main.js - used to filter it out from CLI args in dev mode
18+ const mainScriptPath = path . resolve ( __dirname , 'main.js' ) ;
19+
20+ /**
21+ * Filter CLI args to remove internal Electron arguments.
22+ * In dev mode, process.argv includes: [electron, main.js, ...userArgs]
23+ * In production, it includes: [app, ...userArgs]
24+ * This function filters out the main.js entry point in dev mode.
25+ */
26+ function filterCliArgs ( args ) {
27+ if ( ! args || args . length === 0 ) {
28+ return args ;
29+ }
30+
31+ const normalizedMainScript = mainScriptPath . toLowerCase ( ) ;
32+
33+ return args . filter ( arg => {
34+ // Resolve to handle both absolute and relative paths
35+ const resolvedArg = path . resolve ( arg ) . toLowerCase ( ) ;
36+ return resolvedArg !== normalizedMainScript ;
37+ } ) ;
38+ }
1539// Map of instanceId -> { process, terminated }
1640const spawnedProcesses = new Map ( ) ;
1741
@@ -115,8 +139,9 @@ function registerAppIpcHandlers() {
115139 } ) ;
116140
117141 // CLI args (mirrors Tauri's cli.getMatches for --quit-when-done / -q)
142+ // Filter out internal Electron args (main.js in dev mode)
118143 ipcMain . handle ( 'get-cli-args' , ( ) => {
119- return process . argv ;
144+ return filterCliArgs ( process . argv ) ;
120145 } ) ;
121146
122147 // App path (repo root when running from source)
@@ -132,5 +157,6 @@ function registerAppIpcHandlers() {
132157
133158module . exports = {
134159 registerAppIpcHandlers,
135- terminateAllProcesses
160+ terminateAllProcesses,
161+ filterCliArgs
136162} ;
0 commit comments