Expose more meta information for plugins

Summary: expose `appName`, `appId` and `device` to Sandy plugins. Will be used in next diff to migrate navigation plugin

Reviewed By: cekkaewnumchai

Differential Revision: D24857253

fbshipit-source-id: 03ac3d376d5d1950bcf3d78386a65ce167b517e3
This commit is contained in:
Michel Weststrate
2020-11-11 07:57:14 -08:00
committed by Facebook GitHub Bot
parent 9b4e7e873c
commit 1157976eef
7 changed files with 87 additions and 23 deletions

View File

@@ -46,15 +46,14 @@ export type DevicePluginPredicate = (device: Device) => boolean;
export type DevicePluginFactory = (client: DevicePluginClient) => object;
export interface DevicePluginClient extends BasePluginClient {
readonly device: Device;
}
export interface DevicePluginClient extends BasePluginClient {}
/**
* Wrapper interface around BaseDevice in Flipper
*/
export interface RealFlipperDevice {
os: string;
serial: string;
isArchived: boolean;
deviceType: DeviceType;
addLogListener(callback: DeviceLogListener): Symbol;
@@ -76,25 +75,8 @@ export class SandyDevicePluginInstance extends BasePluginInstance {
realDevice: RealFlipperDevice,
initialStates?: Record<string, any>,
) {
super(flipperLib, definition, initialStates);
const device: Device = {
realDevice, // TODO: temporarily, clean up T70688226
// N.B. we model OS as string, not as enum, to make custom device types possible in the future
os: realDevice.os,
isArchived: realDevice.isArchived,
deviceType: realDevice.deviceType,
onLogEntry(cb) {
const handle = realDevice.addLogListener(cb);
return () => {
realDevice.removeLogListener(handle);
};
},
};
this.client = {
...this.createBasePluginClient(),
device,
};
super(flipperLib, definition, realDevice, initialStates);
this.client = this.createBasePluginClient();
this.initializePlugin(() =>
definition.asDevicePluginModule().devicePlugin(this.client),
);