mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-12 18:29:10 +08:00
windows/mac tray tooltip show controlled session count
* ubuntu 22.04 can't see tooltip Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
45b0e7dc01
commit
c254eebea2
12
src/ipc.rs
12
src/ipc.rs
@ -234,6 +234,8 @@ pub enum Data {
|
||||
#[cfg(windows)]
|
||||
SyncWinCpuUsage(Option<f64>),
|
||||
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
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
102
src/tray.rs
102
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::<Data>();
|
||||
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<Data>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user