From 753d4ac4033f457bb43bb107014b2e9c76090015 Mon Sep 17 00:00:00 2001 From: heronhaye Date: Wed, 14 Aug 2019 20:50:37 +0200 Subject: [PATCH] allow argv2 for deeplinks (#18932) * allow argv2 for deeplinks * also allow argv2 for deeplink on startup --- shared/desktop/app/node.desktop.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/shared/desktop/app/node.desktop.tsx b/shared/desktop/app/node.desktop.tsx index 8cb784e7ff12..3eea53138bdb 100644 --- a/shared/desktop/app/node.desktop.tsx +++ b/shared/desktop/app/node.desktop.tsx @@ -74,9 +74,13 @@ const focusSelfOnAnotherInstanceLaunching = (_, commandLine) => { // The new instance might be due to a URL schema handler launch. logger.info('Launched with URL', commandLine) if (commandLine.length > 1 && commandLine[1]) { - const link = commandLine[1] - if (link.startsWith('web+stellar:') || link.startsWith('keybase://')) { - sendToMainWindow('dispatchAction', {payload: {link}, type: DeeplinksGen.link}) + // Allow both argv1 and argv2 to be the link to support "/usr/lib/electron/electron path-to-app"-style + // invocations (used in the Arch community packages). + for (let link of commandLine.slice(1, 3)) { + if (isRelevantDeepLink(link)) { + sendToMainWindow('dispatchAction', {payload: {link}, type: DeeplinksGen.link}) + return + } } } } @@ -142,6 +146,10 @@ const handleCrashes = () => { } } +const isRelevantDeepLink = x => { + return x.startsWith('web+stellar:') || x.startsWith('keybase://') +} + const createMainWindow = () => { mainWindow = MainWindow() tellMainWindowAboutMenubar() @@ -161,9 +169,17 @@ const createMainWindow = () => { // stash a startupURL to be dispatched when we're ready for it. sendToMainWindow('dispatchAction', {payload: {link: startupURL}, type: DeeplinksGen.link}) startupURL = null - } else if (!isDarwin && process.argv.length > 1 && process.argv[1].startsWith('web+stellar:')) { + } else if (!isDarwin) { // Windows and Linux instead store a launch URL in argv. - sendToMainWindow('dispatchAction', {payload: {link: process.argv[1]}, type: DeeplinksGen.link}) + let link: string | null = null + if (process.argv.length > 1 && isRelevantDeepLink(process.argv[1])) { + link = process.argv[1] + } else if (process.argv.length > 2 && isRelevantDeepLink(process.argv[2])) { + link = process.argv[2] + } + if (link) { + sendToMainWindow('dispatchAction', {payload: {link: link}, type: DeeplinksGen.link}) + } } }) }