Skip to content

Commit 46e6901

Browse files
authored
fix: deepLinkProtocol (#171)
1 parent f499539 commit 46e6901

File tree

1 file changed

+36
-20
lines changed
  • resources/js/electron-plugin/src

1 file changed

+36
-20
lines changed

resources/js/electron-plugin/src/index.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,6 @@ class NativePHP {
9090

9191
event.preventDefault();
9292
});
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-
}
10493
}
10594

10695
private async bootstrapApp(app: Electron.CrossProcessExports.App) {
@@ -175,16 +164,43 @@ class NativePHP {
175164
app.setAsDefaultProtocolClient(deepLinkProtocol);
176165
}
177166

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+
}
186203
}
187-
}
188204

189205
private startAutoUpdater(config) {
190206
if (config?.updater?.enabled === true) {

0 commit comments

Comments
 (0)