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

Commit 7d89ca9

Browse files
committed
Add FlPlatformPlugin
1 parent 8b57b07 commit 7d89ca9

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,8 @@ FILE: ../../../flutter/shell/platform/linux/fl_method_codec_private.h
12091209
FILE: ../../../flutter/shell/platform/linux/fl_method_codec_test.cc
12101210
FILE: ../../../flutter/shell/platform/linux/fl_method_response.cc
12111211
FILE: ../../../flutter/shell/platform/linux/fl_method_response_test.cc
1212+
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc
1213+
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.h
12121214
FILE: ../../../flutter/shell/platform/linux/fl_renderer.cc
12131215
FILE: ../../../flutter/shell/platform/linux/fl_renderer.h
12141216
FILE: ../../../flutter/shell/platform/linux/fl_renderer_x11.cc

shell/platform/linux/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ source_set("flutter_linux") {
8484
"fl_method_channel.cc",
8585
"fl_method_codec.cc",
8686
"fl_method_response.cc",
87+
"fl_platform_plugin.cc",
8788
"fl_renderer.cc",
8889
"fl_renderer_x11.cc",
8990
"fl_standard_message_codec.cc",
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_PLATFORM_PLUGIN_H_
6+
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_PLATFORM_PLUGIN_H_
7+
8+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
9+
10+
G_BEGIN_DECLS
11+
12+
G_DECLARE_FINAL_TYPE(FlPlatformPlugin,
13+
fl_platform_plugin,
14+
FL,
15+
PLATFORM_PLUGIN,
16+
GObject);
17+
18+
/**
19+
* FlPlatformPlugin:
20+
*
21+
* #FlPlatformPlugin is a platform channel that implements the shell side
22+
* of PlatformPlugins.platform from the Flutter services library.
23+
*/
24+
25+
/**
26+
* fl_platform_plugin_new:
27+
* @messenger: an #FlBinaryMessenger
28+
*
29+
* Creates a new platform channel.
30+
*
31+
* Returns: a new #FlPlatformPlugin
32+
*/
33+
FlPlatformPlugin* fl_platform_plugin_new(FlBinaryMessenger* messenger);
34+
35+
G_END_DECLS
36+
37+
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_PLATFORM_PLUGIN_H_

shell/platform/linux/fl_view.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
66

77
#include "flutter/shell/platform/linux/fl_engine_private.h"
8+
#include "flutter/shell/platform/linux/fl_platform_plugin.h"
89
#include "flutter/shell/platform/linux/fl_renderer_x11.h"
910
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
1011

@@ -26,6 +27,9 @@ struct _FlView {
2627

2728
// Pointer button state recorded for sending status updates
2829
int64_t button_state;
30+
31+
// Flutter system channel handlers
32+
FlPlatformPlugin* platform_plugin;
2933
};
3034

3135
enum { PROP_FLUTTER_PROJECT = 1, PROP_LAST };
@@ -81,6 +85,10 @@ static void fl_view_constructed(GObject* object) {
8185

8286
self->renderer = fl_renderer_x11_new();
8387
self->engine = fl_engine_new(self->project, FL_RENDERER(self->renderer));
88+
89+
// Create system channel handlers
90+
FlBinaryMessenger* messenger = fl_engine_get_binary_messenger(self->engine);
91+
self->platform_plugin = fl_platform_plugin_new(messenger);
8492
}
8593

8694
static void fl_view_set_property(GObject* object,
@@ -122,6 +130,7 @@ static void fl_view_dispose(GObject* object) {
122130
g_clear_object(&self->project);
123131
g_clear_object(&self->renderer);
124132
g_clear_object(&self->engine);
133+
g_clear_object(&self->platform_plugin);
125134

126135
G_OBJECT_CLASS(fl_view_parent_class)->dispose(object);
127136
}

0 commit comments

Comments
 (0)