Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2d165d9

Browse files
committed
Check if command messages failed
1 parent bd67db1 commit 2d165d9

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

shell/platform/linux/fl_binary_messenger.cc

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "flutter/shell/platform/linux/fl_engine_private.h"
99
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
1010
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
11+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
1112
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
1213
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
1314

@@ -318,6 +319,28 @@ static GBytes* send_on_channel_finish(FlBinaryMessenger* messenger,
318319
return fl_engine_send_platform_message_finish(engine, r, error);
319320
}
320321

322+
// Completes method call and returns TRUE if the call was successful.
323+
static gboolean finish_method(GObject* object,
324+
GAsyncResult* result,
325+
GError** error) {
326+
g_autoptr(FlMethodResponse) response = fl_method_channel_invoke_method_finish(
327+
FL_METHOD_CHANNEL(object), result, error);
328+
if (response == nullptr) {
329+
return FALSE;
330+
}
331+
return fl_method_response_get_result(response, error) != nullptr;
332+
}
333+
334+
// Called when a response is received for the resize channel message.
335+
static void resize_channel_response_cb(GObject* object,
336+
GAsyncResult* result,
337+
gpointer user_data) {
338+
g_autoptr(GError) error = nullptr;
339+
if (!finish_method(object, result, &error)) {
340+
g_warning("Failed to resize channel: %s", error->message);
341+
}
342+
}
343+
321344
static void resize_channel(FlBinaryMessenger* messenger,
322345
const gchar* channel,
323346
int64_t new_size) {
@@ -328,7 +351,18 @@ static void resize_channel(FlBinaryMessenger* messenger,
328351
g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
329352
FL_METHOD_CODEC(codec), kResizeMethod, args, nullptr);
330353
fl_binary_messenger_send_on_channel(messenger, kControlChannelName, message,
331-
nullptr, nullptr, nullptr);
354+
nullptr, resize_channel_response_cb,
355+
nullptr);
356+
}
357+
358+
// Called when a response is received for the allow channel overflow message.
359+
static void set_allow_channel_overflowl_response_cb(GObject* object,
360+
GAsyncResult* result,
361+
gpointer user_data) {
362+
g_autoptr(GError) error = nullptr;
363+
if (!finish_method(object, result, &error)) {
364+
g_warning("Failed to set allow channel overflow: %s", error->message);
365+
}
332366
}
333367

334368
static void set_allow_channel_overflow(FlBinaryMessenger* messenger,
@@ -340,8 +374,9 @@ static void set_allow_channel_overflow(FlBinaryMessenger* messenger,
340374
fl_value_append_take(args, fl_value_new_bool(allowed));
341375
g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
342376
FL_METHOD_CODEC(codec), kOverflowMethod, args, nullptr);
343-
fl_binary_messenger_send_on_channel(messenger, kControlChannelName, message,
344-
nullptr, nullptr, nullptr);
377+
fl_binary_messenger_send_on_channel(
378+
messenger, kControlChannelName, message, nullptr,
379+
set_allow_channel_overflowl_response_cb, nullptr);
345380
}
346381

347382
static void fl_binary_messenger_impl_class_init(

0 commit comments

Comments
 (0)