From d00cb9e09e3d45395a1cafa45d25681620ebc091 Mon Sep 17 00:00:00 2001 From: Francisco Magdaleno Date: Wed, 4 Sep 2019 16:17:10 -0700 Subject: [PATCH] Finish plumbing message responses on method channels (flutter/engine#11877) --- .../client_wrapper/include/flutter/method_channel.h | 13 ++++++++++--- .../common/cpp/client_wrapper/plugin_registrar.cc | 4 ++-- .../common/framework/Headers/FlutterChannels.h | 6 +----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h index e1f164076a..4baa083cca 100644 --- a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h +++ b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h @@ -48,11 +48,18 @@ class MethodChannel { MethodCall method_call(method, std::move(arguments)); std::unique_ptr> message = codec_->EncodeMethodCall(method_call); - messenger_->Send(name_, message->data(), message->size()); + messenger_->Send(name_, message->data(), message->size(), nullptr); } - // TODO: Add support for a version of InvokeMethod expecting a reply once - // https://github.com/flutter/flutter/issues/18852 is fixed. + // Sends a message to the Flutter engine on this channel expecting a reply. + void InvokeMethod(const std::string& method, + std::unique_ptr arguments, + flutter::BinaryReply reply) { + MethodCall method_call(method, std::move(arguments)); + std::unique_ptr> message = + codec_->EncodeMethodCall(method_call); + messenger_->Send(name_, message->data(), message->size(), reply); + } // Registers a handler that should be called any time a method call is // received on this channel. diff --git a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index cf28181ed4..7ca7c3de73 100644 --- a/engine/src/flutter/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/engine/src/flutter/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -98,8 +98,8 @@ void BinaryMessengerImpl::Send(const std::string& channel, const size_t message_size, BinaryReply reply) const { if (reply == nullptr) { - std::cerr << "Calling BinaryMessengerImpl::Send expecting a reply, but the " - "callback is null.\n"; + FlutterDesktopMessengerSend(messenger_, channel.c_str(), message, + message_size); return; } struct Captures { diff --git a/engine/src/flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h b/engine/src/flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h index 83c9e98976..b0a81e9e7d 100644 --- a/engine/src/flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h +++ b/engine/src/flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h @@ -234,11 +234,7 @@ FLUTTER_EXPORT */ - (void)invokeMethod:(NSString*)method arguments:(id _Nullable)arguments - result:(FlutterResult _Nullable)callback - // TODO: Add macOS support for replies once - // https://github.com/flutter/flutter/issues/18852 is fixed. - API_UNAVAILABLE(macos); - + result:(FlutterResult _Nullable)callback; /** * Registers a handler for method calls from the Flutter side. *