sync language
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
b4e0101e3e
commit
d5d2a98572
@ -218,17 +218,6 @@ class MyTheme {
|
|||||||
return dark ? ThemeMode.dark : ThemeMode.light;
|
return dark ? ThemeMode.dark : ThemeMode.light;
|
||||||
}
|
}
|
||||||
|
|
||||||
static registerEventHandler() {
|
|
||||||
if (desktopType != DesktopType.main) {
|
|
||||||
platformFFI.registerEventHandler('theme', 'theme-$desktopType', (evt) {
|
|
||||||
String? dark = evt['dark'];
|
|
||||||
if (dark != null) {
|
|
||||||
changeTo(dark == 'true');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static ColorThemeExtension color(BuildContext context) {
|
static ColorThemeExtension color(BuildContext context) {
|
||||||
return Theme.of(context).extension<ColorThemeExtension>()!;
|
return Theme.of(context).extension<ColorThemeExtension>()!;
|
||||||
}
|
}
|
||||||
@ -238,14 +227,6 @@ class MyTheme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThemeModeNotifier {
|
|
||||||
final ValueNotifier<Brightness> brightness;
|
|
||||||
ThemeModeNotifier(this.brightness);
|
|
||||||
changeThemeBrightness({required Brightness brightness}) {
|
|
||||||
this.brightness.value = brightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isDarkTheme() {
|
bool isDarkTheme() {
|
||||||
return Get.isDarkMode;
|
return Get.isDarkMode;
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,7 @@ class _UserInterfaceState extends State<_UserInterface>
|
|||||||
onChanged: (key) async {
|
onChanged: (key) async {
|
||||||
await bind.mainSetLocalOption(key: "lang", value: key);
|
await bind.mainSetLocalOption(key: "lang", value: key);
|
||||||
Get.forceAppUpdate();
|
Get.forceAppUpdate();
|
||||||
|
bind.mainChangeLanguage(lang: key);
|
||||||
},
|
},
|
||||||
).marginOnly(left: _kContentHMargin);
|
).marginOnly(left: _kContentHMargin);
|
||||||
});
|
});
|
||||||
|
@ -79,7 +79,7 @@ Future<void> initEnv(String appType) async {
|
|||||||
await initGlobalFFI();
|
await initGlobalFFI();
|
||||||
// await Firebase.initializeApp();
|
// await Firebase.initializeApp();
|
||||||
refreshCurrentUser();
|
refreshCurrentUser();
|
||||||
MyTheme.registerEventHandler();
|
_registerEventHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runMainApp(bool startService) async {
|
void runMainApp(bool startService) async {
|
||||||
@ -270,3 +270,17 @@ _keepScaleBuilder() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_registerEventHandler() {
|
||||||
|
if (desktopType != DesktopType.main) {
|
||||||
|
platformFFI.registerEventHandler('theme', 'theme', (evt) {
|
||||||
|
String? dark = evt['dark'];
|
||||||
|
if (dark != null) {
|
||||||
|
MyTheme.changeTo(dark == 'true');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
platformFFI.registerEventHandler('language', 'language', (_) {
|
||||||
|
Get.forceAppUpdate();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -382,6 +382,10 @@ pub mod connection_manager {
|
|||||||
fn change_theme(&self, dark: bool) {
|
fn change_theme(&self, dark: bool) {
|
||||||
self.push_event("theme", vec![("dark", &dark.to_string())]);
|
self.push_event("theme", vec![("dark", &dark.to_string())]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn change_language(&self) {
|
||||||
|
self.push_event("language", vec![]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlutterHandler {
|
impl FlutterHandler {
|
||||||
|
@ -659,7 +659,7 @@ pub fn main_load_lan_peers() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_change_theme(dark: bool) {
|
fn main_broadcast_message(data: &HashMap<&str, &str>) {
|
||||||
let apps = vec![
|
let apps = vec![
|
||||||
flutter::APP_TYPE_DESKTOP_REMOTE,
|
flutter::APP_TYPE_DESKTOP_REMOTE,
|
||||||
flutter::APP_TYPE_DESKTOP_FILE_TRANSFER,
|
flutter::APP_TYPE_DESKTOP_FILE_TRANSFER,
|
||||||
@ -669,13 +669,24 @@ pub fn main_change_theme(dark: bool) {
|
|||||||
|
|
||||||
for app in apps {
|
for app in apps {
|
||||||
if let Some(s) = flutter::GLOBAL_EVENT_STREAM.read().unwrap().get(app) {
|
if let Some(s) = flutter::GLOBAL_EVENT_STREAM.read().unwrap().get(app) {
|
||||||
let data = HashMap::from([("name", "theme".to_owned()), ("dark", dark.to_string())]);
|
s.add(serde_json::ser::to_string(data).unwrap_or("".to_owned()));
|
||||||
s.add(serde_json::ser::to_string(&data).unwrap_or("".to_owned()));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main_change_theme(dark: bool) {
|
||||||
|
main_broadcast_message(&HashMap::from([
|
||||||
|
("name", "theme"),
|
||||||
|
("dark", &dark.to_string()),
|
||||||
|
]));
|
||||||
send_to_cm(&crate::ipc::Data::Theme(dark));
|
send_to_cm(&crate::ipc::Data::Theme(dark));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn main_change_language(lang: String) {
|
||||||
|
main_broadcast_message(&HashMap::from([("name", "language"), ("lang", &lang)]));
|
||||||
|
send_to_cm(&crate::ipc::Data::Language(lang));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn session_add_port_forward(
|
pub fn session_add_port_forward(
|
||||||
id: String,
|
id: String,
|
||||||
local_port: i32,
|
local_port: i32,
|
||||||
|
@ -183,6 +183,7 @@ pub enum Data {
|
|||||||
Mouse(DataMouse),
|
Mouse(DataMouse),
|
||||||
Control(DataControl),
|
Control(DataControl),
|
||||||
Theme(bool),
|
Theme(bool),
|
||||||
|
Language(String),
|
||||||
Empty,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@ impl InvokeUiCM for SciterHandler {
|
|||||||
fn change_theme(&self, _dark: bool) {
|
fn change_theme(&self, _dark: bool) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn change_language(&self) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SciterHandler {
|
impl SciterHandler {
|
||||||
|
@ -62,6 +62,8 @@ pub trait InvokeUiCM: Send + Clone + 'static + Sized {
|
|||||||
fn new_message(&self, id: i32, text: String);
|
fn new_message(&self, id: i32, text: String);
|
||||||
|
|
||||||
fn change_theme(&self, dark: bool);
|
fn change_theme(&self, dark: bool);
|
||||||
|
|
||||||
|
fn change_language(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
|
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
|
||||||
@ -200,6 +202,8 @@ pub enum ClipboardFileData {
|
|||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
||||||
|
use hbb_common::config::LocalConfig;
|
||||||
|
|
||||||
let (tx_file, _rx_file) = mpsc::unbounded_channel::<ClipboardFileData>();
|
let (tx_file, _rx_file) = mpsc::unbounded_channel::<ClipboardFileData>();
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let cm_clip = cm.clone();
|
let cm_clip = cm.clone();
|
||||||
@ -285,6 +289,10 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
|
|||||||
Data::Theme(dark) => {
|
Data::Theme(dark) => {
|
||||||
cm.change_theme(dark);
|
cm.change_theme(dark);
|
||||||
}
|
}
|
||||||
|
Data::Language(lang) => {
|
||||||
|
LocalConfig::set_option("lang".to_owned(), lang);
|
||||||
|
cm.change_language();
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user