diff --git a/Cargo.lock b/Cargo.lock index 29154d1cf..151d4a727 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,7 +1119,6 @@ dependencies = [ "objc2", "objc2-app-kit", "objc2-foundation", - "once_cell", "open", "parking_lot", "percent-encoding", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 277aa0ad2..5a82d69e8 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -66,7 +66,6 @@ dunce = "1.0.5" nanoid = "0.5" chrono = { workspace = true } boa_engine = "0.22.0" -once_cell = { version = "1.21.4", features = ["parking_lot"] } percent-encoding = "2.3.2" reqwest = { workspace = true } regex = { workspace = true } diff --git a/src-tauri/src/config/port.rs b/src-tauri/src/config/port.rs index 76fb3eaa1..c445fd5be 100644 --- a/src-tauri/src/config/port.rs +++ b/src-tauri/src/config/port.rs @@ -15,7 +15,6 @@ use crate::{ use anyhow::{Context as _, Result, anyhow, bail}; use clash_verge_draft::DraftTransaction; 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 _}; @@ -26,7 +25,7 @@ struct MixedPortFallback { current: u16, } -static PENDING_FALLBACK_NOTICE: Lazy>> = Lazy::new(|| Mutex::new(None)); +static PENDING_FALLBACK_NOTICE: Mutex> = Mutex::new(None); static STARTUP_CORE_BLOCK_REASON: Mutex> = Mutex::new(None); impl Config { diff --git a/src-tauri/src/core/auto_backup.rs b/src-tauri/src/core/auto_backup.rs index a8688c86f..c475cb711 100644 --- a/src-tauri/src/core/auto_backup.rs +++ b/src-tauri/src/core/auto_backup.rs @@ -7,12 +7,11 @@ use crate::{ use anyhow::Result; use chrono::Local; use clash_verge_logging::{Type, logging}; -use once_cell::sync::OnceCell; use parking_lot::RwLock; use std::{ path::PathBuf, sync::{ - Arc, + Arc, OnceLock, atomic::{AtomicBool, AtomicI64, Ordering}, }, time::{Duration, UNIX_EPOCH}, @@ -92,7 +91,7 @@ pub struct AutoBackupManager { impl AutoBackupManager { pub fn global() -> &'static Self { - static INSTANCE: OnceCell = OnceCell::new(); + static INSTANCE: OnceLock = OnceLock::new(); INSTANCE.get_or_init(|| { let (tx, _rx) = watch::channel(AutoBackupSettings::default()); Self { diff --git a/src-tauri/src/core/backup.rs b/src-tauri/src/core/backup.rs index 6a043954f..481fdcb83 100644 --- a/src-tauri/src/core/backup.rs +++ b/src-tauri/src/core/backup.rs @@ -4,7 +4,6 @@ use anyhow::Error; use arc_swap::{ArcSwap, ArcSwapOption}; use backon::{ConstantBuilder, Retryable as _}; use clash_verge_logging::{Type, logging}; -use once_cell::sync::OnceCell; use reqwest_dav::list_cmd::{ListEntity, ListFile, ListMultiStatus}; use smartstring::alias::String; use std::{ @@ -12,7 +11,7 @@ use std::{ env::{consts::OS, temp_dir}, io::Write as _, path::PathBuf, - sync::Arc, + sync::{Arc, OnceLock}, time::Duration, }; use tokio::{fs, time::timeout}; @@ -58,7 +57,7 @@ pub struct WebDavClient { impl WebDavClient { pub fn global() -> &'static Self { - static WEBDAV_CLIENT: OnceCell = OnceCell::new(); + static WEBDAV_CLIENT: OnceLock = OnceLock::new(); WEBDAV_CLIENT.get_or_init(|| Self { config: ArcSwapOption::new(None), clients: ArcSwap::new(Arc::new(HashMap::new())), diff --git a/src-tauri/src/core/manager/mod.rs b/src-tauri/src/core/manager/mod.rs index 997a20f47..b9ea77b04 100644 --- a/src-tauri/src/core/manager/mod.rs +++ b/src-tauri/src/core/manager/mod.rs @@ -6,11 +6,10 @@ mod state; use anyhow::Result; use arc_swap::{ArcSwap, ArcSwapOption}; use clash_verge_logging::{LogRing, Type, logging}; -use once_cell::sync::Lazy; use std::{ fmt, sync::{ - Arc, + Arc, LazyLock, atomic::{AtomicBool, AtomicU64, Ordering}, }, time::Instant, @@ -22,7 +21,7 @@ use crate::singleton; #[cfg(target_os = "windows")] use std::os::windows::io::OwnedHandle; -pub(crate) static CLASH_LOGGER: Lazy> = Lazy::new(|| Arc::new(LogRing::new())); +pub(crate) static CLASH_LOGGER: LazyLock> = LazyLock::new(|| Arc::new(LogRing::new())); tokio::task_local! { static PROFILE_SELECTIONS_PENDING_COMMIT: bool; diff --git a/src-tauri/src/core/notify/notification.rs b/src-tauri/src/core/notify/notification.rs index cc3c5947c..95eaa13da 100644 --- a/src-tauri/src/core/notify/notification.rs +++ b/src-tauri/src/core/notify/notification.rs @@ -1,10 +1,10 @@ use super::NoticeStatus; use clash_verge_logging::{Type, logging}; -use once_cell::sync::Lazy; use parking_lot::Mutex; use serde_json::json; use smartstring::alias::String; use std::sync::Arc; +use std::sync::LazyLock; use std::{collections::HashMap, future::Future}; use tauri::{AppHandle, Emitter as _, Manager as _, WebviewWindow}; @@ -238,7 +238,7 @@ pub fn what_was_asked() -> FailedOperation { .unwrap_or(FailedOperation::SystemProxyRestore) } -static PENDING_FAILURES: Lazy = Lazy::new(FailureTable::default); +static PENDING_FAILURES: LazyLock = LazyLock::new(FailureTable::default); /// A removal has a revision too, so a delayed read cannot restore a resolved failure. #[derive(Debug, Default, Clone, serde::Serialize)] @@ -262,7 +262,7 @@ impl SidecarFailureSnapshot { } } -static SIDECAR_FAILURE: Lazy> = Lazy::new(Mutex::default); +static SIDECAR_FAILURE: LazyLock> = LazyLock::new(Mutex::default); pub fn sidecar_failure_snapshot() -> SidecarFailureSnapshot { SIDECAR_FAILURE.lock().clone() diff --git a/src-tauri/src/core/runstate/mod.rs b/src-tauri/src/core/runstate/mod.rs index 26f85aebc..9aa2291a5 100644 --- a/src-tauri/src/core/runstate/mod.rs +++ b/src-tauri/src/core/runstate/mod.rs @@ -10,7 +10,7 @@ mod probe; use std::{ sync::{ - Arc, + Arc, LazyLock, atomic::{AtomicBool, Ordering}, }, time::Duration, @@ -19,7 +19,6 @@ use std::{ use anyhow::{Context as _, Result, bail}; use arc_swap::ArcSwap; use clash_verge_logging::{Type, logging}; -use once_cell::sync::Lazy; use parking_lot::Mutex; use tokio::sync::Notify; @@ -35,7 +34,7 @@ use health::StoredService; use probe::{CurrentServiceProbe, classify_service_health, probe_outcome}; /// The process-wide Run State, observing the real machine. -pub static RUN_STATE: Lazy> = Lazy::new(|| RunStateStore::new(RealEnv)); +pub static RUN_STATE: LazyLock> = LazyLock::new(|| RunStateStore::new(RealEnv)); /// Distinguishes silence from a reply that updated Service health with a rejection. #[derive(Debug)] diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 1350407ef..5d69f844c 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -26,7 +26,6 @@ use clash_verge_service_ipc::{ RuntimeBundle, RuntimeFileOutcome, RuntimeFileRequest, ServiceErrorCode, ServiceStatusSnapshot, StageRuntimeOutcome, StartClashRequest, WriterConfig, }; -use once_cell::sync::Lazy; use parking_lot::Mutex; use std::{ collections::HashMap, @@ -39,7 +38,7 @@ use std::{ }; static OWNER_MONITOR_GENERATION: AtomicU64 = AtomicU64::new(0); -static ACTIVE_SERVICE_SESSION: Lazy>> = Lazy::new(|| Mutex::new(None)); +static ACTIVE_SERVICE_SESSION: Mutex> = Mutex::new(None); static PENDING_SERVICE_FALLBACK_NOTICE: Mutex> = Mutex::new(None); static PENDING_SERVICE_REPAIR_NOTICE: AtomicBool = AtomicBool::new(false); static PENDING_SERVICE_OWNER_NOTICE: Mutex> = Mutex::new(None); diff --git a/src-tauri/src/feat/clash.rs b/src-tauri/src/feat/clash.rs index 057f493c0..0f90dffc4 100644 --- a/src-tauri/src/feat/clash.rs +++ b/src-tauri/src/feat/clash.rs @@ -9,13 +9,12 @@ use crate::{ }; use bytes::BytesMut; use clash_verge_logging::{Type, logging}; -use once_cell::sync::Lazy; use serde_yaml_ng::{Mapping, Value}; use smartstring::alias::String; -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; #[allow(clippy::expect_used)] -static TLS_CONFIG: Lazy> = Lazy::new(|| { +static TLS_CONFIG: LazyLock> = LazyLock::new(|| { let root_store = rustls::RootCertStore::from_iter(webpki_roots::TLS_SERVER_ROOTS.iter().cloned()); let config = rustls::ClientConfig::builder_with_provider(Arc::new(rustls::crypto::ring::default_provider())) .with_safe_default_protocol_versions() diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ff276b8e7..1df5b4582 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -18,13 +18,13 @@ use crate::{ }; use anyhow::Result; use clash_verge_logging::{Type, logging}; -use once_cell::sync::OnceCell; +use std::sync::OnceLock; use tauri::{AppHandle, Manager as _}; #[cfg(target_os = "macos")] use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_deep_link::DeepLinkExt as _; -pub static APP_HANDLE: OnceCell = OnceCell::new(); +pub static APP_HANDLE: OnceLock = OnceLock::new(); // Re-exported for src/bin/frontend-contract.rs; the wire contract stays owned // by core::notify. diff --git a/src-tauri/src/utils/server.rs b/src-tauri/src/utils/server.rs index 10efd9d59..9d05c92d4 100644 --- a/src-tauri/src/utils/server.rs +++ b/src-tauri/src/utils/server.rs @@ -7,12 +7,12 @@ use crate::{ }; use anyhow::{Context as _, Result, bail}; use clash_verge_logging::{Type, logging}; -use once_cell::sync::OnceCell; use parking_lot::Mutex; use reqwest::ClientBuilder; use serde::{Deserialize, Serialize}; use std::io::{Read as _, Write as _}; use std::path::{Path, PathBuf}; +use std::sync::OnceLock; use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; use tokio::sync::oneshot; @@ -33,9 +33,9 @@ struct InstanceRecord { token: String, } -static SHUTDOWN_SENDER: OnceCell>>> = OnceCell::new(); -static EMBEDDED_PORT: OnceCell = OnceCell::new(); -static INSTANCE_LOCK: OnceCell = OnceCell::new(); +static SHUTDOWN_SENDER: OnceLock>>> = OnceLock::new(); +static EMBEDDED_PORT: OnceLock = OnceLock::new(); +static INSTANCE_LOCK: OnceLock = OnceLock::new(); const PAC_INITIAL_AVAILABLE: bool = false; static PAC_AVAILABLE: AtomicBool = AtomicBool::new(PAC_INITIAL_AVAILABLE); static COMMANDS_READY: AtomicBool = AtomicBool::new(false); diff --git a/src-tauri/src/utils/singleton.rs b/src-tauri/src/utils/singleton.rs index 4dc94e478..e91c4a61e 100644 --- a/src-tauri/src/utils/singleton.rs +++ b/src-tauri/src/utils/singleton.rs @@ -1,4 +1,4 @@ -/// Implements `global()` using the supplied `OnceCell` static. +/// Implements `global()` using the supplied `OnceLock` static. #[macro_export] macro_rules! singleton { ($struct_name:ty, $instance_name:ident) => { diff --git a/src-tauri/src/utils/window_manager.rs b/src-tauri/src/utils/window_manager.rs index eab10d089..0c386a897 100644 --- a/src-tauri/src/utils/window_manager.rs +++ b/src-tauri/src/utils/window_manager.rs @@ -1,8 +1,8 @@ use crate::{core::handle, utils::resolve::window::build_new_window}; use clash_verge_limiter::Limiter; use clash_verge_logging::{Type, logging}; -use once_cell::sync::Lazy; use std::pin::Pin; +use std::sync::LazyLock; use std::time::Duration; use tauri::{Manager as _, WebviewWindow, Wry}; @@ -26,7 +26,7 @@ pub enum WindowState { } const WINDOW_OPERATION_DEBOUNCE_MS: u64 = 625; -static WINDOW_OPERATION_LIMITER: Lazy = Lazy::new(|| { +static WINDOW_OPERATION_LIMITER: LazyLock = LazyLock::new(|| { Limiter::new( Duration::from_millis(WINDOW_OPERATION_DEBOUNCE_MS), clash_verge_limiter::SystemClock,