diff --git a/Cargo.lock b/Cargo.lock index 4ba9821ac..f7bbe10de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1114,7 +1114,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 35aefdadc..d64b8931a 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 6b6e8f7b1..166fade11 100644 --- a/src-tauri/src/config/port.rs +++ b/src-tauri/src/config/port.rs @@ -15,10 +15,14 @@ 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 _, sync::OnceLock}; +use std::{ + collections::HashSet, + net::SocketAddr, + str::FromStr as _, + sync::{LazyLock, OnceLock}, +}; #[derive(Clone, Copy)] struct MixedPortFallback { @@ -26,7 +30,7 @@ struct MixedPortFallback { current: u16, } -static PENDING_FALLBACK_NOTICE: Lazy>> = Lazy::new(|| Mutex::new(None)); +static PENDING_FALLBACK_NOTICE: LazyLock>> = LazyLock::new(|| Mutex::new(None)); static STARTUP_CORE_BLOCK_REASON: OnceLock = OnceLock::new(); impl Config { diff --git a/src-tauri/src/core/auto_backup.rs b/src-tauri/src/core/auto_backup.rs index a8688c86f..ee8cf9a1f 100644 --- a/src-tauri/src/core/auto_backup.rs +++ b/src-tauri/src/core/auto_backup.rs @@ -7,8 +7,8 @@ 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::sync::OnceLock; use std::{ path::PathBuf, sync::{ @@ -92,7 +92,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..b7348217e 100644 --- a/src-tauri/src/core/backup.rs +++ b/src-tauri/src/core/backup.rs @@ -4,9 +4,9 @@ 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::sync::OnceLock; use std::{ collections::HashMap, env::{consts::OS, temp_dir}, @@ -58,7 +58,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 26164816e..002df84c1 100644 --- a/src-tauri/src/core/manager/mod.rs +++ b/src-tauri/src/core/manager/mod.rs @@ -6,7 +6,7 @@ mod state; use anyhow::Result; use arc_swap::{ArcSwap, ArcSwapOption}; use clash_verge_logging::{LogRing, Type, logging}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::{ fmt, sync::{ @@ -22,7 +22,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 0cdf12cdb..707c674cb 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); pub fn record_failure(operation: FailedOperation, code: &str, detail: impl Into) { PENDING_FAILURES.record(operation, code, detail.into()); diff --git a/src-tauri/src/core/runstate/mod.rs b/src-tauri/src/core/runstate/mod.rs index e906256e5..ca7a2a738 100644 --- a/src-tauri/src/core/runstate/mod.rs +++ b/src-tauri/src/core/runstate/mod.rs @@ -19,8 +19,8 @@ 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 std::sync::LazyLock; use tokio::sync::Notify; #[cfg(test)] @@ -35,7 +35,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 fa1bc012b..52b2c3c55 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -26,8 +26,8 @@ use clash_verge_service_ipc::{ RuntimeBundle, RuntimeFileOutcome, RuntimeFileRequest, ServiceErrorCode, ServiceStatusSnapshot, StageRuntimeOutcome, StartClashRequest, WriterConfig, }; -use once_cell::sync::Lazy; use parking_lot::Mutex; +use std::sync::LazyLock; use std::{ collections::HashMap, env::current_exe, @@ -39,7 +39,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: LazyLock>> = LazyLock::new(|| Mutex::new(None)); static PENDING_SERVICE_FALLBACK_NOTICE: AtomicBool = AtomicBool::new(false); 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 b3f9310f8..a17ba964e 100644 --- a/src-tauri/src/feat/clash.rs +++ b/src-tauri/src/feat/clash.rs @@ -9,13 +9,13 @@ 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::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 2dd0c4ae1..90c92de53 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 5175a02c5..70bb9d86b 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,