mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-18 18:02:08 +08:00
refactor(sync): initialize empty mutex state directly
This commit is contained in:
@@ -17,7 +17,7 @@ use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use parking_lot::Mutex;
|
||||
use serde_yaml_ng::Value;
|
||||
use std::{collections::HashSet, net::SocketAddr, str::FromStr as _, sync::LazyLock};
|
||||
use std::{collections::HashSet, net::SocketAddr, str::FromStr as _};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct MixedPortFallback {
|
||||
@@ -25,7 +25,7 @@ struct MixedPortFallback {
|
||||
current: u16,
|
||||
}
|
||||
|
||||
static PENDING_FALLBACK_NOTICE: LazyLock<Mutex<Option<MixedPortFallback>>> = LazyLock::new(|| Mutex::new(None));
|
||||
static PENDING_FALLBACK_NOTICE: Mutex<Option<MixedPortFallback>> = Mutex::new(None);
|
||||
static STARTUP_CORE_BLOCK_REASON: Mutex<Option<String>> = Mutex::new(None);
|
||||
|
||||
impl Config {
|
||||
|
||||
@@ -8,11 +8,10 @@ use anyhow::Result;
|
||||
use chrono::Local;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::OnceLock;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
Arc,
|
||||
Arc, OnceLock,
|
||||
atomic::{AtomicBool, AtomicI64, Ordering},
|
||||
},
|
||||
time::{Duration, UNIX_EPOCH},
|
||||
|
||||
@@ -6,13 +6,12 @@ use backon::{ConstantBuilder, Retryable as _};
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use reqwest_dav::list_cmd::{ListEntity, ListFile, ListMultiStatus};
|
||||
use smartstring::alias::String;
|
||||
use std::sync::OnceLock;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::{consts::OS, temp_dir},
|
||||
io::Write as _,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
sync::{Arc, OnceLock},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::{fs, time::timeout};
|
||||
|
||||
@@ -6,11 +6,10 @@ mod state;
|
||||
use anyhow::Result;
|
||||
use arc_swap::{ArcSwap, ArcSwapOption};
|
||||
use clash_verge_logging::{LogRing, Type, logging};
|
||||
use std::sync::LazyLock;
|
||||
use std::{
|
||||
fmt,
|
||||
sync::{
|
||||
Arc,
|
||||
Arc, LazyLock,
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
},
|
||||
time::Instant,
|
||||
|
||||
@@ -10,7 +10,7 @@ mod probe;
|
||||
|
||||
use std::{
|
||||
sync::{
|
||||
Arc,
|
||||
Arc, LazyLock,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
time::Duration,
|
||||
@@ -20,7 +20,6 @@ use anyhow::{Context as _, Result, bail};
|
||||
use arc_swap::ArcSwap;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::LazyLock;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -27,7 +27,6 @@ use clash_verge_service_ipc::{
|
||||
StageRuntimeOutcome, StartClashRequest, WriterConfig,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::LazyLock;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::current_exe,
|
||||
@@ -39,7 +38,7 @@ use std::{
|
||||
};
|
||||
|
||||
static OWNER_MONITOR_GENERATION: AtomicU64 = AtomicU64::new(0);
|
||||
static ACTIVE_SERVICE_SESSION: LazyLock<Mutex<Option<ActiveServiceSession>>> = LazyLock::new(|| Mutex::new(None));
|
||||
static ACTIVE_SERVICE_SESSION: Mutex<Option<ActiveServiceSession>> = Mutex::new(None);
|
||||
static PENDING_SERVICE_FALLBACK_NOTICE: Mutex<Option<String>> = Mutex::new(None);
|
||||
static PENDING_SERVICE_REPAIR_NOTICE: AtomicBool = AtomicBool::new(false);
|
||||
static PENDING_SERVICE_OWNER_NOTICE: Mutex<Option<String>> = Mutex::new(None);
|
||||
|
||||
@@ -11,8 +11,7 @@ use bytes::BytesMut;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use serde_yaml_ng::{Mapping, Value};
|
||||
use smartstring::alias::String;
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
#[allow(clippy::expect_used)]
|
||||
static TLS_CONFIG: LazyLock<Arc<rustls::ClientConfig>> = LazyLock::new(|| {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
use crate::config::IVerge;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
/// Variant order defines execution dependency order.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(super) enum Effect {
|
||||
RestartCore,
|
||||
ClashConfig,
|
||||
Autostart,
|
||||
Language,
|
||||
SystemProxy,
|
||||
TrayIcon,
|
||||
Hotkey,
|
||||
TrayMenu,
|
||||
TrayIcon,
|
||||
TrayTooltip,
|
||||
TrayClick,
|
||||
Lightweight,
|
||||
Language,
|
||||
LogLevel,
|
||||
LogFile,
|
||||
}
|
||||
|
||||
@@ -20,22 +20,6 @@ pub(super) enum Patch<'a> {
|
||||
Clash(&'a Mapping),
|
||||
}
|
||||
|
||||
const EFFECT_ORDER: &[Effect] = &[
|
||||
Effect::RestartCore,
|
||||
Effect::ClashConfig,
|
||||
Effect::Autostart,
|
||||
Effect::Language,
|
||||
Effect::SystemProxy,
|
||||
Effect::Hotkey,
|
||||
Effect::TrayMenu,
|
||||
Effect::TrayIcon,
|
||||
Effect::TrayTooltip,
|
||||
Effect::TrayClick,
|
||||
Effect::Lightweight,
|
||||
Effect::LogLevel,
|
||||
Effect::LogFile,
|
||||
];
|
||||
|
||||
async fn ensure_restart(manager: &CoreManager) -> Result<()> {
|
||||
Config::generate().await?;
|
||||
let previous = manager.current_core_readiness_generation();
|
||||
@@ -143,15 +127,13 @@ pub(super) async fn apply(config_write: &MutexGuard<'_, ()>, patch: Patch<'_>, e
|
||||
Patch::Clash(patch) => clash.edit_draft(|draft| draft.patch_config(patch)),
|
||||
}
|
||||
let result: Result<()> = async {
|
||||
for &effect in EFFECT_ORDER {
|
||||
if effects.contains(&effect) {
|
||||
let result = Box::pin(ensure_effect(effect, verge_patch, manager, &update)).await;
|
||||
if matches!(patch, Patch::Clash(_)) && matches!(effect, Effect::TrayMenu | Effect::TrayIcon) {
|
||||
// Tray failures must not reject an applied Clash mode change.
|
||||
logging_error!(Type::Tray, result);
|
||||
} else {
|
||||
result?;
|
||||
}
|
||||
for effect in effects.iter().copied() {
|
||||
let result = Box::pin(ensure_effect(effect, verge_patch, manager, &update)).await;
|
||||
if matches!(patch, Patch::Clash(_)) && matches!(effect, Effect::TrayMenu | Effect::TrayIcon) {
|
||||
// Tray failures must not reject an applied Clash mode change.
|
||||
logging_error!(Type::Tray, result);
|
||||
} else {
|
||||
result?;
|
||||
}
|
||||
}
|
||||
match patch {
|
||||
|
||||
Reference in New Issue
Block a user