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

@@ -38,6 +38,7 @@ import {BasePluginInstance} from '../plugin/PluginBase';
import {FlipperLib} from '../plugin/FlipperLib';
import {stubLogger} from '../utils/Logger';
import {Idler} from '../utils/Idler';
import {createState} from '../state/atom';
type Renderer = RenderResult<typeof queries>;
@@ -207,10 +208,13 @@ export function startPlugin<Module extends FlipperPluginModule<any>>(
isBackgroundPlugin(_pluginId: string) {
return !!options?.isBackgroundPlugin;
},
connected: createState(false),
initPlugin() {
this.connected.set(true);
pluginInstance.connect();
},
deinitPlugin() {
this.connected.set(false);
pluginInstance.disconnect();
},
call(