feat(deeplink): add handleDeeplink on app startup
This commit is contained in:
parent
95ddea5ff8
commit
e70f03130d
|
@ -14,6 +14,7 @@ import runDaemon from './daemon/zcashd-child-process';
|
|||
import zcashLog from './daemon/logger';
|
||||
import getZecPrice from '../services/zec-price';
|
||||
import store from './electron-store';
|
||||
import { handleDeeplink } from './handle-deeplink';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
@ -79,6 +80,35 @@ const createWindow = () => {
|
|||
exports.mainWindow = mainWindow;
|
||||
};
|
||||
|
||||
app.setAsDefaultProtocolClient('zcash');
|
||||
|
||||
const instanceLock = app.requestSingleInstanceLock();
|
||||
if (instanceLock) {
|
||||
app.on('second-instance', (event: Object, argv: string[]) => {
|
||||
handleDeeplink({
|
||||
app,
|
||||
mainWindow,
|
||||
argv,
|
||||
listenOpenUrl: false,
|
||||
});
|
||||
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
app.on('will-finish-launching', () => handleDeeplink({
|
||||
app,
|
||||
mainWindow,
|
||||
}));
|
||||
|
||||
/* eslint-disable-next-line consistent-return */
|
||||
app.on('ready', async () => {
|
||||
createWindow();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// @flow
|
||||
import { typeof app as ElectronApp, type electron$BrowserWindow } from 'electron'; // eslint-disable-line
|
||||
|
||||
const sendMessage = (mainWindow, url) => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.webContents.send('on-deep-link', url);
|
||||
} else {
|
||||
mainWindow.on('show', () => mainWindow.webContents.send('on-deep-link', url));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const handleDeeplink = ({
|
||||
app,
|
||||
mainWindow,
|
||||
argv = process.argv,
|
||||
listenOpenUrl = true,
|
||||
}: {
|
||||
app: ElectronApp,
|
||||
mainWindow: electron$BrowserWindow,
|
||||
argv?: string[],
|
||||
listenOpenUrl?: boolean,
|
||||
}) => {
|
||||
if (listenOpenUrl) {
|
||||
app.on('open-url', (event: Object, url: string) => {
|
||||
event.preventDefault();
|
||||
sendMessage(mainWindow, url);
|
||||
});
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
const argIndex = argv.findIndex(item => /zcash:(\/\/)?/.test(item));
|
||||
if (argIndex !== -1) sendMessage(mainWindow, argv[argIndex]);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue