Expose current connection status to Sandy plugins

Summary:
Introduced `isConnected` flag on device and plugin client to reflect whether a connection is still available for the plugins, or that they have been disconnected.

Potentially we could expose the (readonly) `connected` state atom for this as well, or an `onDisconnect` event for device pugins, to create a responsive UI, but there might be no need for that, in which case this suffices.

Reviewed By: nikoant

Differential Revision: D26249346

fbshipit-source-id: b8486713fdf2fcd520488ce54f771bd038fd13f8
This commit is contained in:
Michel Weststrate
2021-02-09 04:12:09 -08:00
committed by Facebook GitHub Bot
parent 7e1bf0f58b
commit bb529411b5
6 changed files with 62 additions and 16 deletions

View File

@@ -90,23 +90,23 @@ export function getCurrentPluginInstance(): typeof currentPluginInstance {
export abstract class BasePluginInstance {
/** generally available Flipper APIs */
flipperLib: FlipperLib;
readonly flipperLib: FlipperLib;
/** the original plugin definition */
definition: SandyPluginDefinition;
/** the plugin instance api as used inside components and such */
instanceApi: any;
/** the device owning this plugin */
device: Device;
readonly device: Device;
activated = false;
destroyed = false;
events = new EventEmitter();
readonly events = new EventEmitter();
// temporarily field that is used during deserialization
initialStates?: Record<string, any>;
// all the atoms that should be serialized when making an export / import
rootStates: Record<string, Atom<any>> = {};
readonly rootStates: Record<string, Atom<any>> = {};
// last seen deeplink
lastDeeplink?: any;
// export handler
@@ -135,6 +135,10 @@ export abstract class BasePluginInstance {
get isArchived() {
return realDevice.isArchived;
},
get isConnected() {
// for now same as isArchived, in the future we might distinguish between archived/imported and disconnected/offline devices
return !realDevice.isArchived;
},
deviceType: realDevice.deviceType,
onLogEntry(cb) {