mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
refactor(port): store startup block reason in a OnceLock
This commit is contained in:
@@ -18,7 +18,7 @@ use clash_verge_logging::{Type, logging};
|
||||
use once_cell::sync::Lazy;
|
||||
use parking_lot::Mutex;
|
||||
use serde_yaml_ng::Value;
|
||||
use std::{collections::HashSet, net::SocketAddr, str::FromStr as _};
|
||||
use std::{collections::HashSet, net::SocketAddr, str::FromStr as _, sync::OnceLock};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct MixedPortFallback {
|
||||
@@ -27,7 +27,7 @@ struct MixedPortFallback {
|
||||
}
|
||||
|
||||
static PENDING_FALLBACK_NOTICE: Lazy<Mutex<Option<MixedPortFallback>>> = Lazy::new(|| Mutex::new(None));
|
||||
static STARTUP_CORE_BLOCK_REASON: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
|
||||
static STARTUP_CORE_BLOCK_REASON: OnceLock<String> = OnceLock::new();
|
||||
|
||||
impl Config {
|
||||
pub(crate) async fn resolve_startup_mixed_port() -> Result<bool> {
|
||||
@@ -142,12 +142,12 @@ impl Config {
|
||||
}
|
||||
|
||||
pub(crate) fn block_startup_core(error: &anyhow::Error) {
|
||||
*STARTUP_CORE_BLOCK_REASON.lock() = Some(error.to_string());
|
||||
let _ = STARTUP_CORE_BLOCK_REASON.set(error.to_string());
|
||||
report_fallback_error(error.to_string());
|
||||
}
|
||||
|
||||
pub(crate) fn startup_core_block_reason() -> Option<String> {
|
||||
STARTUP_CORE_BLOCK_REASON.lock().clone()
|
||||
STARTUP_CORE_BLOCK_REASON.get().cloned()
|
||||
}
|
||||
|
||||
pub(crate) fn notify_startup_mixed_port_fallback() {
|
||||
|
||||
Reference in New Issue
Block a user