Skip to content

Commit

Permalink
Refactor SettingsChannel (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim authored Mar 3, 2022
1 parent ccb8911 commit 358b95b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 44 deletions.
1 change: 0 additions & 1 deletion shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ template("embedder") {
"channels/platform_channel_tizen.cc",
"channels/platform_view_channel.cc",
"channels/settings_channel.cc",
"channels/settings_channel_tizen.cc",
"channels/text_input_channel.cc",
"channels/window_channel.cc",
"external_texture_pixel_gl.cc",
Expand Down
5 changes: 5 additions & 0 deletions shell/platform/tizen/channels/encodable_value_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EMBEDDER_ENCODABLE_VALUE_HOLDER_H_
#define EMBEDDER_ENCODABLE_VALUE_HOLDER_H_

#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"

namespace flutter {
Expand All @@ -28,3 +31,5 @@ struct EncodableValueHolder {
};

} // namespace flutter

#endif // EMBEDDER_ENCODABLE_VALUE_HOLDER_H_
25 changes: 22 additions & 3 deletions shell/platform/tizen/channels/settings_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "settings_channel.h"

#include <system/system_settings.h>

#include "flutter/shell/platform/common/json_message_codec.h"

namespace flutter {
Expand All @@ -23,21 +25,38 @@ SettingsChannel::SettingsChannel(BinaryMessenger* messenger)
messenger,
kChannelName,
&JsonMessageCodec::GetInstance())) {
Init();
system_settings_set_changed_cb(
SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
[](system_settings_key_e key, void* user_data) -> void {
auto* self = reinterpret_cast<SettingsChannel*>(user_data);
self->SendSettingsEvent();
},
this);
SendSettingsEvent();
}

SettingsChannel::~SettingsChannel() {
Dispose();
system_settings_unset_changed_cb(
SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR);
}

void SettingsChannel::SendSettingsEvent() {
rapidjson::Document event(rapidjson::kObjectType);
auto& allocator = event.GetAllocator();
event.AddMember(kTextScaleFactorKey, 1.0, allocator);
event.AddMember(kPlatformBrightnessKey, "light", allocator);
event.AddMember(kAlwaysUse24HourFormatKey, Prefer24HourTime(), allocator);
event.AddMember(kPlatformBrightnessKey, "light", allocator);
channel_->Send(event);
}

bool SettingsChannel::Prefer24HourTime() {
bool value = false;
if (system_settings_get_value_bool(
SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &value) ==
SYSTEM_SETTINGS_ERROR_NONE) {
return value;
}
return false;
}

} // namespace flutter
4 changes: 1 addition & 3 deletions shell/platform/tizen/channels/settings_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ class SettingsChannel {
public:
explicit SettingsChannel(BinaryMessenger* messenger);
virtual ~SettingsChannel();
void SendSettingsEvent();

private:
void SendSettingsEvent();
bool Prefer24HourTime();
void Init();
void Dispose();

std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
};
Expand Down
37 changes: 0 additions & 37 deletions shell/platform/tizen/channels/settings_channel_tizen.cc

This file was deleted.

0 comments on commit 358b95b

Please sign in to comment.