sync language

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-09-08 08:52:56 +08:00
parent b4e0101e3e
commit d5d2a98572
8 changed files with 47 additions and 23 deletions

View File

@@ -382,6 +382,10 @@ pub mod connection_manager {
fn change_theme(&self, dark: bool) {
self.push_event("theme", vec![("dark", &dark.to_string())]);
}
fn change_language(&self) {
self.push_event("language", vec![]);
}
}
impl FlutterHandler {

View File

@@ -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![
flutter::APP_TYPE_DESKTOP_REMOTE,
flutter::APP_TYPE_DESKTOP_FILE_TRANSFER,
@@ -669,13 +669,24 @@ pub fn main_change_theme(dark: bool) {
for app in apps {
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));
}
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(
id: String,
local_port: i32,

View File

@@ -183,6 +183,7 @@ pub enum Data {
Mouse(DataMouse),
Control(DataControl),
Theme(bool),
Language(String),
Empty,
}

View File

@@ -51,6 +51,10 @@ impl InvokeUiCM for SciterHandler {
fn change_theme(&self, _dark: bool) {
// TODO
}
fn change_language(&self) {
// TODO
}
}
impl SciterHandler {

View File

@@ -62,6 +62,8 @@ pub trait InvokeUiCM: Send + Clone + 'static + Sized {
fn new_message(&self, id: i32, text: String);
fn change_theme(&self, dark: bool);
fn change_language(&self);
}
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
@@ -200,6 +202,8 @@ pub enum ClipboardFileData {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[tokio::main(flavor = "current_thread")]
pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
use hbb_common::config::LocalConfig;
let (tx_file, _rx_file) = mpsc::unbounded_channel::<ClipboardFileData>();
#[cfg(windows)]
let cm_clip = cm.clone();
@@ -285,6 +289,10 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
Data::Theme(dark) => {
cm.change_theme(dark);
}
Data::Language(lang) => {
LocalConfig::set_option("lang".to_owned(), lang);
cm.change_language();
}
_ => {
}