From 62ae4aeac9368d9941389ddc5f7940da8c23c5c1 Mon Sep 17 00:00:00 2001 From: Mr-Update <37781396+Mr-Update@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:45:49 +0200 Subject: [PATCH 1/7] Update de.rs --- src/lang/de.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang/de.rs b/src/lang/de.rs index cc0ae6af9..c307281ee 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -543,6 +543,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("HSV Color", "HSV-Farbe"), ("Installation Successful!", "Installation erfolgreich!"), ("Installation failed!", "Installation fehlgeschlagen!"), - ("Reverse mouse wheel", ""), + ("Reverse mouse wheel", "Mausrad rückwärts drehen"), ].iter().cloned().collect(); } From 9129e82804b14adcefbb882648cbc8cedaeeaef3 Mon Sep 17 00:00:00 2001 From: Andrzej Rudnik Date: Mon, 11 Sep 2023 20:54:33 +0200 Subject: [PATCH 2/7] Update pl.rs --- src/lang/pl.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lang/pl.rs b/src/lang/pl.rs index d488f681d..cea9b69bd 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -528,21 +528,21 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Move tab to new window", "Przenieś zakładkę do nowego okna"), ("Can not be empty", "Nie może być puste"), ("Already exists", "Już istnieje"), - ("Change Password", ""), - ("Refresh Password", ""), - ("ID", ""), - ("Grid View", ""), - ("List View", ""), - ("Select", ""), - ("Toggle Tags", ""), - ("pull_ab_failed_tip", ""), - ("push_ab_failed_tip", ""), - ("synced_peer_readded_tip", ""), - ("Change Color", ""), - ("Primary Color", ""), - ("HSV Color", ""), - ("Installation Successful!", ""), - ("Installation failed!", ""), - ("Reverse mouse wheel", ""), + ("Change Password", "Zmień hasło"), + ("Refresh Password", "Odśwież hasło"), + ("ID", "ID"), + ("Grid View", "Widok siatki"), + ("List View", "Widok listy"), + ("Select", "Wybierz"), + ("Toggle Tags", "Przełącz tagi"), + ("pull_ab_failed_tip", "Aktualizacja książki adresowej nie powiodła się"), + ("push_ab_failed_tip", "Nie udało się zsynchronizować książki adresowej z serwerem"), + ("synced_peer_readded_tip", "Urządzenia, które były obecne w ostatnich sesjach, zostaną ponownie dodane do książki adresowej"), + ("Change Color", "Zmień kolor"), + ("Primary Color", "Kolor podstawowy"), + ("HSV Color", "Kolor HSV"), + ("Installation Successful!", "Instalacja zakończona!"), + ("Installation failed!", "Instalacja nie powiodła się"), + ("Reverse mouse wheel", "Odwróć rolkę myszki"), ].iter().cloned().collect(); } From e3d34c46c79bd21012c092011833d9859662c147 Mon Sep 17 00:00:00 2001 From: Ibnul Mutaki Date: Tue, 12 Sep 2023 13:08:19 +0700 Subject: [PATCH 3/7] update text indo --- src/lang/id.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lang/id.rs b/src/lang/id.rs index 5f802e44b..e85811772 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -541,8 +541,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Change Color", "Ganti warna"), ("Primary Color", "Warna utama"), ("HSV Color", "Warna HSV"), - ("Installation Successful!", ""), - ("Installation failed!", ""), - ("Reverse mouse wheel", ""), + ("Installation Successful!", "Instalasi berhasil!"), + ("Installation failed!", "Instalasi gagal!"), + ("Reverse mouse wheel", "Balikkan arah scroll mouse!"), ].iter().cloned().collect(); } From 45b0e7dc0186022ec28076cee9dbadf65e3d5948 Mon Sep 17 00:00:00 2001 From: 21pages Date: Mon, 11 Sep 2023 19:51:58 +0800 Subject: [PATCH 4/7] translate placeholders ui:{value}, translation: {} Signed-off-by: 21pages --- src/lang.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/lang.rs b/src/lang.rs index 75c067e14..fb10230c4 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,5 +1,7 @@ +use hbb_common::regex::Regex; use std::ops::Deref; +mod ar; mod ca; mod cn; mod cs; @@ -17,6 +19,7 @@ mod it; mod ja; mod ko; mod kz; +mod lt; mod nl; mod pl; mod ptbr; @@ -32,8 +35,6 @@ mod tr; mod tw; mod ua; mod vn; -mod lt; -mod ar; pub const LANGS: &[(&str, &str)] = &[ ("en", "English"), @@ -137,16 +138,67 @@ pub fn translate_locale(name: String, locale: &str) -> String { "ar" => ar::T.deref(), _ => en::T.deref(), }; + let (name, placeholder_value) = extract_placeholder(&name); + let replace = |s: &&str| { + let mut s = s.to_string(); + if let Some(value) = placeholder_value.as_ref() { + s = s.replace("{}", &value); + } + s + }; if let Some(v) = m.get(&name as &str) { if v.is_empty() { if lang != "en" { if let Some(v) = en::T.get(&name as &str) { - return v.to_string(); + return replace(v); } } } else { - return v.to_string(); + return replace(v); } } - name + replace(&name.as_str()) +} + +// Matching pattern is {} +// Write {value} in the UI and {} in the translation file +// +// Example: +// Write in the UI: translate("There are {24} hours in a day") +// Write in the translation file: ("There are {} hours in a day", "{} hours make up a day") +fn extract_placeholder(input: &str) -> (String, Option) { + if let Ok(re) = Regex::new(r#"\{(.*?)\}"#) { + if let Some(captures) = re.captures(input) { + if let Some(inner_match) = captures.get(1) { + let name = re.replace(input, "{}").to_string(); + let value = inner_match.as_str().to_string(); + return (name, Some(value)); + } + } + } + (input.to_string(), None) +} + +mod test { + #[test] + fn test_extract_placeholders() { + use super::extract_placeholder as f; + + assert_eq!(f(""), ("".to_string(), None)); + assert_eq!( + f("{3} sessions"), + ("{} sessions".to_string(), Some("3".to_string())) + ); + assert_eq!(f(" } { "), (" } { ".to_string(), None)); + // Allow empty value + assert_eq!( + f("{} sessions"), + ("{} sessions".to_string(), Some("".to_string())) + ); + // Match only the first one + assert_eq!( + f("{2} times {4} makes {8}"), + ("{} times {4} makes {8}".to_string(), Some("2".to_string())) + ); + } } From c254eebea233da2a0e3b16db33f6f5dca1a48824 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 9 Sep 2023 09:45:05 +0800 Subject: [PATCH 5/7] windows/mac tray tooltip show controlled session count * ubuntu 22.04 can't see tooltip Signed-off-by: 21pages --- src/ipc.rs | 12 +++++ src/lang/ar.rs | 1 + src/lang/ca.rs | 1 + src/lang/cn.rs | 1 + src/lang/cs.rs | 1 + src/lang/da.rs | 1 + src/lang/de.rs | 1 + src/lang/el.rs | 1 + src/lang/eo.rs | 1 + src/lang/es.rs | 1 + src/lang/fa.rs | 1 + src/lang/fr.rs | 1 + src/lang/hu.rs | 1 + src/lang/id.rs | 1 + src/lang/it.rs | 1 + src/lang/ja.rs | 1 + src/lang/ko.rs | 1 + src/lang/kz.rs | 1 + src/lang/lt.rs | 1 + src/lang/nl.rs | 1 + src/lang/pl.rs | 1 + src/lang/pt_PT.rs | 1 + src/lang/ptbr.rs | 1 + src/lang/ro.rs | 1 + src/lang/ru.rs | 1 + src/lang/sk.rs | 1 + src/lang/sl.rs | 1 + src/lang/sq.rs | 1 + src/lang/sr.rs | 1 + src/lang/sv.rs | 1 + src/lang/template.rs | 1 + src/lang/th.rs | 1 + src/lang/tr.rs | 1 + src/lang/tw.rs | 1 + src/lang/ua.rs | 1 + src/lang/vn.rs | 1 + src/tray.rs | 102 +++++++++++++++++++++++++++++++++++++------ 37 files changed, 135 insertions(+), 14 deletions(-) diff --git a/src/ipc.rs b/src/ipc.rs index 1cbd994bb..db41b8649 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -234,6 +234,8 @@ pub enum Data { #[cfg(windows)] SyncWinCpuUsage(Option), FileTransferLog(String), + #[cfg(any(windows, target_os = "macos"))] + ControlledSessionCount(usize), } #[tokio::main(flavor = "current_thread")] @@ -482,6 +484,16 @@ async fn handle(data: Data, stream: &mut Connection) { #[cfg(all(feature = "flutter", feature = "plugin_framework"))] #[cfg(not(any(target_os = "android", target_os = "ios")))] Data::Plugin(plugin) => crate::plugin::ipc::handle_plugin(plugin, stream).await, + #[cfg(any(windows, target_os = "macos"))] + Data::ControlledSessionCount(_) => { + allow_err!( + stream + .send(&Data::ControlledSessionCount( + crate::Connection::alive_conns().len() + )) + .await + ); + } _ => {} } } diff --git a/src/lang/ar.rs b/src/lang/ar.rs index 4a1f8486c..33782738f 100644 --- a/src/lang/ar.rs +++ b/src/lang/ar.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ca.rs b/src/lang/ca.rs index 55e01fefa..65c4ea9ce 100644 --- a/src/lang/ca.rs +++ b/src/lang/ca.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/cn.rs b/src/lang/cn.rs index 5fdfa460e..006edd270 100644 --- a/src/lang/cn.rs +++ b/src/lang/cn.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "安装成功!"), ("Installation failed!", "安装失败!"), ("Reverse mouse wheel", "鼠标滚轮反向"), + ("{} sessions", "{}个会话"), ].iter().cloned().collect(); } diff --git a/src/lang/cs.rs b/src/lang/cs.rs index 37473e0b6..45e224d81 100644 --- a/src/lang/cs.rs +++ b/src/lang/cs.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/da.rs b/src/lang/da.rs index 9a9ecdfe1..889f82634 100644 --- a/src/lang/da.rs +++ b/src/lang/da.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/de.rs b/src/lang/de.rs index c307281ee..9185f3288 100644 --- a/src/lang/de.rs +++ b/src/lang/de.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Installation erfolgreich!"), ("Installation failed!", "Installation fehlgeschlagen!"), ("Reverse mouse wheel", "Mausrad rückwärts drehen"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/el.rs b/src/lang/el.rs index d2ae3eb5c..3440486f7 100644 --- a/src/lang/el.rs +++ b/src/lang/el.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/eo.rs b/src/lang/eo.rs index 90144c694..5a8c4da1f 100644 --- a/src/lang/eo.rs +++ b/src/lang/eo.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/es.rs b/src/lang/es.rs index 4589844c2..484d6fe5b 100644 --- a/src/lang/es.rs +++ b/src/lang/es.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Instalación exitosa"), ("Installation failed!", "La instalación ha fallado"), ("Reverse mouse wheel", "Invertir rueda del ratón"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fa.rs b/src/lang/fa.rs index ab1d7ab12..86dbbe013 100644 --- a/src/lang/fa.rs +++ b/src/lang/fa.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/fr.rs b/src/lang/fr.rs index 3ce8bca02..9dc310940 100644 --- a/src/lang/fr.rs +++ b/src/lang/fr.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/hu.rs b/src/lang/hu.rs index 50ca96792..4a24572cd 100644 --- a/src/lang/hu.rs +++ b/src/lang/hu.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/id.rs b/src/lang/id.rs index e85811772..d7c8aed82 100644 --- a/src/lang/id.rs +++ b/src/lang/id.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Instalasi berhasil!"), ("Installation failed!", "Instalasi gagal!"), ("Reverse mouse wheel", "Balikkan arah scroll mouse!"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/it.rs b/src/lang/it.rs index 9b708ca39..dc1d09020 100644 --- a/src/lang/it.rs +++ b/src/lang/it.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Installazione completata"), ("Installation failed!", "Installazione fallita"), ("Reverse mouse wheel", "Rotella mouse inversa"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ja.rs b/src/lang/ja.rs index 015ee7af3..1e2829bd4 100644 --- a/src/lang/ja.rs +++ b/src/lang/ja.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ko.rs b/src/lang/ko.rs index 2897ed5f8..a3c251e86 100644 --- a/src/lang/ko.rs +++ b/src/lang/ko.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/kz.rs b/src/lang/kz.rs index 5a0c14871..0b956d66c 100644 --- a/src/lang/kz.rs +++ b/src/lang/kz.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/lt.rs b/src/lang/lt.rs index 100e22955..c64554239 100644 --- a/src/lang/lt.rs +++ b/src/lang/lt.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/nl.rs b/src/lang/nl.rs index 7503831bf..d4038e2ed 100644 --- a/src/lang/nl.rs +++ b/src/lang/nl.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pl.rs b/src/lang/pl.rs index cea9b69bd..5a727cfa1 100644 --- a/src/lang/pl.rs +++ b/src/lang/pl.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Instalacja zakończona!"), ("Installation failed!", "Instalacja nie powiodła się"), ("Reverse mouse wheel", "Odwróć rolkę myszki"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/pt_PT.rs b/src/lang/pt_PT.rs index 91a85a3b1..7b31cc813 100644 --- a/src/lang/pt_PT.rs +++ b/src/lang/pt_PT.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ptbr.rs b/src/lang/ptbr.rs index 7ca81495d..c5134e9dd 100644 --- a/src/lang/ptbr.rs +++ b/src/lang/ptbr.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ro.rs b/src/lang/ro.rs index bcc13a0df..23fc8bf82 100644 --- a/src/lang/ro.rs +++ b/src/lang/ro.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ru.rs b/src/lang/ru.rs index eb9f8161b..d231d3ef0 100644 --- a/src/lang/ru.rs +++ b/src/lang/ru.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", "Установка выполнена успешно!"), ("Installation failed!", "Установка не выполнена!"), ("Reverse mouse wheel", "Реверсировать колесо мыши"), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sk.rs b/src/lang/sk.rs index 003b2cabc..16b33ee44 100644 --- a/src/lang/sk.rs +++ b/src/lang/sk.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sl.rs b/src/lang/sl.rs index 80b9aed1d..7cb0c677d 100755 --- a/src/lang/sl.rs +++ b/src/lang/sl.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sq.rs b/src/lang/sq.rs index fd2db0c83..028096c6d 100644 --- a/src/lang/sq.rs +++ b/src/lang/sq.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sr.rs b/src/lang/sr.rs index 9092d453d..55ae4022c 100644 --- a/src/lang/sr.rs +++ b/src/lang/sr.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/sv.rs b/src/lang/sv.rs index ed8c3697a..ca4adea6b 100644 --- a/src/lang/sv.rs +++ b/src/lang/sv.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/template.rs b/src/lang/template.rs index 6b4d176d2..48a710e5d 100644 --- a/src/lang/template.rs +++ b/src/lang/template.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/th.rs b/src/lang/th.rs index a5e193a00..abe318b18 100644 --- a/src/lang/th.rs +++ b/src/lang/th.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tr.rs b/src/lang/tr.rs index 0fe1369df..b38c3e497 100644 --- a/src/lang/tr.rs +++ b/src/lang/tr.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/tw.rs b/src/lang/tw.rs index 5e533e9bc..22cd296c9 100644 --- a/src/lang/tw.rs +++ b/src/lang/tw.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/ua.rs b/src/lang/ua.rs index 7cc885f56..dba9b625b 100644 --- a/src/lang/ua.rs +++ b/src/lang/ua.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/lang/vn.rs b/src/lang/vn.rs index e65fab66b..6a6b8366b 100644 --- a/src/lang/vn.rs +++ b/src/lang/vn.rs @@ -544,5 +544,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("Installation Successful!", ""), ("Installation failed!", ""), ("Reverse mouse wheel", ""), + ("{} sessions", ""), ].iter().cloned().collect(); } diff --git a/src/tray.rs b/src/tray.rs index 2f4aae93a..8dac19bab 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -1,5 +1,11 @@ +use crate::{client::translate, ipc::Data}; +use hbb_common::{allow_err, log, tokio}; +use std::{ + sync::{Arc, Mutex}, + time::Duration, +}; + pub fn start_tray() { - use hbb_common::{allow_err, log}; allow_err!(make_tray()); } @@ -40,31 +46,44 @@ pub fn make_tray() -> hbb_common::ResultType<()> { let event_loop = EventLoopBuilder::new().build(); let tray_menu = Menu::new(); - let quit_i = MenuItem::new(crate::client::translate("Exit".to_owned()), true, None); - let open_i = MenuItem::new(crate::client::translate("Open".to_owned()), true, None); + let quit_i = MenuItem::new(translate("Exit".to_owned()), true, None); + let open_i = MenuItem::new(translate("Open".to_owned()), true, None); tray_menu.append_items(&[&open_i, &quit_i]); - - let _tray_icon = Some( - TrayIconBuilder::new() - .with_menu(Box::new(tray_menu)) - .with_tooltip(format!( + let tooltip = |count: usize| { + if count == 0 { + format!( "{} {}", crate::get_app_name(), - crate::lang::translate("Service is running".to_owned()) - )) + translate("Service is running".to_owned()), + ) + } else { + format!( + "{} - {}\n{}", + crate::get_app_name(), + translate("Ready".to_owned()), + translate("{".to_string() + &format!("{count}") + "} sessions"), + ) + } + }; + let tray_icon = Some( + TrayIconBuilder::new() + .with_menu(Box::new(tray_menu)) + .with_tooltip(tooltip(0)) .with_icon(icon) .build()?, ); + let tray_icon = Arc::new(Mutex::new(tray_icon)); let menu_channel = MenuEvent::receiver(); let tray_channel = TrayEvent::receiver(); + #[cfg(not(target_os = "linux"))] + let (ipc_sender, ipc_receiver) = std::sync::mpsc::channel::(); let mut docker_hiden = false; let open_func = move || { - if cfg!(not(feature = "flutter")) - { - crate::run_me::<&str>(vec![]).ok(); - return; + if cfg!(not(feature = "flutter")) { + crate::run_me::<&str>(vec![]).ok(); + return; } #[cfg(target_os = "macos")] crate::platform::macos::handle_application_should_open_untitled_file(); @@ -89,6 +108,11 @@ pub fn make_tray() -> hbb_common::ResultType<()> { } }; + // ubuntu 22.04 can't see tooltip + #[cfg(not(target_os = "linux"))] + std::thread::spawn(move || { + start_query_session_count(ipc_sender.clone()); + }); event_loop.run(move |_event, _, control_flow| { if !docker_hiden { #[cfg(target_os = "macos")] @@ -121,5 +145,55 @@ pub fn make_tray() -> hbb_common::ResultType<()> { open_func(); } } + + #[cfg(not(target_os = "linux"))] + if let Ok(data) = ipc_receiver.try_recv() { + match data { + Data::ControlledSessionCount(count) => { + tray_icon + .lock() + .unwrap() + .as_mut() + .map(|t| t.set_tooltip(Some(tooltip(count)))); + } + _ => {} + } + } }); } + +#[cfg(not(target_os = "linux"))] +#[tokio::main(flavor = "current_thread")] +async fn start_query_session_count(sender: std::sync::mpsc::Sender) { + let mut last_count = 0; + loop { + if let Ok(mut c) = crate::ipc::connect(1000, "").await { + let mut timer = tokio::time::interval(Duration::from_secs(1)); + loop { + tokio::select! { + res = c.next() => { + match res { + Err(err) => { + log::error!("ipc connection closed: {}", err); + break; + } + + Ok(Some(Data::ControlledSessionCount(count))) => { + if count != last_count { + last_count = count; + sender.send(Data::ControlledSessionCount(count)).ok(); + } + } + _ => {} + } + } + + _ = timer.tick() => { + c.send(&Data::ControlledSessionCount(0)).await.ok(); + } + } + } + } + hbb_common::sleep(1.).await; + } +} From db0ab2e4a9e226da23416d45ff64ca168ef58c47 Mon Sep 17 00:00:00 2001 From: 21pages Date: Mon, 11 Sep 2023 15:19:07 +0800 Subject: [PATCH 6/7] try start tray when a new controlled connection is established for windows flutter Signed-off-by: 21pages --- src/server/connection.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/connection.rs b/src/server/connection.rs index c9f07eb78..85db55136 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -1351,6 +1351,12 @@ impl Connection { log::error!("ipc to connection manager exit: {}", err); } }); + #[cfg(all(windows, feature = "flutter"))] + std::thread::spawn(|| { + if crate::is_server() && !crate::check_process("--tray", false) { + crate::platform::run_as_user(vec!["--tray"]).ok(); + } + }); } } From 55dbcb646b5baef799b11172ffc08d3c033fb988 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 9 Sep 2023 15:23:26 +0800 Subject: [PATCH 7/7] windows remove "--cm-no-ui", "--cm --hide" Signed-off-by: 21pages --- src/core_main.rs | 2 +- src/hbbs_http/sync.rs | 1 + src/server/connection.rs | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core_main.rs b/src/core_main.rs index 3fe1a1630..e7bb4d0f6 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -404,7 +404,7 @@ pub fn core_main() -> Option> { crate::ui_interface::start_option_status_sync(); } else if args[0] == "--cm-no-ui" { #[cfg(feature = "flutter")] - #[cfg(not(any(target_os = "android", target_os = "ios")))] + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows")))] crate::flutter::connection_manager::start_cm_no_ui(); return None; } else { diff --git a/src/hbbs_http/sync.rs b/src/hbbs_http/sync.rs index 9db6c1c93..e997a2794 100644 --- a/src/hbbs_http/sync.rs +++ b/src/hbbs_http/sync.rs @@ -157,6 +157,7 @@ fn handle_config_options(config_options: HashMap) { Config::set_options(options); } +#[allow(unused)] #[cfg(not(any(target_os = "ios")))] pub fn is_pro() -> bool { PRO.lock().unwrap().clone() diff --git a/src/server/connection.rs b/src/server/connection.rs index 85db55136..969eb47a1 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -2412,7 +2412,10 @@ async fn start_ipc( if let Ok(s) = crate::ipc::connect(1000, "_cm").await { stream = Some(s); } else { + #[allow(unused_mut)] + #[allow(unused_assignments)] let mut args = vec!["--cm"]; + #[cfg(not(windows))] if crate::hbbs_http::sync::is_pro() && password::hide_cm() { args.push("--hide"); }