| Flutter Linux Embedder |

Classes | Functions | Variables
fl_platform_handler.cc File Reference
`#include "flutter/shell/platform/linux/fl_platform_handler.h"`
`#include <gtk/gtk.h>`
`#include <cstring>`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"`

Go to the source code of this file.

## Classes
struct | _FlPlatformHandler

## Functions
static void | send_response (FlMethodCall *method_call, FlMethodResponse *response)
static void | clipboard_text_cb (GtkClipboard *clipboard, const gchar *text, gpointer user_data)
static void | clipboard_text_has_strings_cb (GtkClipboard *clipboard, const gchar *text, gpointer user_data)
static FlMethodResponse * | clipboard_set_data (FlPlatformHandler *self, FlValue *args)
static FlMethodResponse * | clipboard_get_data_async (FlPlatformHandler *self, FlMethodCall *method_call)
static FlMethodResponse * | clipboard_has_strings_async (FlPlatformHandler *self, FlMethodCall *method_call)
static gchar * | get_exit_response (FlMethodResponse *response)
static void | quit_application ()
static void | request_app_exit_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
static void | request_app_exit (FlPlatformHandler *self, const char *type)
static FlMethodResponse * | system_intitialization_complete (FlPlatformHandler *self, FlMethodCall *method_call)
static FlMethodResponse * | system_exit_application (FlPlatformHandler *self, FlMethodCall *method_call)
static FlMethodResponse * | system_sound_play (FlPlatformHandler *self, FlValue *args)
static FlMethodResponse * | system_navigator_pop (FlPlatformHandler *self)
static void | method_call_cb (FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
static void | fl_platform_handler_dispose (GObject *object)
static void | fl_platform_handler_class_init (FlPlatformHandlerClass *klass)
static void | fl_platform_handler_init (FlPlatformHandler *self)
FlPlatformHandler * | fl_platform_handler_new (FlBinaryMessenger *messenger)
void | fl_platform_handler_request_app_exit (FlPlatformHandler *self)

## Variables
static constexpr char | kChannelName [] = "flutter/platform"
static constexpr char | kBadArgumentsError [] = "Bad Arguments"
static constexpr char | kUnknownClipboardFormatError []
static constexpr char | kInProgressError [] = "In Progress"
static constexpr char | kGetClipboardDataMethod [] = "Clipboard.getData"
static constexpr char | kSetClipboardDataMethod [] = "Clipboard.setData"
static constexpr char | kClipboardHasStringsMethod [] = "Clipboard.hasStrings"
static constexpr char | kExitApplicationMethod [] = "System.exitApplication"
static constexpr char | kRequestAppExitMethod [] = "System.requestAppExit"
static constexpr char | kInitializationCompleteMethod []
static constexpr char | kPlaySoundMethod [] = "SystemSound.play"
static constexpr char | kSystemNavigatorPopMethod [] = "SystemNavigator.pop"
static constexpr char | kTextKey [] = "text"
static constexpr char | kValueKey [] = "value"
static constexpr char | kExitTypeKey [] = "type"
static constexpr char | kExitTypeCancelable [] = "cancelable"
static constexpr char | kExitTypeRequired [] = "required"
static constexpr char | kExitResponseKey [] = "response"
static constexpr char | kExitResponseCancel [] = "cancel"
static constexpr char | kExitResponseExit [] = "exit"
static constexpr char | kTextPlainFormat [] = "text/plain"
static constexpr char | kSoundTypeAlert [] = "SystemSoundType.alert"
static constexpr char | kSoundTypeClick [] = "SystemSoundType.click"

## Function Documentation

## ◆ clipboard_get_data_async()

static FlMethodResponse* clipboard_get_data_async | ( | FlPlatformHandler * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 119 of file fl_platform_handler.cc.

120 {
121 FlValue* args = fl_method_call_get_args(method_call);
122
123 if (fl_value_get_type(args) != FL_VALUE_TYPE_STRING) {
124 return FL_METHOD_RESPONSE(fl_method_error_response_new(
125 kBadArgumentsError, "Expected string", nullptr));
126 }
127
128 const gchar* format = fl_value_get_string(args);
129 if (strcmp(format, kTextPlainFormat) != 0) {
130 return FL_METHOD_RESPONSE(fl_method_error_response_new(
131 kUnknownClipboardFormatError, "GTK clipboard API only supports text",
132 nullptr));
133 }
134
135 GtkClipboard* clipboard =
136 gtk_clipboard_get_default(gdk_display_get_default());
137 gtk_clipboard_request_text(clipboard, clipboard_text_cb,
138 g_object_ref(method_call));
139
140 // Will respond later.
141 return nullptr;
142 }

References args, clipboard_text_cb(), fl_method_call_get_args(), fl_method_error_response_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, format, kBadArgumentsError, kTextPlainFormat, kUnknownClipboardFormatError, and method_call.

Referenced by method_call_cb().

## ◆ clipboard_has_strings_async()

static FlMethodResponse* clipboard_has_strings_async | ( | FlPlatformHandler * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 146 of file fl_platform_handler.cc.

148 {
149 GtkClipboard* clipboard =
150 gtk_clipboard_get_default(gdk_display_get_default());
151 gtk_clipboard_request_text(clipboard, clipboard_text_has_strings_cb,
152 g_object_ref(method_call));
153
154 // Will respond later.
155 return nullptr;
156 }

References clipboard_text_has_strings_cb(), and method_call.

Referenced by method_call_cb().

## ◆ clipboard_set_data()

static FlMethodResponse* clipboard_set_data | ( | FlPlatformHandler * | self,
|  | FlValue * | args
| ) |  |
| static

Definition at line 97 of file fl_platform_handler.cc.

98 {
99 if (fl_value_get_type(args) != FL_VALUE_TYPE_MAP) {
100 return FL_METHOD_RESPONSE(fl_method_error_response_new(
101 kBadArgumentsError, "Argument map missing or malformed", nullptr));
102 }
103
104 FlValue* text_value = fl_value_lookup_string(args, kTextKey);
105 if (text_value == nullptr ||
106 fl_value_get_type(text_value) != FL_VALUE_TYPE_STRING) {
107 return FL_METHOD_RESPONSE(fl_method_error_response_new(
108 kBadArgumentsError, "Missing clipboard text", nullptr));
109 }
110
111 GtkClipboard* clipboard =
112 gtk_clipboard_get_default(gdk_display_get_default());
113 gtk_clipboard_set_text(clipboard, fl_value_get_string(text_value), -1);
114
115 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
116 }

References args, fl_method_error_response_new(), fl_method_success_response_new(), fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kBadArgumentsError, and kTextKey.

Referenced by method_call_cb().

## ◆ clipboard_text_cb()

static void clipboard_text_cb | ( | GtkClipboard * | clipboard,
|  | const gchar * | text,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 64 of file fl_platform_handler.cc.

66 {
67 g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data);
68
69 g_autoptr(FlValue) result = nullptr;
70 if (text != nullptr) {
71 result = fl_value_new_map();
72 fl_value_set_string_take(result, kTextKey, fl_value_new_string(text));
73 }
74
75 g_autoptr(FlMethodResponse) response =
76 FL_METHOD_RESPONSE(fl_method_success_response_new(result));
77 send_response(method_call, response);
78 }

References fl_method_success_response_new(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), kTextKey, method_call, result, send_response(), and user_data.

Referenced by clipboard_get_data_async().

## ◆ clipboard_text_has_strings_cb()

static void clipboard_text_has_strings_cb | ( | GtkClipboard * | clipboard,
|  | const gchar * | text,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 81 of file fl_platform_handler.cc.

83 {
84 g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data);
85
86 g_autoptr(FlValue) result = fl_value_new_map();
87 fl_value_set_string_take(
88 result, kValueKey,
89 fl_value_new_bool(text != nullptr && strlen(text) > 0));
90
91 g_autoptr(FlMethodResponse) response =
92 FL_METHOD_RESPONSE(fl_method_success_response_new(result));
93 send_response(method_call, response);
94 }

References fl_method_success_response_new(), fl_value_new_bool(), fl_value_new_map(), fl_value_set_string_take(), kValueKey, method_call, result, send_response(), and user_data.

Referenced by clipboard_has_strings_async().

## ◆ fl_platform_handler_class_init()

static void fl_platform_handler_class_init | ( | FlPlatformHandlerClass * | klass | ) |
| static

Definition at line 397 of file fl_platform_handler.cc.

397 {
398 G_OBJECT_CLASS(klass)->dispose = fl_platform_handler_dispose;
399 }

References fl_platform_handler_dispose().

## ◆ fl_platform_handler_dispose()

static void fl_platform_handler_dispose | ( | GObject * | object | ) |
| static

Definition at line 385 of file fl_platform_handler.cc.

385 {
386 FlPlatformHandler* self = FL_PLATFORM_HANDLER(object);
387
388 g_cancellable_cancel(self->cancellable);
389
390 g_clear_object(&self->channel);
391 g_clear_object(&self->exit_application_method_call);
392 g_clear_object(&self->cancellable);
393
394 G_OBJECT_CLASS(fl_platform_handler_parent_class)->dispose(object);
395 }

Referenced by fl_platform_handler_class_init().

## ◆ fl_platform_handler_init()

static void fl_platform_handler_init | ( | FlPlatformHandler * | self | ) |
| static

Definition at line 401 of file fl_platform_handler.cc.

401 {
402 self->cancellable = g_cancellable_new();
403 }

## ◆ fl_platform_handler_new()

FlPlatformHandler* fl_platform_handler_new | ( | FlBinaryMessenger * | messenger | ) |

FlPlatformHandler:

#FlPlatformHandler is a handler that implements the shell side of SystemChannels.platform from the Flutter services library. fl_platform_handler_new: @messenger: an #FlBinaryMessenger

Creates a new handler that implements SystemChannels.platform from the Flutter services library.

Returns: a new #FlPlatformHandler

Definition at line 405 of file fl_platform_handler.cc.

405 {
406 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
407
408 FlPlatformHandler* self = FL_PLATFORM_HANDLER(
409 g_object_new(fl_platform_handler_get_type(), nullptr));
410
411 g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
412 self->channel =
413 fl_method_channel_new(messenger, kChannelName, FL_METHOD_CODEC(codec));
414 fl_method_channel_set_method_call_handler(self->channel, method_call_cb, self,
415 nullptr);
416 self->app_initialization_complete = FALSE;
417
418 return self;
419 }

References fl_json_method_codec_new(), fl_method_channel_new(), fl_method_channel_set_method_call_handler(), kChannelName, and method_call_cb().

Referenced by create_context_cb(), fl_test_application_activate(), and TEST().

## ◆ fl_platform_handler_request_app_exit()

void fl_platform_handler_request_app_exit | ( | FlPlatformHandler * | handler | ) |

fl_platform_handler_request_app_exit: @handler: an #FlPlatformHandler

Request the application exits (i.e. due to the window being requested to be closed).

Calling this will only send an exit request to the framework if the framework has already indicated that it is ready to receive requests by sending a "System.initializationComplete" method call on the platform channel. Calls before initialization is complete will result in an immediate exit.

Definition at line 421 of file fl_platform_handler.cc.

421 {
422 g_return_if_fail(FL_IS_PLATFORM_HANDLER(self));
423 // Request a cancellable exit.
424 request_app_exit(self, kExitTypeCancelable);
425 }

References kExitTypeCancelable, and request_app_exit().

Referenced by window_delete_event_cb().

## ◆ get_exit_response()

static gchar* get_exit_response | ( | FlMethodResponse * | response | ) |
| static

Definition at line 159 of file fl_platform_handler.cc.

159 {
160 if (response == nullptr) {
161 return nullptr;
162 }
163
164 g_autoptr(GError) error = nullptr;
165 FlValue* result = fl_method_response_get_result(response, &error);
166 if (result == nullptr) {
167 g_warning("Error returned from System.requestAppExit: %s", error->message);
168 return nullptr;
169 }
170 if (fl_value_get_type(result) != FL_VALUE_TYPE_MAP) {
171 g_warning("System.requestAppExit result argument map missing or malformed");
172 return nullptr;
173 }
174
175 FlValue* response_value = fl_value_lookup_string(result, kExitResponseKey);
176 if (fl_value_get_type(response_value) != FL_VALUE_TYPE_STRING) {
177 g_warning("Invalid response from System.requestAppExit");
178 return nullptr;
179 }
180 return g_strdup(fl_value_get_string(response_value));
181 }

References error, fl_method_response_get_result(), fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kExitResponseKey, and result.

Referenced by request_app_exit_response_cb().

## ◆ method_call_cb()

static void method_call_cb | ( | FlMethodChannel * | channel,
|  | FlMethodCall * | method_call,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 353 of file fl_platform_handler.cc.

355 {
356 FlPlatformHandler* self = FL_PLATFORM_HANDLER(user_data);
357
358 const gchar* method = fl_method_call_get_name(method_call);
359 FlValue* args = fl_method_call_get_args(method_call);
360
361 g_autoptr(FlMethodResponse) response = nullptr;
362 if (strcmp(method, kSetClipboardDataMethod) == 0) {
363 response = clipboard_set_data(self, args);
364 } else if (strcmp(method, kGetClipboardDataMethod) == 0) {
365 response = clipboard_get_data_async(self, method_call);
366 } else if (strcmp(method, kClipboardHasStringsMethod) == 0) {
367 response = clipboard_has_strings_async(self, method_call);
368 } else if (strcmp(method, kExitApplicationMethod) == 0) {
369 response = system_exit_application(self, method_call);
370 } else if (strcmp(method, kInitializationCompleteMethod) == 0) {
371 response = system_intitialization_complete(self, method_call);
372 } else if (strcmp(method, kPlaySoundMethod) == 0) {
373 response = system_sound_play(self, args);
374 } else if (strcmp(method, kSystemNavigatorPopMethod) == 0) {
375 response = system_navigator_pop(self);
376 } else {
377 response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
378 }
379
380 if (response != nullptr) {
381 send_response(method_call, response);
382 }
383 }

References args, clipboard_get_data_async(), clipboard_has_strings_async(), clipboard_set_data(), fl_method_call_get_args(), fl_method_call_get_name(), fl_method_not_implemented_response_new(), kClipboardHasStringsMethod, kExitApplicationMethod, kGetClipboardDataMethod, kInitializationCompleteMethod, kPlaySoundMethod, kSetClipboardDataMethod, kSystemNavigatorPopMethod, method_call, send_response(), system_exit_application(), system_intitialization_complete(), system_navigator_pop(), system_sound_play(), and user_data.

Referenced by fl_platform_handler_new().

## ◆ quit_application()

static void quit_application | ( |  | ) |
| static

Definition at line 184 of file fl_platform_handler.cc.

184 {
185 GApplication* app = g_application_get_default();
186 if (app == nullptr) {
187 // Unable to gracefully quit, so just exit the process.
188 exit(0);
189 }
190
191 // GtkApplication windows contain a reference back to the application.
192 // Break them so the application object can cleanup.
193 // See https://gitlab.gnome.org/GNOME/gtk/-/issues/6190
194 if (GTK_IS_APPLICATION(app)) {
195 // List is copied as it will be modified as windows are disconnected from
196 // the application.
197 g_autoptr(GList) windows =
198 g_list_copy(gtk_application_get_windows(GTK_APPLICATION(app)));
199 for (GList* link = windows; link != NULL; link = link->next) {
200 GtkWidget* window = GTK_WIDGET(link->data);
201 gtk_window_set_application(GTK_WINDOW(window), NULL);
202 }
203 }
204
205 g_application_quit(app);
206 }

Referenced by request_app_exit(), request_app_exit_response_cb(), system_exit_application(), and system_navigator_pop().

## ◆ request_app_exit()

static void request_app_exit | ( | FlPlatformHandler * | self,
|  | const char * | type
| ) |  |
| static

Definition at line 256 of file fl_platform_handler.cc.

256 {
257 g_autoptr(FlValue) args = fl_value_new_map();
258 if (!self->app_initialization_complete ||
259 g_str_equal(type, kExitTypeRequired)) {
260 quit_application();
261 return;
262 }
263
264 fl_value_set_string_take(args, kExitTypeKey, fl_value_new_string(type));
265 fl_method_channel_invoke_method(self->channel, kRequestAppExitMethod, args,
266 self->cancellable,
267 request_app_exit_response_cb, self);
268 }

References args, fl_method_channel_invoke_method(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), kExitTypeKey, kExitTypeRequired, kRequestAppExitMethod, quit_application(), request_app_exit_response_cb(), and type.

Referenced by fl_platform_handler_request_app_exit(), and system_exit_application().

## ◆ request_app_exit_response_cb()

static void request_app_exit_response_cb | ( | GObject * | object,
|  | GAsyncResult * | result,
|  | gpointer | user_data
| ) |  |
| static

Definition at line 209 of file fl_platform_handler.cc.

211 {
212 FlPlatformHandler* self = FL_PLATFORM_HANDLER(user_data);
213
214 g_autoptr(GError) error = nullptr;
215 g_autoptr(FlMethodResponse) method_response =
216 fl_method_channel_invoke_method_finish(FL_METHOD_CHANNEL(object), result,
217 &error);
218 g_autofree gchar* exit_response = nullptr;
219 if (method_response == nullptr) {
220 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
221 return;
222 }
223 g_warning("Failed to complete System.requestAppExit: %s", error->message);
224 } else {
225 exit_response = get_exit_response(method_response);
226 }
227 // If something went wrong, then just exit.
228 if (exit_response == nullptr) {
229 exit_response = g_strdup(kExitResponseExit);
230 }
231
232 if (g_str_equal(exit_response, kExitResponseExit)) {
233 quit_application();
234 } else if (g_str_equal(exit_response, kExitResponseCancel)) {
235 // Canceled - no action to take.
236 }
237
238 // If request was due to a request from Flutter, pass result back.
239 if (self->exit_application_method_call != nullptr) {
240 g_autoptr(FlValue) exit_result = fl_value_new_map();
241 fl_value_set_string_take(exit_result, kExitResponseKey,
242 fl_value_new_string(exit_response));
243 g_autoptr(FlMethodResponse) exit_response =
244 FL_METHOD_RESPONSE(fl_method_success_response_new(exit_result));
245 if (!fl_method_call_respond(self->exit_application_method_call,
246 exit_response, &error)) {
247 g_warning("Failed to send response to System.exitApplication: %s",
248 error->message);
249 }
250 g_clear_object(&self->exit_application_method_call);
251 }
252 }

References error, fl_method_call_respond(), fl_method_channel_invoke_method_finish(), fl_method_success_response_new(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), get_exit_response(), kExitResponseCancel, kExitResponseExit, kExitResponseKey, quit_application(), result, and user_data.

Referenced by request_app_exit().

## ◆ send_response()

static void send_response | ( | FlMethodCall * | method_call,
|  | FlMethodResponse * | response
| ) |  |
| static

Definition at line 55 of file fl_platform_handler.cc.

56 {
57 g_autoptr(GError) error = nullptr;
58 if (!fl_method_call_respond(method_call, response, &error)) {
59 g_warning("Failed to send method call response: %s", error->message);
60 }
61 }

References error, fl_method_call_respond(), and method_call.

Referenced by clipboard_text_cb(), clipboard_text_has_strings_cb(), and method_call_cb().

## ◆ system_exit_application()

static FlMethodResponse* system_exit_application | ( | FlPlatformHandler * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 281 of file fl_platform_handler.cc.

282 {
283 FlValue* args = fl_method_call_get_args(method_call);
284 if (fl_value_get_type(args) != FL_VALUE_TYPE_MAP) {
285 return FL_METHOD_RESPONSE(fl_method_error_response_new(
286 kBadArgumentsError, "Argument map missing or malformed", nullptr));
287 }
288
289 FlValue* type_value = fl_value_lookup_string(args, kExitTypeKey);
290 if (type_value == nullptr ||
291 fl_value_get_type(type_value) != FL_VALUE_TYPE_STRING) {
292 return FL_METHOD_RESPONSE(fl_method_error_response_new(
293 kBadArgumentsError, "Missing type argument", nullptr));
294 }
295 const char* type = fl_value_get_string(type_value);
296
297 // Save method call to respond to when our request to Flutter completes.
298 if (self->exit_application_method_call != nullptr) {
299 return FL_METHOD_RESPONSE(fl_method_error_response_new(
300 kInProgressError, "Request already in progress", nullptr));
301 }
302 self->exit_application_method_call =
303 FL_METHOD_CALL(g_object_ref(method_call));
304
305 // Requested to immediately quit if the app hasn't yet signaled that it is
306 // ready to handle requests, or if the type of exit requested is "required".
307 if (!self->app_initialization_complete ||
308 g_str_equal(type, kExitTypeRequired)) {
309 quit_application();
310 g_autoptr(FlValue) exit_result = fl_value_new_map();
311 fl_value_set_string_take(exit_result, kExitResponseKey,
312 fl_value_new_string(kExitResponseExit));
313 return FL_METHOD_RESPONSE(fl_method_success_response_new(exit_result));
314 }
315
316 // Send the request back to Flutter to follow the standard process.
317 request_app_exit(self, type);
318
319 // Will respond later.
320 return nullptr;
321 }

References args, fl_method_call_get_args(), fl_method_error_response_new(), fl_method_success_response_new(), fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, kBadArgumentsError, kExitResponseExit, kExitResponseKey, kExitTypeKey, kExitTypeRequired, kInProgressError, method_call, quit_application(), request_app_exit(), and type.

Referenced by method_call_cb().

## ◆ system_intitialization_complete()

static FlMethodResponse* system_intitialization_complete | ( | FlPlatformHandler * | self,
|  | FlMethodCall * | method_call
| ) |  |
| static

Definition at line 273 of file fl_platform_handler.cc.

275 {
276 self->app_initialization_complete = TRUE;
277 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
278 }

References fl_method_success_response_new(), and TRUE.

Referenced by method_call_cb().

## ◆ system_navigator_pop()

static FlMethodResponse* system_navigator_pop | ( | FlPlatformHandler * | self | ) |
| static

Definition at line 347 of file fl_platform_handler.cc.

347 {
348 quit_application();
349 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
350 }

References fl_method_success_response_new(), and quit_application().

Referenced by method_call_cb().

## ◆ system_sound_play()

static FlMethodResponse* system_sound_play | ( | FlPlatformHandler * | self,
|  | FlValue * | args
| ) |  |
| static

Definition at line 324 of file fl_platform_handler.cc.

325 {
326 if (fl_value_get_type(args) != FL_VALUE_TYPE_STRING) {
327 return FL_METHOD_RESPONSE(fl_method_error_response_new(
328 kBadArgumentsError, "Expected string", nullptr));
329 }
330
331 const gchar* type = fl_value_get_string(args);
332 if (strcmp(type, kSoundTypeAlert) == 0) {
333 GdkDisplay* display = gdk_display_get_default();
334 if (display != nullptr) {
335 gdk_display_beep(display);
336 }
337 } else if (strcmp(type, kSoundTypeClick) == 0) {
338 // We don't make sounds for keyboard on desktops.
339 } else {
340 g_warning("Ignoring unknown sound type %s in SystemSound.play.\n", type);
341 }
342
343 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
344 }

References args, fl_method_error_response_new(), fl_method_success_response_new(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, kBadArgumentsError, kSoundTypeAlert, kSoundTypeClick, and type.

Referenced by method_call_cb().

## Variable Documentation

## ◆ kBadArgumentsError

constexpr char kBadArgumentsError[] = "Bad Arguments"
| staticconstexpr

Definition at line 14 of file fl_platform_handler.cc.

Referenced by clipboard_get_data_async(), clipboard_set_data(), system_exit_application(), and system_sound_play().

## ◆ kChannelName

constexpr char kChannelName[] = "flutter/platform"
| staticconstexpr

Definition at line 13 of file fl_platform_handler.cc.

Referenced by fl_platform_handler_new().

## ◆ kClipboardHasStringsMethod

constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings"
| staticconstexpr

Definition at line 20 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kExitApplicationMethod

constexpr char kExitApplicationMethod[] = "System.exitApplication"
| staticconstexpr

Definition at line 21 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kExitResponseCancel

constexpr char kExitResponseCancel[] = "cancel"
| staticconstexpr

Definition at line 35 of file fl_platform_handler.cc.

Referenced by request_app_exit_response_cb().

## ◆ kExitResponseExit

constexpr char kExitResponseExit[] = "exit"
| staticconstexpr

Definition at line 36 of file fl_platform_handler.cc.

Referenced by request_app_exit_response_cb(), and system_exit_application().

## ◆ kExitResponseKey

constexpr char kExitResponseKey[] = "response"
| staticconstexpr

Definition at line 34 of file fl_platform_handler.cc.

Referenced by get_exit_response(), request_app_exit_response_cb(), and system_exit_application().

## ◆ kExitTypeCancelable

constexpr char kExitTypeCancelable[] = "cancelable"
| staticconstexpr

Definition at line 31 of file fl_platform_handler.cc.

Referenced by fl_platform_handler_request_app_exit().

## ◆ kExitTypeKey

constexpr char kExitTypeKey[] = "type"
| staticconstexpr

Definition at line 30 of file fl_platform_handler.cc.

Referenced by request_app_exit(), and system_exit_application().

## ◆ kExitTypeRequired

constexpr char kExitTypeRequired[] = "required"
| staticconstexpr

Definition at line 32 of file fl_platform_handler.cc.

Referenced by request_app_exit(), and system_exit_application().

## ◆ kGetClipboardDataMethod

constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"
| staticconstexpr

Definition at line 18 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kInitializationCompleteMethod

constexpr char kInitializationCompleteMethod[]
| staticconstexpr

Initial value:
=
"System.initializationComplete"

Definition at line 23 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kInProgressError

constexpr char kInProgressError[] = "In Progress"
| staticconstexpr

Definition at line 17 of file fl_platform_handler.cc.

Referenced by system_exit_application().

## ◆ kPlaySoundMethod

constexpr char kPlaySoundMethod[] = "SystemSound.play"
| staticconstexpr

Definition at line 25 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kRequestAppExitMethod

constexpr char kRequestAppExitMethod[] = "System.requestAppExit"
| staticconstexpr

Definition at line 22 of file fl_platform_handler.cc.

Referenced by request_app_exit().

## ◆ kSetClipboardDataMethod

constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"
| staticconstexpr

Definition at line 19 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kSoundTypeAlert

constexpr char kSoundTypeAlert[] = "SystemSoundType.alert"
| staticconstexpr

Definition at line 40 of file fl_platform_handler.cc.

Referenced by system_sound_play().

## ◆ kSoundTypeClick

constexpr char kSoundTypeClick[] = "SystemSoundType.click"
| staticconstexpr

Definition at line 41 of file fl_platform_handler.cc.

Referenced by system_sound_play().

## ◆ kSystemNavigatorPopMethod

constexpr char kSystemNavigatorPopMethod[] = "SystemNavigator.pop"
| staticconstexpr

Definition at line 26 of file fl_platform_handler.cc.

Referenced by method_call_cb().

## ◆ kTextKey

constexpr char kTextKey[] = "text"
| staticconstexpr

Definition at line 27 of file fl_platform_handler.cc.

Referenced by clipboard_set_data(), and clipboard_text_cb().

## ◆ kTextPlainFormat

constexpr char kTextPlainFormat[] = "text/plain"
| staticconstexpr

Definition at line 38 of file fl_platform_handler.cc.

Referenced by clipboard_get_data_async().

## ◆ kUnknownClipboardFormatError

constexpr char kUnknownClipboardFormatError[]
| staticconstexpr

Initial value:
=
"Unknown Clipboard Format"

Definition at line 15 of file fl_platform_handler.cc.

Referenced by clipboard_get_data_async().

## ◆ kValueKey

constexpr char kValueKey[] = "value"
| staticconstexpr

Definition at line 28 of file fl_platform_handler.cc.

Referenced by clipboard_text_has_strings_cb().

system_sound_play
static FlMethodResponse * system_sound_play(FlPlatformHandler *self, FlValue *args)
Definition: fl_platform_handler.cc:324
kExitTypeRequired
static constexpr char kExitTypeRequired[]
Definition: fl_platform_handler.cc:32
fl_json_method_codec_new
G_MODULE_EXPORT FlJsonMethodCodec * fl_json_method_codec_new()
Definition: fl_json_method_codec.cc:205
kExitApplicationMethod
static constexpr char kExitApplicationMethod[]
Definition: fl_platform_handler.cc:21
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:75
kSoundTypeClick
static constexpr char kSoundTypeClick[]
Definition: fl_platform_handler.cc:41
kInitializationCompleteMethod
static constexpr char kInitializationCompleteMethod[]
Definition: fl_platform_handler.cc:23
fl_method_channel_new
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
Definition: fl_method_channel.cc:112
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
type
uint8_t type
Definition: fl_standard_message_codec_test.cc:1115
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
clipboard_text_has_strings_cb
static void clipboard_text_has_strings_cb(GtkClipboard *clipboard, const gchar *text, gpointer user_data)
Definition: fl_platform_handler.cc:81
fl_method_not_implemented_response_new
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
Definition: fl_method_response.cc:179
kChannelName
static constexpr char kChannelName[]
Definition: fl_platform_handler.cc:13
fl_method_channel_invoke_method_finish
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
Definition: fl_method_channel.cc:192
fl_platform_handler_dispose
static void fl_platform_handler_dispose(GObject *object)
Definition: fl_platform_handler.cc:385
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
system_navigator_pop
static FlMethodResponse * system_navigator_pop(FlPlatformHandler *self)
Definition: fl_platform_handler.cc:347
kGetClipboardDataMethod
static constexpr char kGetClipboardDataMethod[]
Definition: fl_platform_handler.cc:18
fl_method_response_get_result
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
Definition: fl_method_response.cc:82
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
kSoundTypeAlert
static constexpr char kSoundTypeAlert[]
Definition: fl_platform_handler.cc:40
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
clipboard_has_strings_async
static FlMethodResponse * clipboard_has_strings_async(FlPlatformHandler *self, FlMethodCall *method_call)
Definition: fl_platform_handler.cc:146
kExitResponseKey
static constexpr char kExitResponseKey[]
Definition: fl_platform_handler.cc:34
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
get_exit_response
static gchar * get_exit_response(FlMethodResponse *response)
Definition: fl_platform_handler.cc:159
clipboard_set_data
static FlMethodResponse * clipboard_set_data(FlPlatformHandler *self, FlValue *args)
Definition: fl_platform_handler.cc:97
kExitTypeCancelable
static constexpr char kExitTypeCancelable[]
Definition: fl_platform_handler.cc:31
fl_method_call_respond
G_MODULE_EXPORT gboolean fl_method_call_respond(FlMethodCall *self, FlMethodResponse *response, GError **error)
Definition: fl_method_call.cc:77
kSystemNavigatorPopMethod
static constexpr char kSystemNavigatorPopMethod[]
Definition: fl_platform_handler.cc:26
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
kValueKey
static constexpr char kValueKey[]
Definition: fl_platform_handler.cc:28
method_call
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
Definition: fl_method_channel.h:120
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
clipboard_get_data_async
static FlMethodResponse * clipboard_get_data_async(FlPlatformHandler *self, FlMethodCall *method_call)
Definition: fl_platform_handler.cc:119
kExitTypeKey
static constexpr char kExitTypeKey[]
Definition: fl_platform_handler.cc:30
fl_method_call_get_name
const G_MODULE_EXPORT gchar * fl_method_call_get_name(FlMethodCall *self)
Definition: fl_method_call.cc:67
kTextPlainFormat
static constexpr char kTextPlainFormat[]
Definition: fl_platform_handler.cc:38
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
kTextKey
static constexpr char kTextKey[]
Definition: fl_platform_handler.cc:27
kRequestAppExitMethod
static constexpr char kRequestAppExitMethod[]
Definition: fl_platform_handler.cc:22
clipboard_text_cb
static void clipboard_text_cb(GtkClipboard *clipboard, const gchar *text, gpointer user_data)
Definition: fl_platform_handler.cc:64
kInProgressError
static constexpr char kInProgressError[]
Definition: fl_platform_handler.cc:17
fl_method_channel_invoke_method
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_method_channel.cc:162
send_response
static void send_response(FlMethodCall *method_call, FlMethodResponse *response)
Definition: fl_platform_handler.cc:55
kUnknownClipboardFormatError
static constexpr char kUnknownClipboardFormatError[]
Definition: fl_platform_handler.cc:15
fl_method_channel_set_method_call_handler
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
Definition: fl_method_channel.cc:134
kBadArgumentsError
static constexpr char kBadArgumentsError[]
Definition: fl_platform_handler.cc:14
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
kSetClipboardDataMethod
static constexpr char kSetClipboardDataMethod[]
Definition: fl_platform_handler.cc:19
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
quit_application
static void quit_application()
Definition: fl_platform_handler.cc:184
kClipboardHasStringsMethod
static constexpr char kClipboardHasStringsMethod[]
Definition: fl_platform_handler.cc:20
kPlaySoundMethod
static constexpr char kPlaySoundMethod[]
Definition: fl_platform_handler.cc:25
system_intitialization_complete
static FlMethodResponse * system_intitialization_complete(FlPlatformHandler *self, FlMethodCall *method_call)
Definition: fl_platform_handler.cc:273
request_app_exit_response_cb
static void request_app_exit_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_platform_handler.cc:209
kExitResponseCancel
static constexpr char kExitResponseCancel[]
Definition: fl_platform_handler.cc:35
system_exit_application
static FlMethodResponse * system_exit_application(FlPlatformHandler *self, FlMethodCall *method_call)
Definition: fl_platform_handler.cc:281
fl_method_call_get_args
G_MODULE_EXPORT FlValue * fl_method_call_get_args(FlMethodCall *self)
Definition: fl_method_call.cc:72
request_app_exit
static void request_app_exit(FlPlatformHandler *self, const char *type)
Definition: fl_platform_handler.cc:256
method_call_cb
static void method_call_cb(FlMethodChannel *channel, FlMethodCall *method_call, gpointer user_data)
Definition: fl_platform_handler.cc:353
format
uint32_t uint32_t * format
Definition: fl_texture_registrar_test.cc:41
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
kExitResponseExit
static constexpr char kExitResponseExit[]
Definition: fl_platform_handler.cc:36