From 0445a05e5b198e9e8fa43a6707977368f44d2a91 Mon Sep 17 00:00:00 2001 From: John Knox Date: Wed, 27 Feb 2019 10:07:02 -0800 Subject: [PATCH] Add isMethodSupported to client Summary: Allows plugins to check if extension commands or new features are enabled in the current app, by calling `this.client.supportsMethod('xxx')`. Reviewed By: passy Differential Revision: D14225961 fbshipit-source-id: c9f7f5b3091209f0ce9705d9d3a0ec173edf3e25 --- src/Client.js | 9 +++++++++ src/plugin.js | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/Client.js b/src/Client.js index f5b935fdd..71081191d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -469,4 +469,13 @@ export default class Client extends EventEmitter { } return this.rawSend('execute', {api, method, params}); } + + supportsMethod(api: string, method: string): Promise { + if (this.sdkVersion < 2) { + return Promise.resolve(false); + } + return this.rawCall('isMethodSupported', {api, method}).then( + response => response.isSupported, + ); + } } diff --git a/src/plugin.js b/src/plugin.js index b19520264..5e9978da4 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -23,6 +23,7 @@ export type PluginClient = {| send: (method: string, params?: Object) => void, call: (method: string, params?: Object) => Promise, subscribe: (method: string, callback: (params: any) => void) => void, + supportsMethod: (method: string) => Promise, |}; type PluginTarget = BaseDevice | Client; @@ -168,6 +169,7 @@ export class FlipperPlugin extends FlipperBasePlugin< }); this.realClient.subscribe(id, method, callback); }, + supportsMethod: method => this.realClient.supportsMethod(id, method), }; }