@@ -7,6 +7,14 @@ const { registerFsIpcHandlers, getAppDataDir } = require('./main-fs-ipc');
77const { registerCredIpcHandlers, cleanupWindowTrust } = require ( './main-cred-ipc' ) ;
88const { registerWindowIpcHandlers, registerWindow } = require ( './main-window-ipc' ) ;
99
10+ // Request single instance lock - only one instance of the app should run at a time
11+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
12+
13+ if ( ! gotTheLock ) {
14+ // Another instance is running, quit this one immediately
15+ app . quit ( ) ;
16+ }
17+
1018// In-memory key-value store shared across all windows (mirrors Tauri's put_item/get_all_items)
1119// Used for multi-window storage synchronization
1220const sharedStorageMap = new Map ( ) ;
@@ -99,6 +107,20 @@ app.on('quit-requested', (exitCode) => {
99107 gracefulShutdown ( exitCode ) ;
100108} ) ;
101109
110+ // Handle second instance attempts - forward args to existing windows
111+ app . on ( 'second-instance' , ( event , commandLine , workingDirectory ) => {
112+ // Forward to all windows via IPC
113+ // Window focusing is handled by the renderer's singleInstanceHandler
114+ BrowserWindow . getAllWindows ( ) . forEach ( win => {
115+ if ( ! win . isDestroyed ( ) ) {
116+ win . webContents . send ( 'single-instance' , {
117+ args : commandLine ,
118+ cwd : workingDirectory
119+ } ) ;
120+ }
121+ } ) ;
122+ } ) ;
123+
102124app . whenReady ( ) . then ( async ( ) => {
103125 // Remove default menu bar
104126 Menu . setApplicationMenu ( null ) ;
@@ -136,6 +158,10 @@ app.on('window-all-closed', () => {
136158 gracefulShutdown ( 0 ) ;
137159} ) ;
138160
161+ // macOS: When dock icon is clicked and no windows are open, create a new window.
162+ // Currently this won't fire because window-all-closed quits the app. If macOS support
163+ // is added and we want apps to stay running with no windows, change window-all-closed
164+ // to not quit on macOS (process.platform !== 'darwin').
139165app . on ( 'activate' , ( ) => {
140166 if ( BrowserWindow . getAllWindows ( ) . length === 0 ) {
141167 createWindow ( ) ;
0 commit comments