Set up deeplink handling for open-plugin deeplink
Summary: Introduce open-plugin deeplink protocol. Implementation steps will follow in rest of this diff Reviewed By: jknoxville Differential Revision: D29761801 fbshipit-source-id: 47070c063df2cb3286e418b2fb20f9d8855a95d5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
860f723521
commit
226cf8ccf9
75
desktop/app/src/dispatcher/handleOpenPluginDeeplink.tsx
Normal file
75
desktop/app/src/dispatcher/handleOpenPluginDeeplink.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {selectPlugin} from '../reducers/connections';
|
||||
import {Store} from '../reducers/index';
|
||||
|
||||
type OpenPluginParams = {
|
||||
pluginId: string;
|
||||
client: string | undefined;
|
||||
devices: string[];
|
||||
payload: string | undefined;
|
||||
};
|
||||
|
||||
export function parseOpenPluginParams(query: string): OpenPluginParams {
|
||||
// 'flipper://open-plugin?plugin-id=graphql&client=facebook&devices=android,ios&chrome=1&payload='
|
||||
const url = new URL(query);
|
||||
const params = new Map<string, string>(url.searchParams as any);
|
||||
if (!params.has('plugin-id')) {
|
||||
throw new Error('Missing plugin-id param');
|
||||
}
|
||||
return {
|
||||
pluginId: params.get('plugin-id')!,
|
||||
client: params.get('client'),
|
||||
devices: params.get('devices')?.split(',') ?? [],
|
||||
payload: params.get('payload')
|
||||
? decodeURIComponent(params.get('payload')!)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export async function handleOpenPluginDeeplink(store: Store, query: string) {
|
||||
const params = parseOpenPluginParams(query);
|
||||
await verifyLighthouse();
|
||||
await verifyUserIsLoggedIn();
|
||||
await verifyFlipperIsUpToDate();
|
||||
await verifyPluginInstalled();
|
||||
await verifyClient();
|
||||
await verifyPluginInstalled();
|
||||
await openPlugin(store, params);
|
||||
}
|
||||
function verifyLighthouse() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
function verifyUserIsLoggedIn() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
function verifyFlipperIsUpToDate() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
function verifyPluginInstalled() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
function verifyClient() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
function openPlugin(store: Store, params: OpenPluginParams) {
|
||||
store.dispatch(
|
||||
selectPlugin({
|
||||
selectedApp: params.client,
|
||||
selectedPlugin: params.pluginId,
|
||||
deepLinkPayload: params.payload,
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user