mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refactor linux install/uninstall service as windows
This commit is contained in:
24
src/tray.rs
24
src/tray.rs
@@ -1,24 +1,15 @@
|
||||
/// Start a tray icon in Linux
|
||||
///
|
||||
/// [Block]
|
||||
/// This function will block current execution, show the tray icon and handle events.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn start_tray() {}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
pub fn start_tray() {
|
||||
use hbb_common::{allow_err, log};
|
||||
allow_err!(make_tray());
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
// https://github.com/tauri-apps/tray-icon/blob/dev/examples/tao.rs
|
||||
use hbb_common::anyhow::Context;
|
||||
use tao::event_loop::{ControlFlow, EventLoopBuilder};
|
||||
use tray_icon::{
|
||||
menu::{Menu, MenuEvent, MenuItem},
|
||||
ClickEvent, TrayEvent, TrayIconBuilder,
|
||||
TrayEvent, TrayIconBuilder,
|
||||
};
|
||||
let icon;
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -31,7 +22,7 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
_ => DARK,
|
||||
};
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
icon = include_bytes!("../res/tray-icon.ico");
|
||||
}
|
||||
@@ -83,6 +74,9 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
.spawn()
|
||||
.ok();
|
||||
}
|
||||
// xdg-open?
|
||||
#[cfg(target_os = "linux")]
|
||||
crate::run_me::<&str>(vec![]).ok();
|
||||
};
|
||||
|
||||
event_loop.run(move |_event, _, control_flow| {
|
||||
@@ -99,16 +93,16 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
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();
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
crate::platform::uninstall_service(false);
|
||||
} else if event.id == open_i.id() {
|
||||
open_func();
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(event) = tray_channel.try_recv() {
|
||||
if let Ok(_event) = tray_channel.try_recv() {
|
||||
#[cfg(target_os = "windows")]
|
||||
if event.event == ClickEvent::Left {
|
||||
if _event.event == tray_icon::ClickEvent::Left {
|
||||
open_func();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user