aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-12-07 21:58:21 +0100
committerLibravatar GitHub <noreply@github.com>2017-12-07 21:58:21 +0100
commitc45534c5622e0e48466cf9ada5362b30b04033ab (patch)
tree0fa45c777c062ade505b5f229d137b9dcb6cbd43 /src
parentfix(Service): Fix issues when installing recipe (diff)
parentConvert url to string (diff)
downloadferdium-app-c45534c5622e0e48466cf9ada5362b30b04033ab.tar.gz
ferdium-app-c45534c5622e0e48466cf9ada5362b30b04033ab.tar.zst
ferdium-app-c45534c5622e0e48466cf9ada5362b30b04033ab.zip
feat(App): Register franz:// as an URL handler to control the app from external resources
[PR] Add deep linking functionality
Diffstat (limited to 'src')
-rw-r--r--src/electron/deepLinking.js5
-rw-r--r--src/index.js30
-rw-r--r--src/stores/AppStore.js8
3 files changed, 41 insertions, 2 deletions
diff --git a/src/electron/deepLinking.js b/src/electron/deepLinking.js
new file mode 100644
index 000000000..16e68b914
--- /dev/null
+++ b/src/electron/deepLinking.js
@@ -0,0 +1,5 @@
1export default function handleDeepLink(window, rawUrl) {
2 const url = rawUrl.replace('franz://', '');
3
4 window.webContents.send('navigateFromDeepLink', { url });
5}
diff --git a/src/index.js b/src/index.js
index 6a08e5e5a..4253b681f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -8,6 +8,7 @@ import { isDevMode, isWindows } from './environment';
8import ipcApi from './electron/ipc-api'; 8import ipcApi from './electron/ipc-api';
9import Tray from './lib/Tray'; 9import Tray from './lib/Tray';
10import Settings from './electron/Settings'; 10import Settings from './electron/Settings';
11import handleDeepLink from './electron/deepLinking';
11import { appId } from './package.json'; // eslint-disable-line import/no-unresolved 12import { appId } from './package.json'; // eslint-disable-line import/no-unresolved
12import './electron/exception'; 13import './electron/exception';
13 14
@@ -26,10 +27,20 @@ if (isWindows) {
26} 27}
27 28
28// Force single window 29// Force single window
29const isSecondInstance = app.makeSingleInstance(() => { 30const isSecondInstance = app.makeSingleInstance((argv) => {
30 if (mainWindow) { 31 if (mainWindow) {
31 if (mainWindow.isMinimized()) mainWindow.restore(); 32 if (mainWindow.isMinimized()) mainWindow.restore();
32 mainWindow.focus(); 33 mainWindow.focus();
34
35 if (process.platform === 'win32') {
36 // Keep only command line / deep linked arguments
37 const url = argv.slice(1);
38
39 if (url) {
40 console.log(url.toString());
41 handleDeepLink(mainWindow, url.toString());
42 }
43 }
33 } 44 }
34}); 45});
35 46
@@ -70,7 +81,8 @@ const createWindow = () => {
70 const trayIcon = new Tray(); 81 const trayIcon = new Tray();
71 82
72 // Initialize ipcApi 83 // Initialize ipcApi
73 ipcApi({ mainWindow, settings, trayIcon }); 84 const franzIpcApi = ipcApi({ mainWindow, settings, trayIcon });
85 console.log(franzIpcApi);
74 86
75 // Manage Window State 87 // Manage Window State
76 mainWindowState.manage(mainWindow); 88 mainWindowState.manage(mainWindow);
@@ -137,6 +149,8 @@ const createWindow = () => {
137 149
138 mainWindow.on('show', () => { 150 mainWindow.on('show', () => {
139 mainWindow.setSkipTaskbar(false); 151 mainWindow.setSkipTaskbar(false);
152
153 handleDeepLink(mainWindow, 'franz://settings/services/add/msteams');
140 }); 154 });
141 155
142 app.mainWindow = mainWindow; 156 app.mainWindow = mainWindow;
@@ -176,3 +190,15 @@ app.on('activate', () => {
176 mainWindow.show(); 190 mainWindow.show();
177 } 191 }
178}); 192});
193
194app.on('will-finish-launching', () => {
195 // Protocol handler for osx
196 app.on('open-url', (event, url) => {
197 event.preventDefault();
198 console.log(`open-url event: ${url}`);
199 handleDeepLink(mainWindow, url);
200 });
201});
202
203// Register App URL
204app.setAsDefaultProtocolClient('franz');
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index 17ec832cf..3e6d4d288 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -116,6 +116,14 @@ export default class AppStore extends Store {
116 } 116 }
117 }); 117 });
118 118
119 // Handle deep linking (franz://)
120 ipcRenderer.on('navigateFromDeepLink', (event, data) => {
121 const { url } = data;
122 if (!url) return;
123
124 this.stores.router.push(data.url);
125 });
126
119 // Check system idle time every minute 127 // Check system idle time every minute
120 setInterval(() => { 128 setInterval(() => {
121 this.idleTime = idleTimer.getIdleTime(); 129 this.idleTime = idleTimer.getIdleTime();