fix(deeplink) - fix deeplink on osx startup

This commit is contained in:
georgelima 2019-02-18 20:22:07 -05:00
parent eff884f0b4
commit cbc92d0cff
3 changed files with 13 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import React, { type ComponentType, Component } from 'react';
import { ipcRenderer, remote } from 'electron';
import { type RouterHistory, type Location } from 'react-router-dom';
import { searchUriInArgv } from '../../config/handle-deeplink';
import electronStore from "../../config/electron-store"
type PassedProps = {
history: RouterHistory,
@ -11,11 +12,13 @@ type PassedProps = {
isRunning: boolean,
};
const OSX_DEEPLINK_URL_KEY = "OSX_DEEPLINK_URL"
export const withDeepLink = (
WrappedComponent: ComponentType<PassedProps>,
): ComponentType<$Diff<PassedProps, {}>> => class extends Component<PassedProps> {
componentDidMount() {
const arg = searchUriInArgv(remote.process.argv);
const arg = searchUriInArgv([...remote.process.argv, electronStore.get(OSX_DEEPLINK_URL_KEY) || ""]);
if (arg) this.redirect(arg);
@ -35,6 +38,11 @@ export const withDeepLink = (
redirect(message: string) {
const { history } = this.props;
// clean osx deeplink storage
if (electronStore.has(OSX_DEEPLINK_URL_KEY)) {
electronStore.delete(OSX_DEEPLINK_URL_KEY)
}
history.replace(`/send/${message.replace(/zcash:(\/\/)?/, '')}`);
}

View File

@ -104,10 +104,7 @@ if (instanceLock) {
app.quit();
}
app.on('will-finish-launching', () => handleDeeplink({
app,
mainWindow,
}));
handleDeeplink({ app, mainWindow })
/* eslint-disable-next-line consistent-return */
app.on('ready', async () => {

View File

@ -1,5 +1,6 @@
// @flow
import { typeof app as ElectronApp, type electron$BrowserWindow } from 'electron'; // eslint-disable-line
import { typeof app as ElectronApp, type electron$BrowserWindow, remote } from 'electron'; // eslint-disable-line
import store from "./electron-store"
const sendMessage = (mainWindow, url) => {
if (mainWindow) {
@ -30,6 +31,7 @@ export const handleDeeplink = ({
if (listenOpenUrl) {
app.on('open-url', (event: Object, url: string) => {
event.preventDefault();
store.set("OSX_DEEPLINK_URL", url)
sendMessage(mainWindow, url);
});
}