Add isMethodSupported handler
Summary: Allows plugin to check if something is supported by that app, for example an extension command or a new feature, before trying to use it. Reviewed By: passy Differential Revision: D14225957 fbshipit-source-id: 3c5a29a06b56fe5f1da772824232547447872344
This commit is contained in:
committed by
Facebook Github Bot
parent
dbb4fa1191
commit
40ada838d7
@@ -231,6 +231,22 @@ void FlipperClient::onMessageReceived(
|
||||
return;
|
||||
}
|
||||
|
||||
if (method == "isMethodSupported") {
|
||||
const auto identifier = params["api"].getString();
|
||||
if (connections_.find(identifier) == connections_.end()) {
|
||||
std::string errorMessage = "Connection " + identifier +
|
||||
" not found for method " + method.getString();
|
||||
log(errorMessage);
|
||||
responder->error(folly::dynamic::object("message", errorMessage)(
|
||||
"name", "ConnectionNotFound"));
|
||||
return;
|
||||
}
|
||||
const auto& conn = connections_.at(params["api"].getString());
|
||||
bool isSupported = conn->hasReceiver(params["method"].getString());
|
||||
responder->success(dynamic::object("isSupported", isSupported));
|
||||
return;
|
||||
}
|
||||
|
||||
dynamic response =
|
||||
dynamic::object("message", "Received unknown method: " + method);
|
||||
responder->error(response);
|
||||
|
||||
@@ -53,6 +53,13 @@ class FlipperConnectionImpl : public FlipperConnection {
|
||||
receivers_[method] = receiver;
|
||||
}
|
||||
|
||||
/**
|
||||
Runtime check which receivers are supported for this app
|
||||
*/
|
||||
bool hasReceiver(const std::string& method) {
|
||||
return receivers_.find(method) != receivers_.end();
|
||||
}
|
||||
|
||||
private:
|
||||
FlipperConnectionManager* socket_;
|
||||
std::string name_;
|
||||
|
||||
@@ -34,7 +34,7 @@ static constexpr int maxPayloadSize = 0xFFFFFF;
|
||||
// Not a public-facing version number.
|
||||
// Used for compatibility checking with desktop flipper.
|
||||
// To be bumped for every core platform interface change.
|
||||
static constexpr int sdkVersion = 1;
|
||||
static constexpr int sdkVersion = 2;
|
||||
|
||||
namespace facebook {
|
||||
namespace flipper {
|
||||
|
||||
Reference in New Issue
Block a user