| Flutter Linux Embedder |

fl_settings_channel.cc
Go to the documentation of this file.
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_settings_channel.h"
6
7 #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"
8 #include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
9
10 static constexpr char kChannelName[] = "flutter/settings";
11 static constexpr char kTextScaleFactorKey[] = "textScaleFactor";
12 static constexpr char kAlwaysUse24HourFormatKey[] = "alwaysUse24HourFormat";
13 static constexpr char kPlatformBrightnessKey[] = "platformBrightness";
14 static constexpr char kPlatformBrightnessLight[] = "light";
15 static constexpr char kPlatformBrightnessDark[] = "dark";
16
17 struct _FlSettingsChannel {
18 GObject parent_instance;
19
20 FlBasicMessageChannel* channel;
21 };
22
23 G_DEFINE_TYPE(FlSettingsChannel, fl_settings_channel, G_TYPE_OBJECT)
24
25 static void fl_settings_channel_dispose(GObject* object) {
26 FlSettingsChannel* self = FL_SETTINGS_CHANNEL(object);
27
28 g_clear_object(&self->channel);
29
30 G_OBJECT_CLASS(fl_settings_channel_parent_class)->dispose(object);
31 }
32
33 static void fl_settings_channel_class_init(FlSettingsChannelClass* klass) {
34 G_OBJECT_CLASS(klass)->dispose = fl_settings_channel_dispose;
35 }
36
37 static void fl_settings_channel_init(FlSettingsChannel* self) {}
38
39 FlSettingsChannel* fl_settings_channel_new(FlBinaryMessenger* messenger) {
40 FlSettingsChannel* self = FL_SETTINGS_CHANNEL(
41 g_object_new(fl_settings_channel_get_type(), nullptr));
42
43 g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new();
44 self->channel = fl_basic_message_channel_new(messenger, kChannelName,
45 FL_MESSAGE_CODEC(codec));
46
47 return self;
48 }
49
50 void fl_settings_channel_send(
51 FlSettingsChannel* self,
52 double text_scale_factor,
53 gboolean always_use_24_hour_format,
54 FlSettingsChannelPlatformBrightness platform_brightness) {
55 g_return_if_fail(FL_IS_SETTINGS_CHANNEL(self));
56
57 g_autoptr(FlValue) message = fl_value_new_map();
58 fl_value_set_string_take(message, kTextScaleFactorKey,
59 fl_value_new_float(text_scale_factor));
60 fl_value_set_string_take(message, kAlwaysUse24HourFormatKey,
61 fl_value_new_bool(always_use_24_hour_format));
62 const gchar* platform_brightness_string;
63 switch (platform_brightness) {
64 case FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT:
65 platform_brightness_string = kPlatformBrightnessLight;
66 break;
67 case FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK:
68 platform_brightness_string = kPlatformBrightnessDark;
69 break;
70 default:
71 g_assert_not_reached();
72 }
73 fl_value_set_string_take(message, kPlatformBrightnessKey,
74 fl_value_new_string(platform_brightness_string));
75 fl_basic_message_channel_send(self->channel, message, nullptr, nullptr,
76 nullptr);
77 }
fl_basic_message_channel_new
G_MODULE_EXPORT FlBasicMessageChannel * fl_basic_message_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMessageCodec *codec)
Definition: fl_basic_message_channel.cc:154
fl_basic_message_channel_send
G_MODULE_EXPORT void fl_basic_message_channel_send(FlBasicMessageChannel *self, FlValue *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_basic_message_channel.cc:226
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
fl_basic_message_channel.h
g_autoptr
g_autoptr(GMutexLocker) locker
fl_json_message_codec_new
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
Definition: fl_json_message_codec.cc:306
fl_json_message_codec.h
fl_settings_channel_class_init
static void fl_settings_channel_class_init(FlSettingsChannelClass *klass)
Definition: fl_settings_channel.cc:33
kTextScaleFactorKey
static constexpr char kTextScaleFactorKey[]
Definition: fl_settings_channel.cc:11
fl_settings_channel_send
void fl_settings_channel_send(FlSettingsChannel *self, double text_scale_factor, gboolean always_use_24_hour_format, FlSettingsChannelPlatformBrightness platform_brightness)
Definition: fl_settings_channel.cc:50
fl_settings_channel_dispose
static void fl_settings_channel_dispose(GObject *object)
Definition: fl_settings_channel.cc:25
fl_settings_channel_init
static void fl_settings_channel_init(FlSettingsChannel *self)
Definition: fl_settings_channel.cc:37
kPlatformBrightnessKey
static constexpr char kPlatformBrightnessKey[]
Definition: fl_settings_channel.cc:13
kPlatformBrightnessLight
static constexpr char kPlatformBrightnessLight[]
Definition: fl_settings_channel.cc:14
kChannelName
static constexpr char kChannelName[]
Definition: fl_settings_channel.cc:10
kAlwaysUse24HourFormatKey
static constexpr char kAlwaysUse24HourFormatKey[]
Definition: fl_settings_channel.cc:12
fl_settings_channel_new
FlSettingsChannel * fl_settings_channel_new(FlBinaryMessenger *messenger)
Definition: fl_settings_channel.cc:39
kPlatformBrightnessDark
static constexpr char kPlatformBrightnessDark[]
Definition: fl_settings_channel.cc:15
fl_settings_channel.h
FlSettingsChannelPlatformBrightness
FlSettingsChannelPlatformBrightness
Definition: fl_settings_channel.h:12
FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK
@ FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK
Definition: fl_settings_channel.h:14
FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT
@ FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT
Definition: fl_settings_channel.h:13
fl_value_new_float
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
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
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
_FlSettingsChannel
Definition: fl_settings_channel.cc:17
_FlSettingsChannel::parent_instance
GObject parent_instance
Definition: fl_settings_channel.cc:18
_FlSettingsChannel::channel
FlBasicMessageChannel * channel
Definition: fl_settings_channel.cc:20