|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#include "flutter/shell/platform/linux/fl_platform_plugin.h" |
| 6 | +#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h" |
| 7 | +#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h" |
| 8 | + |
| 9 | +struct _FlPlatformPlugin { |
| 10 | + GObject parent_instance; |
| 11 | + |
| 12 | + FlMethodChannel* channel; |
| 13 | +}; |
| 14 | + |
| 15 | +G_DEFINE_TYPE(FlPlatformPlugin, fl_platform_plugin, G_TYPE_OBJECT) |
| 16 | + |
| 17 | +static void method_call_cb(FlMethodChannel* channel, |
| 18 | + FlMethodCall* method_call, |
| 19 | + gpointer user_data) { |
| 20 | + // FlPlatformPlugin* self = FL_PLATFORM_PLUGIN(user_data); |
| 21 | + |
| 22 | + const gchar* method = fl_method_call_get_name(method_call); |
| 23 | + FlValue* args = fl_method_call_get_args(method_call); |
| 24 | + if (strcmp(method, "Clipboard.setData") == 0) { |
| 25 | + g_debug("Got Clipboard.setData\n"); |
| 26 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 27 | + } else if (strcmp(method, "Clipboard.getData") == 0) { |
| 28 | + g_debug("Got Clipboard.getData\n"); |
| 29 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 30 | + } else if (strcmp(method, "HapticFeedback.vibrate") == 0) { |
| 31 | + g_debug("Got HapticFeedback.vibrate\n"); |
| 32 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 33 | + } else if (strcmp(method, "SystemSound.play") == 0) { |
| 34 | + if (fl_value_get_type(args) != FL_VALUE_TYPE_STRING) { |
| 35 | + g_warning("Ignoring unknown SystemSound.play message with unknown type"); |
| 36 | + fl_method_call_respond_error(method_call, "FIXME", nullptr, nullptr, |
| 37 | + nullptr); |
| 38 | + } else { |
| 39 | + const gchar* type = fl_value_get_string(args); |
| 40 | + g_debug("Got SystemSound.play(\"%s\")", type); |
| 41 | + // FIXME(robert-ancell): Play sound |
| 42 | + fl_method_call_respond(method_call, nullptr, nullptr); |
| 43 | + } |
| 44 | + } else if (strcmp(method, "SystemChrome.setPreferredOrientations") == 0) { |
| 45 | + g_debug("Got SystemChrome.setPreferredOrientations\n"); |
| 46 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 47 | + } else if (strcmp(method, "SystemChrome.setApplicationSwitcherDescription") == |
| 48 | + 0) { |
| 49 | + if (fl_value_get_type(args) != FL_VALUE_TYPE_MAP) { |
| 50 | + g_warning("Ignoring unknown flutter/platform message type"); |
| 51 | + fl_method_call_respond_error(method_call, "FIXME", nullptr, nullptr, |
| 52 | + nullptr); |
| 53 | + } else { |
| 54 | + FlValue* label_value = fl_value_lookup_string(args, "label"); |
| 55 | + FlValue* primary_color_value = |
| 56 | + fl_value_lookup_string(args, "primaryColor"); |
| 57 | + |
| 58 | + const gchar* label = |
| 59 | + label_value != nullptr && |
| 60 | + fl_value_get_type(label_value) == FL_VALUE_TYPE_STRING |
| 61 | + ? fl_value_get_string(label_value) |
| 62 | + : ""; |
| 63 | + int64_t primary_color = |
| 64 | + primary_color_value != nullptr && |
| 65 | + fl_value_get_type(primary_color_value) == FL_VALUE_TYPE_INT |
| 66 | + ? fl_value_get_int(primary_color_value) |
| 67 | + : -1; |
| 68 | + |
| 69 | + g_debug( |
| 70 | + "Got SystemChrome.setApplicationSwitcherDescription(\"%s\", " |
| 71 | + "%" G_GINT64_FORMAT ")\n", |
| 72 | + label, primary_color); |
| 73 | + // FIXME(robert-ancell): Use label |
| 74 | + fl_method_call_respond(method_call, nullptr, nullptr); |
| 75 | + } |
| 76 | + |
| 77 | + } else if (strcmp(method, "SystemChrome.setEnabledSystemUIOverlays") == 0) { |
| 78 | + g_debug("Got SystemChrome.setEnabledSystemUIOverlays\n"); |
| 79 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 80 | + } else if (strcmp(method, "SystemChrome.setSystemUIOverlayStyle") == 0) { |
| 81 | + g_debug("Got SystemChrome.setSystemUIOverlayStyle\n"); |
| 82 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 83 | + } else if (strcmp(method, "SystemNavigator.pop") == 0) { |
| 84 | + g_debug("Got SystemNavigator.pop\n"); |
| 85 | + // FIXME(robert-ancell): Quit the application |
| 86 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 87 | + } else |
| 88 | + fl_method_call_respond_not_implemented(method_call, nullptr); |
| 89 | +} |
| 90 | + |
| 91 | +static void fl_platform_plugin_dispose(GObject* object) { |
| 92 | + FlPlatformPlugin* self = FL_PLATFORM_PLUGIN(object); |
| 93 | + |
| 94 | + g_clear_object(&self->channel); |
| 95 | + |
| 96 | + G_OBJECT_CLASS(fl_platform_plugin_parent_class)->dispose(object); |
| 97 | +} |
| 98 | + |
| 99 | +static void fl_platform_plugin_class_init(FlPlatformPluginClass* klass) { |
| 100 | + G_OBJECT_CLASS(klass)->dispose = fl_platform_plugin_dispose; |
| 101 | +} |
| 102 | + |
| 103 | +static void fl_platform_plugin_init(FlPlatformPlugin* self) {} |
| 104 | + |
| 105 | +FlPlatformPlugin* fl_platform_plugin_new(FlBinaryMessenger* messenger) { |
| 106 | + g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr); |
| 107 | + |
| 108 | + FlPlatformPlugin* self = |
| 109 | + FL_PLATFORM_PLUGIN(g_object_new(fl_platform_plugin_get_type(), nullptr)); |
| 110 | + |
| 111 | + g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new(); |
| 112 | + self->channel = fl_method_channel_new(messenger, "flutter/platform", |
| 113 | + FL_METHOD_CODEC(codec)); |
| 114 | + fl_method_channel_set_method_call_handler(self->channel, method_call_cb, |
| 115 | + self); |
| 116 | + |
| 117 | + return self; |
| 118 | +} |
0 commit comments