Introduce isPluginAvailable and selectPlugin
Summary: Introduced API to replace the deprecated `selectPlugin` in Sandy. The API can be used to navigate from `device plugin -> device plugin`, or` client plugin -> device / client plugin` Introduced `isPluginAvailable` as well, so that the user interaction an be fine tuned in case the plugin is not disabled. Reviewed By: jknoxville Differential Revision: D25422370 fbshipit-source-id: c6c603f1c68e6291280b3d0883e474448754ded1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
02a56da3f5
commit
52862f6083
@@ -46,7 +46,17 @@ export type DevicePluginPredicate = (device: Device) => boolean;
|
||||
|
||||
export type DevicePluginFactory = (client: DevicePluginClient) => object;
|
||||
|
||||
export interface DevicePluginClient extends BasePluginClient {}
|
||||
export interface DevicePluginClient extends BasePluginClient {
|
||||
/**
|
||||
* Checks if the provided plugin is available for the current device
|
||||
*/
|
||||
isPluginAvailable(pluginId: string): boolean;
|
||||
|
||||
/**
|
||||
* opens a different plugin by id, optionally providing a deeplink to bring the plugin to a certain state
|
||||
*/
|
||||
selectPlugin(pluginId: string, deeplinkPayload?: unknown): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper interface around BaseDevice in Flipper
|
||||
@@ -59,6 +69,7 @@ export interface RealFlipperDevice {
|
||||
addLogListener(callback: DeviceLogListener): Symbol;
|
||||
removeLogListener(id: Symbol): void;
|
||||
addLogEntry(entry: DeviceLogEntry): void;
|
||||
devicePlugins: string[];
|
||||
}
|
||||
|
||||
export class SandyDevicePluginInstance extends BasePluginInstance {
|
||||
@@ -76,7 +87,17 @@ export class SandyDevicePluginInstance extends BasePluginInstance {
|
||||
initialStates?: Record<string, any>,
|
||||
) {
|
||||
super(flipperLib, definition, realDevice, initialStates);
|
||||
this.client = this.createBasePluginClient();
|
||||
this.client = {
|
||||
...this.createBasePluginClient(),
|
||||
isPluginAvailable(pluginId: string) {
|
||||
return flipperLib.isPluginAvailable(realDevice, null, pluginId);
|
||||
},
|
||||
selectPlugin(pluginId: string, deeplink?: unknown) {
|
||||
if (this.isPluginAvailable(pluginId)) {
|
||||
flipperLib.selectPlugin(realDevice, null, pluginId, deeplink);
|
||||
}
|
||||
},
|
||||
};
|
||||
this.initializePlugin(() =>
|
||||
definition.asDevicePluginModule().devicePlugin(this.client),
|
||||
);
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
*/
|
||||
|
||||
import {Logger} from '../utils/Logger';
|
||||
import {RealFlipperDevice} from './DevicePlugin';
|
||||
import {NormalizedMenuEntry} from './MenuEntry';
|
||||
import {RealFlipperClient} from './Plugin';
|
||||
|
||||
/**
|
||||
* This interface exposes all global methods for which an implementation will be provided by Flipper itself
|
||||
@@ -18,4 +20,15 @@ export interface FlipperLib {
|
||||
enableMenuEntries(menuEntries: NormalizedMenuEntry[]): void;
|
||||
createPaste(input: string): Promise<string | undefined>;
|
||||
GK(gatekeeper: string): boolean;
|
||||
isPluginAvailable(
|
||||
device: RealFlipperDevice,
|
||||
client: RealFlipperClient | null,
|
||||
pluginId: string,
|
||||
): boolean;
|
||||
selectPlugin(
|
||||
device: RealFlipperDevice,
|
||||
client: RealFlipperClient | null,
|
||||
pluginId: string,
|
||||
deeplink: unknown,
|
||||
): void;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,16 @@ export interface PluginClient<
|
||||
* Checks if a method is available on the client implementation
|
||||
*/
|
||||
supportsMethod(method: keyof Methods): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Checks if the provided plugin is available for the current device / application
|
||||
*/
|
||||
isPluginAvailable(pluginId: string): boolean;
|
||||
|
||||
/**
|
||||
* opens a different plugin by id, optionally providing a deeplink to bring the plugin to a certain state
|
||||
*/
|
||||
selectPlugin(pluginId: string, deeplinkPayload?: unknown): void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,6 +108,7 @@ export interface RealFlipperClient {
|
||||
device_id: string;
|
||||
};
|
||||
deviceSync: RealFlipperDevice;
|
||||
plugins: string[];
|
||||
isBackgroundPlugin(pluginId: string): boolean;
|
||||
initPlugin(pluginId: string): void;
|
||||
deinitPlugin(pluginId: string): void;
|
||||
@@ -174,6 +185,23 @@ export class SandyPluginInstance extends BasePluginInstance {
|
||||
method as any,
|
||||
);
|
||||
},
|
||||
isPluginAvailable(pluginId: string) {
|
||||
return flipperLib.isPluginAvailable(
|
||||
realClient.deviceSync,
|
||||
realClient,
|
||||
pluginId,
|
||||
);
|
||||
},
|
||||
selectPlugin(pluginId: string, deeplink?: unknown) {
|
||||
if (this.isPluginAvailable(pluginId)) {
|
||||
flipperLib.selectPlugin(
|
||||
realClient.deviceSync,
|
||||
realClient,
|
||||
pluginId,
|
||||
deeplink,
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
this.initializePlugin(() =>
|
||||
definition.asPluginModule().plugin(this.client),
|
||||
|
||||
Reference in New Issue
Block a user