This commit is contained in:
rustdesk 2023-06-06 01:47:02 +08:00
parent 77c9341ba5
commit 14541fd182

View File

@ -50,7 +50,8 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
let tray_menu = Menu::new();
let quit_i = MenuItem::new(crate::client::translate("Exit".to_owned()), true, None);
tray_menu.append_items(&[&quit_i]);
let open_i = MenuItem::new(crate::client::translate("Open".to_owned()), true, None);
tray_menu.append_items(&[&open_i, &quit_i]);
let _tray_icon = Some(
TrayIconBuilder::new()
@ -68,26 +69,7 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
let tray_channel = TrayEvent::receiver();
let mut docker_hiden = false;
event_loop.run(move |_event, _, control_flow| {
if !docker_hiden {
#[cfg(target_os = "macos")]
crate::platform::macos::hide_dock();
docker_hiden = true;
}
*control_flow = ControlFlow::Wait;
if let Ok(event) = menu_channel.try_recv() {
if event.id == quit_i.id() {
#[cfg(target_os = "macos")]
crate::platform::macos::uninstall(false);
#[cfg(any(target_os = "linux", target_os = "windows"))]
crate::platform::uninstall_service(false).ok();
}
println!("{event:?}");
}
if let Ok(event) = tray_channel.try_recv() {
if event.event == ClickEvent::Double {
let open_func = move || {
#[cfg(target_os = "macos")]
crate::platform::macos::handle_application_should_open_untitled_file();
#[cfg(target_os = "windows")]
@ -101,6 +83,33 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
.spawn()
.ok();
}
};
event_loop.run(move |_event, _, control_flow| {
if !docker_hiden {
#[cfg(target_os = "macos")]
crate::platform::macos::hide_dock();
docker_hiden = true;
}
*control_flow = ControlFlow::WaitUntil(
std::time::Instant::now() + std::time::Duration::from_millis(100),
);
if let Ok(event) = menu_channel.try_recv() {
if event.id == quit_i.id() {
#[cfg(target_os = "macos")]
crate::platform::macos::uninstall(false);
#[cfg(any(target_os = "linux", target_os = "windows"))]
crate::platform::uninstall_service(false).ok();
} else if event.id == open_i.id() {
open_func();
}
}
if let Ok(event) = tray_channel.try_recv() {
#[cfg(target_os = "windows")]
if event.event == ClickEvent::Left {
open_func();
}
}
});