@@ -90,17 +90,6 @@ class NativePHP {
90
90
91
91
event . preventDefault ( ) ;
92
92
} ) ;
93
-
94
- // Handle deep linking for Windows
95
- if ( process . platform === 'win32' ) {
96
- app . on ( 'second-instance' , ( event , commandLine , workingDirectory ) => {
97
- if ( this . mainWindow ) {
98
- if ( this . mainWindow . isMinimized ( ) ) this . mainWindow . restore ( ) ;
99
- this . mainWindow . focus ( ) ;
100
- }
101
- this . handleDeepLink ( commandLine . pop ( ) ) ;
102
- } ) ;
103
- }
104
93
}
105
94
106
95
private async bootstrapApp ( app : Electron . CrossProcessExports . App ) {
@@ -175,16 +164,43 @@ class NativePHP {
175
164
app . setAsDefaultProtocolClient ( deepLinkProtocol ) ;
176
165
}
177
166
178
-
179
- if ( process . platform === 'win32' ) {
180
- const gotTheLock = app . requestSingleInstanceLock ( ) ;
181
- if ( ! gotTheLock ) {
182
- app . quit ( ) ;
183
- return ;
184
- }
185
- }
167
+ /**
168
+ * Handle protocol url for windows and linux
169
+ * This code will be different in Windows and Linux compared to MacOS.
170
+ * This is due to both platforms emitting the second-instance event rather
171
+ * than the open-url event and Windows requiring additional code in order to
172
+ * open the contents of the protocol link within the same Electron instance.
173
+ */
174
+ if ( process . platform !== "darwin" ) {
175
+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
176
+ if ( ! gotTheLock ) {
177
+ app . quit ( ) ;
178
+ return ;
179
+ } else {
180
+ app . on (
181
+ "second-instance" ,
182
+ ( event , commandLine , workingDirectory ) => {
183
+ // Someone tried to run a second instance, we should focus our window.
184
+ if ( this . mainWindow ) {
185
+ if ( this . mainWindow . isMinimized ( ) )
186
+ this . mainWindow . restore ( ) ;
187
+ this . mainWindow . focus ( ) ;
188
+ }
189
+
190
+ // the commandLine is array of strings in which last element is deep link url
191
+ notifyLaravel ( "events" , {
192
+ event : "\\Native\\Laravel\\Events\\App\\OpenedFromURL" ,
193
+ payload : {
194
+ url : commandLine [ commandLine . length - 1 ] ,
195
+ workingDirectory : workingDirectory ,
196
+ } ,
197
+ } ) ;
198
+ } ,
199
+ ) ;
200
+ }
201
+ }
202
+ }
186
203
}
187
- }
188
204
189
205
private startAutoUpdater ( config ) {
190
206
if ( config ?. updater ?. enabled === true ) {
0 commit comments