Skip to content

Commit 31517c3

Browse files
committed
Protocol handling
1 parent f0c7ebc commit 31517c3

File tree

3 files changed

+651
-5
lines changed

3 files changed

+651
-5
lines changed

app/main/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ const mainURL = 'file://' + path.join(__dirname, '../renderer', 'main.html');
3838

3939
const singleInstanceLock = app.requestSingleInstanceLock();
4040
if (singleInstanceLock) {
41-
app.on('second-instance', () => {
42-
if (mainWindow) {
41+
// @ts-ignore
42+
app.on('second-instance', (event, argv) => {
43+
// uri scheme handler for windows and linux
44+
if (process.platform !== 'darwin') {
45+
const NotifArgs = argv.slice(1);
46+
if (NotifArgs[1].startsWith("zulip://send")) {
47+
handleNotifCall(NotifArgs[1]);
48+
} else if (mainWindow) {
49+
if (mainWindow.isMinimized()) {
50+
mainWindow.restore();
51+
}
52+
mainWindow.show();
53+
}
54+
} else if (mainWindow) {
4355
if (mainWindow.isMinimized()) {
4456
mainWindow.restore();
4557
}
@@ -57,6 +69,14 @@ const iconPath = (): string => {
5769
return APP_ICON + (process.platform === 'win32' ? '.ico' : '.png');
5870
};
5971

72+
function handleNotifCall(NotifArgs: any): void {
73+
// if (mainWindow) {
74+
// mainWindow.webContents.focus();
75+
// mainWindow.webContents.send('deep-linking-url', deepLinkingUrl);
76+
// }
77+
console.log(decodeURIComponent(NotifArgs));
78+
}
79+
6080
function createMainWindow(): Electron.BrowserWindow {
6181
// Load the previous state with fallback to defaults
6282
const mainWindowState: windowStateKeeper.State = windowStateKeeper({
@@ -136,6 +156,10 @@ function createMainWindow(): Electron.BrowserWindow {
136156
// Decrease load on GPU (experimental)
137157
app.disableHardwareAcceleration();
138158

159+
if (process.platform === 'win32' && isDev) {
160+
console.log('Protocol handler set');
161+
app.setAsDefaultProtocolClient('zulip', process.execPath, [path.resolve(process.argv[1])]);
162+
}
139163
// Temporary fix for Electron render colors differently
140164
// More info here - https://github.com/electron/electron/issues/10732
141165
app.commandLine.appendSwitch('force-color-profile', 'srgb');

0 commit comments

Comments
 (0)