From 6d0039b104c3e35c52839500200d326a9dd9d9dc Mon Sep 17 00:00:00 2001 From: Kingtous Date: Sat, 19 Nov 2022 20:06:17 +0800 Subject: [PATCH] opt: stop show tray icon in root mode --- src/core_main.rs | 10 ++++++++-- src/tray.rs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index 1f13172dd..13a2ef91c 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -188,8 +188,14 @@ pub fn core_main() -> Option> { #[cfg(target_os = "linux")] { let handler = std::thread::spawn(move || crate::start_server(true)); - crate::tray::start_tray(); - // revent server exit when encountering errors from tray + // Show the tray in linux only when current user is a normal user + // [Note] + // As for GNOME, the tray cannot be shown in user's status bar. + // As for KDE, the tray can be shown without user's theme. + if !crate::platform::is_root() { + crate::tray::start_tray(); + } + // prevent server exit when encountering errors from tray hbb_common::allow_err!(handler.join()); } } else if args[0] == "--import-config" { diff --git a/src/tray.rs b/src/tray.rs index 5064d96dc..3658739a4 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -150,6 +150,13 @@ fn get_default_app_indicator() -> Option { match std::fs::File::create(icon_path.clone()) { Ok(mut f) => { f.write_all(icon).unwrap(); + // set .png icon file to be writable + // this ensures successful file rewrite when switching between x11 and wayland. + let mut perm = f.metadata().unwrap().permissions(); + if perm.readonly() { + perm.set_readonly(false); + f.set_permissions(perm).unwrap(); + } } Err(err) => { error!("Error when writing icon to {:?}: {}", icon_path, err);