Add support for async / custom plugin export
Summary: Sandy plugins can now set up an `onExport` handler to enable customizing the export format of a plugin: `client.onExport(callback: (idler, onStatusMessage) => Promise<state>)` Import will be done in next diff Reviewed By: nikoant Differential Revision: D26124440 fbshipit-source-id: c787c79d929aa8fb484f15a9340d7c87545793cb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
32bde8cace
commit
34c915a739
@@ -37,6 +37,7 @@ import {
|
||||
import {BasePluginInstance} from '../plugin/PluginBase';
|
||||
import {FlipperLib} from '../plugin/FlipperLib';
|
||||
import {stubLogger} from '../utils/Logger';
|
||||
import {Idler} from '../utils/Idler';
|
||||
|
||||
type Renderer = RenderResult<typeof queries>;
|
||||
|
||||
@@ -95,9 +96,14 @@ interface BasePluginResult {
|
||||
triggerDeepLink(deeplink: unknown): void;
|
||||
|
||||
/**
|
||||
* Grab all the persistable state
|
||||
* Grab all the persistable state, but will ignore any onExport handler
|
||||
*/
|
||||
exportState(): any;
|
||||
exportState(): Record<string, any>;
|
||||
|
||||
/**
|
||||
* Grab all the persistable state, respecting onExport handlers
|
||||
*/
|
||||
exportStateAsync(): Promise<Record<string, any>>;
|
||||
|
||||
/**
|
||||
* Trigger menu entry by label
|
||||
@@ -367,7 +373,9 @@ function createBasePluginResult(
|
||||
flipperLib: pluginInstance.flipperLib,
|
||||
activate: () => pluginInstance.activate(),
|
||||
deactivate: () => pluginInstance.deactivate(),
|
||||
exportState: () => pluginInstance.exportState(),
|
||||
exportStateAsync: () =>
|
||||
pluginInstance.exportState(createStubIdler(), () => {}),
|
||||
exportState: () => pluginInstance.exportStateSync(),
|
||||
triggerDeepLink: (deepLink: unknown) => {
|
||||
pluginInstance.triggerDeepLink(deepLink);
|
||||
},
|
||||
@@ -422,3 +430,18 @@ function createMockDevice(options?: StartPluginOptions): RealFlipperDevice {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createStubIdler(): Idler {
|
||||
return {
|
||||
shouldIdle() {
|
||||
return false;
|
||||
},
|
||||
idle() {
|
||||
return Promise.resolve();
|
||||
},
|
||||
cancel() {},
|
||||
isCancelled() {
|
||||
return false;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user