From 98bb392d7863a0a268a0dc2b6e50c2a848d4ef9e Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 9 Apr 2020 06:36:23 -0700 Subject: [PATCH] Allow device specification for plugin deep-link Summary: Allow optionally to provide the device title to select a plugin in. Currently, there's only support for `flipper:///`. This allows to add a `?device=`. Reviewed By: mweststrate Differential Revision: D20920587 fbshipit-source-id: e7df4b510f1adfa9c2c9d072f6aebca1edb89cc0 --- desktop/app/src/reducers/connections.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/desktop/app/src/reducers/connections.tsx b/desktop/app/src/reducers/connections.tsx index 6b1756225..87defb798 100644 --- a/desktop/app/src/reducers/connections.tsx +++ b/desktop/app/src/reducers/connections.tsx @@ -241,7 +241,22 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => { case 'SELECT_PLUGIN': { const {payload} = action; const {selectedPlugin, selectedApp, deepLinkPayload} = payload; - const selectedDevice = payload.selectedDevice || state.selectedDevice; + let selectedDevice = + selectedApp === null + ? null + : payload.selectedDevice || state.selectedDevice; + if (deepLinkPayload) { + const deepLinkParams = new URLSearchParams(deepLinkPayload || ''); + const deviceParam = deepLinkParams.get('device'); + const deviceMatch = state.devices.find((v) => v.title === deviceParam); + if (deviceMatch) { + selectedDevice = deviceMatch; + } else { + console.warn( + `Could not find matching device "${deviceParam}" requested through deep-link.`, + ); + } + } if (!selectDevice) { console.warn('Trying to select a plugin before a device was selected!'); }