1
- import { clipboard } from "electron/common" ;
1
+ import { clipboard , shell } from "electron/common" ;
2
2
import {
3
3
BrowserWindow ,
4
4
type IpcMainEvent ,
@@ -157,6 +157,8 @@ function createMainWindow(): BrowserWindow {
157
157
}
158
158
159
159
await app . whenReady ( ) ;
160
+ // Register custom protocol handler
161
+ app . setAsDefaultProtocolClient ( "zulip" ) ;
160
162
161
163
if ( process . env . GDK_BACKEND !== GDK_BACKEND ) {
162
164
console . warn (
@@ -174,14 +176,19 @@ function createMainWindow(): BrowserWindow {
174
176
175
177
remoteMain . initialize ( ) ;
176
178
177
- app . on ( "second-instance" , ( ) => {
179
+ app . on ( "second-instance" , ( event , commandLine ) => {
178
180
if ( mainWindow ) {
179
181
if ( mainWindow . isMinimized ( ) ) {
180
182
mainWindow . restore ( ) ;
181
183
}
182
184
183
185
mainWindow . show ( ) ;
184
186
}
187
+ // Handle deep link when opened from protocol
188
+ const url = commandLine . find ( ( argument ) => argument . startsWith ( "zulip://" ) ) ;
189
+ if ( url ) {
190
+ mainWindow . webContents . send ( "open-url" , url ) ;
191
+ }
185
192
} ) ;
186
193
187
194
ipcMain . on (
@@ -196,6 +203,24 @@ function createMainWindow(): BrowserWindow {
196
203
app . on ( "activate" , ( ) => {
197
204
mainWindow . show ( ) ;
198
205
} ) ;
206
+ // Handle deep linking when app is already running (macOS)
207
+ app . on ( "open-url" , async ( event , url ) => {
208
+ event . preventDefault ( ) ;
209
+
210
+ const response = await dialog . showMessageBox ( {
211
+ type : "question" ,
212
+ buttons : [ "Open in App" , "Open in Browser" ] ,
213
+ defaultId : 0 ,
214
+ message : `Do you want to open this link in the desktop app or browser?` ,
215
+ detail : url ,
216
+ } ) ;
217
+
218
+ if ( response . response === 0 ) {
219
+ mainWindow . webContents . send ( "open-url" , url ) ;
220
+ } else {
221
+ await shell . openExternal ( url ) ; // Open in browser
222
+ }
223
+ } ) ;
199
224
200
225
app . on ( "web-contents-created" , ( _event , contents : WebContents ) => {
201
226
contents . setWindowOpenHandler ( ( details ) => {
0 commit comments