-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related issue #2 Signed-off-by: Hidenori Matsubayashi <[email protected]>
- Loading branch information
1 parent
eb2687a
commit e1f3cac
Showing
8 changed files
with
153 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 Sony Corporation. All rights reserved. | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/platform/linux_embedded/plugins/settings_plugin.h" | ||
|
||
#include "flutter/shell/platform/common/json_message_codec.h" | ||
|
||
namespace flutter { | ||
|
||
namespace { | ||
constexpr char kChannelName[] = "flutter/settings"; | ||
|
||
constexpr char kAlwaysUse24HourFormat[] = "alwaysUse24HourFormat"; | ||
constexpr char kTextScaleFactor[] = "textScaleFactor"; | ||
constexpr char kPlatformBrightness[] = "platformBrightness"; | ||
|
||
constexpr char kPlatformBrightnessDark[] = "dark"; | ||
constexpr char kPlatformBrightnessLight[] = "light"; | ||
} // namespace | ||
|
||
SettingsPlugin::SettingsPlugin(BinaryMessenger* messenger, | ||
WindowBindingHandler* delegate) | ||
: channel_(std::make_unique<BasicMessageChannel<rapidjson::Document>>( | ||
messenger, | ||
kChannelName, | ||
&JsonMessageCodec::GetInstance())), | ||
delegate_(delegate) {} | ||
|
||
void SettingsPlugin::SendSettings() { | ||
rapidjson::Document settings(rapidjson::kObjectType); | ||
auto& allocator = settings.GetAllocator(); | ||
settings.AddMember(kAlwaysUse24HourFormat, GetAlwaysUse24HourFormat(), | ||
allocator); | ||
settings.AddMember(kTextScaleFactor, GetTextScaleFactor(), allocator); | ||
|
||
if (GetPreferredBrightness() == PlatformBrightness::kDark) { | ||
settings.AddMember(kPlatformBrightness, kPlatformBrightnessDark, allocator); | ||
} else { | ||
settings.AddMember(kPlatformBrightness, kPlatformBrightnessLight, | ||
allocator); | ||
} | ||
channel_->Send(settings); | ||
} | ||
|
||
bool SettingsPlugin::GetAlwaysUse24HourFormat() { | ||
// The current OS does not have 24 hour format factor. | ||
return true; | ||
} | ||
|
||
float SettingsPlugin::GetTextScaleFactor() { | ||
// The current OS does not have text scale factor. | ||
return 1.0; | ||
} | ||
|
||
SettingsPlugin::PlatformBrightness SettingsPlugin::GetPreferredBrightness() { | ||
// The current OS does not have brightness factor. | ||
return PlatformBrightness::kLight; | ||
} | ||
|
||
void SettingsPlugin::UpdateHighContrastMode(bool is_high_contrast) { | ||
is_high_contrast_ = is_high_contrast; | ||
SendSettings(); | ||
} | ||
|
||
} // namespace flutter |
56 changes: 56 additions & 0 deletions
56
src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2023 Sony Corporation. All rights reserved. | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ | ||
#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ | ||
|
||
#include <rapidjson/document.h> | ||
|
||
#include <memory> | ||
|
||
#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" | ||
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" | ||
#include "flutter/shell/platform/linux_embedded/window_binding_handler.h" | ||
|
||
namespace flutter { | ||
|
||
// Abstract settings plugin. | ||
// | ||
// Used to look up and notify Flutter of user-configured system settings. | ||
// These are typically set in the control panel. | ||
class SettingsPlugin { | ||
public: | ||
enum struct PlatformBrightness { kDark, kLight }; | ||
|
||
explicit SettingsPlugin(BinaryMessenger* messenger, | ||
WindowBindingHandler* delegate); | ||
~SettingsPlugin() = default; | ||
|
||
// Sends settings (e.g., platform brightness) to the engine. | ||
void SendSettings(); | ||
|
||
// Update the high contrast status of the system. | ||
void UpdateHighContrastMode(bool is_high_contrast); | ||
|
||
private: | ||
// Returns `true` if the user uses 24 hour time. | ||
bool GetAlwaysUse24HourFormat(); | ||
|
||
// Returns the user-preferred text scale factor. | ||
float GetTextScaleFactor(); | ||
|
||
// Returns the user-preferred brightness. | ||
PlatformBrightness GetPreferredBrightness(); | ||
|
||
bool is_high_contrast_ = false; | ||
|
||
private: | ||
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_; | ||
WindowBindingHandler* delegate_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters