fixed an issue with opening a window via a shortcut when the application is already active

This commit is contained in:
coolcoala
2025-08-03 12:50:16 +03:00
parent b7d7e1a1af
commit 2c485b5efb
2 changed files with 9 additions and 56 deletions

View File

@@ -7,8 +7,7 @@ use crate::{
process::AsyncHandler,
utils::logging::Type,
};
use anyhow::{bail, Result};
use port_scanner::local_port_available;
use anyhow::Result;
use std::convert::Infallible;
use warp::Filter;
@@ -17,32 +16,6 @@ struct QueryParam {
param: String,
}
/// check whether there is already exists
pub async fn check_singleton() -> Result<()> {
let port = IVerge::get_singleton_port();
if !local_port_available(port) {
let argvs: Vec<String> = std::env::args().collect();
if argvs.len() > 1 {
#[cfg(not(target_os = "macos"))]
{
let param = argvs[1].as_str();
if param.starts_with("clash:") {
let _ = reqwest::get(format!(
"http://127.0.0.1:{port}/commands/scheme?param={param}"
))
.await;
}
}
} else {
let _ = reqwest::get(format!("http://127.0.0.1:{port}/commands/visible")).await;
}
log::error!("failed to setup singleton listen server");
bail!("app exists");
} else {
Ok(())
}
}
/// The embed server only be used to implement singleton process
/// maybe it can be used as pac server later
pub fn embed_server() {