Support handling deeplinks in plugins

Summary:
This adds support for handling incoming deeplinks in a Sandy plugin, which can be done by using a `client.onDeepLink(deepLink => { } )` listener

Also generalized deeplinks to not just support strings, but also richer objects, which is beneficial to plugin to plugin linking.

Reviewed By: jknoxville

Differential Revision: D22524749

fbshipit-source-id: 2cbe8d52f6eac91a1c1c8c8494706952920b9181
This commit is contained in:
Michel Weststrate
2020-07-22 04:11:32 -07:00
committed by Facebook GitHub Bot
parent 485b4c9827
commit f0c54667e0
13 changed files with 225 additions and 31 deletions

View File

@@ -23,10 +23,7 @@ const WelcomeScreen = isHeadless()
import NotificationScreen from '../chrome/NotificationScreen';
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
import {
getPluginKey,
defaultEnabledBackgroundPlugins,
} from '../utils/pluginUtils';
import {getPluginKey} from '../utils/pluginUtils';
import {deconstructClientId} from '../utils/clientUtils';
import {FlipperDevicePlugin, PluginDefinition, isSandyPlugin} from '../plugin';
import {RegisterPluginAction} from './plugins';
@@ -63,7 +60,7 @@ export type State = {
deviceId?: string;
errorMessage?: string;
}>;
deepLinkPayload: string | null;
deepLinkPayload: unknown;
staticView: StaticView;
};
@@ -89,7 +86,7 @@ export type Action =
payload: {
selectedPlugin: null | string;
selectedApp?: null | string;
deepLinkPayload: null | string;
deepLinkPayload: unknown;
selectedDevice?: null | BaseDevice;
time: number;
};
@@ -245,8 +242,8 @@ export default (state: State = INITAL_STATE, action: Actions): State => {
const {payload} = action;
const {selectedPlugin, selectedApp, deepLinkPayload} = payload;
let selectedDevice = payload.selectedDevice;
if (deepLinkPayload) {
const deepLinkParams = new URLSearchParams(deepLinkPayload || '');
if (typeof deepLinkPayload === 'string') {
const deepLinkParams = new URLSearchParams(deepLinkPayload);
const deviceParam = deepLinkParams.get('device');
const deviceMatch = state.devices.find((v) => v.title === deviceParam);
if (deviceMatch) {
@@ -460,7 +457,7 @@ export const selectPlugin = (payload: {
selectedPlugin: null | string;
selectedApp?: null | string;
selectedDevice?: BaseDevice | null;
deepLinkPayload: null | string;
deepLinkPayload: unknown;
time?: number;
}): Action => ({
type: 'SELECT_PLUGIN',