Merge pull request #680 from yuya-oc/fix-mac-deeplink

Fix deep linking not working when the app is not already opened
This commit is contained in:
Yuya Ochiai 2018-01-22 12:43:47 +09:00 committed by GitHub
commit f14df27409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -8,6 +8,8 @@ const {findDOMNode} = require('react-dom');
const {ipcRenderer, remote, shell} = require('electron'); const {ipcRenderer, remote, shell} = require('electron');
const url = require('url'); const url = require('url');
const contextMenu = require('../js/contextMenu'); const contextMenu = require('../js/contextMenu');
const {protocols} = require('../../../electron-builder.json');
const scheme = protocols[0].schemes[0];
const ErrorView = require('./ErrorView.jsx'); const ErrorView = require('./ErrorView.jsx');
@ -72,7 +74,7 @@ const MattermostView = createReactClass({
webview.addEventListener('new-window', (e) => { webview.addEventListener('new-window', (e) => {
var currentURL = url.parse(webview.getURL()); var currentURL = url.parse(webview.getURL());
var destURL = url.parse(e.url); var destURL = url.parse(e.url);
if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:') { if (destURL.protocol !== 'http:' && destURL.protocol !== 'https:' && destURL.protocol !== `${scheme}:`) {
ipcRenderer.send('confirm-protocol', destURL.protocol, e.url); ipcRenderer.send('confirm-protocol', destURL.protocol, e.url);
return; return;
} }

View file

@ -357,12 +357,23 @@ function setDeeplinkingUrl(url) {
} }
} }
// Protocol handler for osx app.on('will-finish-launching', () => {
app.on('open-url', (event, url) => { // Protocol handler for osx
event.preventDefault(); app.on('open-url', (event, url) => {
setDeeplinkingUrl(url); event.preventDefault();
mainWindow.webContents.send('protocol-deeplink', deeplinkingUrl); setDeeplinkingUrl(url);
mainWindow.show(); if (app.isReady()) {
function openDeepLink() {
try {
mainWindow.webContents.send('protocol-deeplink', deeplinkingUrl);
mainWindow.show();
} catch (err) {
setTimeout(openDeepLink, 1000);
}
}
openDeepLink();
}
});
}); });
// This method will be called when Electron has finished // This method will be called when Electron has finished