no duplidate trays
This commit is contained in:
parent
644da37a4f
commit
53431eb162
@ -123,7 +123,7 @@ pub fn is_server() -> bool {
|
||||
*IS_SERVER
|
||||
}
|
||||
|
||||
// Is server logic running.
|
||||
// Is server logic running.
|
||||
#[inline]
|
||||
pub fn is_server_running() -> bool {
|
||||
*SERVER_RUNNING.read().unwrap()
|
||||
@ -1053,3 +1053,36 @@ pub async fn get_next_nonkeyexchange_msg(
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn check_process(arg: &str, same_uid: bool) -> bool {
|
||||
use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
|
||||
let mut sys = System::new();
|
||||
sys.refresh_processes();
|
||||
let app = std::env::current_exe()
|
||||
.unwrap_or_default()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
if app.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let my_uid = sys
|
||||
.process((std::process::id() as usize).into())
|
||||
.map(|x| x.user_id())
|
||||
.unwrap_or_default();
|
||||
for (_, p) in sys.processes().iter() {
|
||||
if same_uid && p.user_id() != my_uid {
|
||||
continue;
|
||||
}
|
||||
if p.cmd().is_empty() || p.cmd()[0] != app {
|
||||
continue;
|
||||
}
|
||||
if arg.is_empty() {
|
||||
if p.cmd().len() == 1 {
|
||||
return true;
|
||||
}
|
||||
} else if p.cmd().len() > 1 && p.cmd()[1] == arg {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
@ -160,7 +160,9 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
return None;
|
||||
}
|
||||
} else if args[0] == "--tray" {
|
||||
crate::tray::start_tray();
|
||||
if !crate::check_process("--tray", true) {
|
||||
crate::tray::start_tray();
|
||||
}
|
||||
return None;
|
||||
} else if args[0] == "--service" {
|
||||
log::info!("start --service");
|
||||
|
@ -577,19 +577,10 @@ pub fn hide_dock() {
|
||||
}
|
||||
|
||||
fn check_main_window() -> bool {
|
||||
use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
|
||||
let mut sys = System::new();
|
||||
sys.refresh_processes();
|
||||
let app = format!("/Applications/{}.app", crate::get_app_name());
|
||||
let my_uid = sys
|
||||
.process((std::process::id() as usize).into())
|
||||
.map(|x| x.user_id())
|
||||
.unwrap_or_default();
|
||||
for (_, p) in sys.processes().iter() {
|
||||
if p.cmd().len() == 1 && p.user_id() == my_uid && p.cmd()[0].contains(&app) {
|
||||
return true;
|
||||
}
|
||||
if crate::check_process("", true) {
|
||||
return true;
|
||||
}
|
||||
let app = format!("/Applications/{}.app", crate::get_app_name());
|
||||
std::process::Command::new("open")
|
||||
.args(["-n", &app])
|
||||
.status()
|
||||
|
Loading…
x
Reference in New Issue
Block a user