@@ -4,10 +4,20 @@ const { spawn } = require("child_process");
44const path = require ( "path" ) ;
55const net = require ( "net" ) ;
66
7+ // Prevent multiple instances — second launch focuses the existing window instead
8+ if ( ! app . requestSingleInstanceLock ( ) ) {
9+ app . quit ( ) ;
10+ process . exit ( 0 ) ;
11+ }
12+
713const isPacked = app . isPackaged ;
8- const root = isPacked ? process . resourcesPath : path . join ( __dirname , ".." ) ;
914
10- // Deno binary: shipped via the `deno` npm package
15+ // __dirname resolves correctly in both dev and packaged (asar-off) mode:
16+ // dev: <project>/electron → root = <project>
17+ // packed: <app>/Resources/app/electron → root = <app>/Resources/app
18+ const root = path . join ( __dirname , ".." ) ;
19+
20+ // Deno binary is an extraResource — lives outside the app folder in both modes
1121const denoBin = isPacked
1222 ? path . join ( process . resourcesPath , "deno-bin" , process . platform === "win32" ? "deno.exe" : "deno" )
1323 : path . join ( root , "node_modules" , "deno" , process . platform === "win32" ? "deno.exe" : "deno" ) ;
@@ -95,12 +105,19 @@ function createWindow() {
95105 win . on ( "closed" , ( ) => { win = null ; } ) ;
96106}
97107
108+ app . on ( "second-instance" , ( ) => {
109+ // A second instance tried to launch — focus the existing window instead
110+ if ( win ) {
111+ if ( win . isMinimized ( ) ) win . restore ( ) ;
112+ win . focus ( ) ;
113+ }
114+ } ) ;
115+
98116app . whenReady ( ) . then ( async ( ) => {
99117 startDeno ( ) ;
100118 startNuxt ( ) ;
101119
102120 try {
103- // Wait for the Nuxt server to be ready before showing the window
104121 await waitForPort ( NUXT_PORT ) ;
105122 } catch ( err ) {
106123 console . error ( "Nuxt server did not start in time:" , err . message ) ;
0 commit comments