mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-06 17:12:07 +08:00
refactor: api cleanup (#7812)
* refactor(config): unify YAML persistence * refactor(config): remove redundant config APIs * refactor(config): remove unused config APIs * refactor(config): narrow profile APIs * fix(config): preserve profiles on invalid reorder * refactor(startup): narrow resolve helpers * refactor(config): unify mixed port defaults * refactor(network): simplify response APIs * refactor(config): make profile builders infallible * refactor(config): make profile activation infallible * refactor(api): simplify internal runtime APIs * refactor: consolidate internal config and window APIs
This commit is contained in:
@@ -21,13 +21,13 @@ use clash_verge_logging::{Type, logging, logging_error};
|
||||
use clash_verge_signal;
|
||||
|
||||
pub mod dns;
|
||||
pub mod scheme;
|
||||
pub mod window;
|
||||
pub mod window_script;
|
||||
mod scheme;
|
||||
pub(crate) mod window;
|
||||
mod window_script;
|
||||
|
||||
static RESOLVE_DONE: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
pub fn init_work_dir_and_logger() -> anyhow::Result<()> {
|
||||
pub(crate) fn init_work_dir_and_logger() -> anyhow::Result<()> {
|
||||
AsyncHandler::block_on(async {
|
||||
init_work_config().await;
|
||||
logging!(info, Type::Setup, "Initializing logger");
|
||||
@@ -36,16 +36,16 @@ pub fn init_work_dir_and_logger() -> anyhow::Result<()> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resolve_setup_sync() {
|
||||
pub(crate) fn resolve_setup_sync() {
|
||||
AsyncHandler::spawn(|| async {
|
||||
AsyncHandler::spawn_blocking(init_scheme);
|
||||
AsyncHandler::spawn_blocking(init_embed_server);
|
||||
AsyncHandler::spawn_blocking(server::embed_server);
|
||||
#[cfg(target_os = "linux")]
|
||||
AsyncHandler::spawn_blocking(watch_linux_theme_changed);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn resolve_setup_async() {
|
||||
pub(crate) fn resolve_setup_async() {
|
||||
AsyncHandler::spawn(|| async {
|
||||
logging!(info, Type::ClashVergeRev, "Version: {}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
@@ -100,21 +100,16 @@ pub async fn resolve_reset_async() -> Result<(), anyhow::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn init_scheme() {
|
||||
fn init_scheme() {
|
||||
logging_error!(Type::Setup, init::init_scheme());
|
||||
}
|
||||
|
||||
pub async fn resolve_scheme(param: &str) -> Result<()> {
|
||||
pub(crate) async fn resolve_scheme(param: &str) {
|
||||
logging_error!(Type::Setup, scheme::resolve_scheme(param).await);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn init_embed_server() {
|
||||
server::embed_server();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn watch_linux_theme_changed() {
|
||||
fn watch_linux_theme_changed() {
|
||||
match dark_light::subscribe() {
|
||||
Ok(watcher) => {
|
||||
for mode in watcher.iter() {
|
||||
@@ -137,28 +132,28 @@ pub(crate) fn watch_linux_theme_changed() {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn init_resources() {
|
||||
async fn init_resources() {
|
||||
logging_error!(Type::Setup, init::init_resources().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_startup_script() {
|
||||
async fn init_startup_script() {
|
||||
logging_error!(Type::Setup, init::startup_script().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_timer() {
|
||||
async fn init_timer() {
|
||||
logging_error!(Type::Setup, Timer::global().init().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_hotkey() {
|
||||
async fn init_hotkey() {
|
||||
let skip_register_hotkeys = !Config::verge().await.latest_arc().enable_global_hotkey.unwrap_or(true);
|
||||
logging_error!(Type::Setup, Hotkey::global().init(skip_register_hotkeys).await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_auto_lightweight_boot() {
|
||||
async fn init_auto_lightweight_boot() {
|
||||
logging_error!(Type::Setup, auto_lightweight_boot().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_auto_backup() {
|
||||
async fn init_auto_backup() {
|
||||
logging_error!(Type::Setup, AutoBackupManager::global().init().await);
|
||||
}
|
||||
|
||||
@@ -184,37 +179,37 @@ async fn init_silent_updater() {
|
||||
logging!(info, Type::Setup, "Silent updater initialized");
|
||||
}
|
||||
|
||||
pub fn init_signal() {
|
||||
pub(crate) fn init_signal() {
|
||||
logging!(info, Type::Setup, "Initializing signal handlers...");
|
||||
clash_verge_signal::register(feat::quit);
|
||||
}
|
||||
|
||||
pub async fn init_work_config() {
|
||||
async fn init_work_config() {
|
||||
logging_error!(Type::Setup, init::init_config().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_tray() {
|
||||
async fn init_tray() {
|
||||
logging_error!(Type::Setup, Tray::global().init().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_verge_config() {
|
||||
async fn init_verge_config() {
|
||||
logging_error!(Type::Setup, Config::init_runtime_config().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_verge_config_before_window() -> bool {
|
||||
async fn init_verge_config_before_window() -> bool {
|
||||
let result = Config::init_config_before_window().await;
|
||||
let success = result.is_ok();
|
||||
logging_error!(Type::Setup, result);
|
||||
success
|
||||
}
|
||||
|
||||
pub(super) async fn init_service_manager() {
|
||||
async fn init_service_manager() {
|
||||
clash_verge_service_ipc::set_config(Some(ServiceManager::config())).await;
|
||||
|
||||
SERVICE_MANAGER.detect_startup_status().await;
|
||||
}
|
||||
|
||||
pub(super) async fn init_core_manager() -> bool {
|
||||
async fn init_core_manager() -> bool {
|
||||
match CoreManager::global().init().await {
|
||||
Ok(initialized) => initialized,
|
||||
Err(error) => {
|
||||
@@ -224,27 +219,27 @@ pub(super) async fn init_core_manager() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn refresh_tray_menu() {
|
||||
async fn refresh_tray_menu() {
|
||||
logging_error!(Type::Setup, Tray::global().update_part().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_window() {
|
||||
async fn init_window() {
|
||||
let is_silent_start = Config::verge().await.data_arc().enable_silent_start.unwrap_or(false);
|
||||
WindowManager::create_window(!is_silent_start).await;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub(super) async fn resolve_dock_show() {
|
||||
async fn resolve_dock_show() {
|
||||
let is_silent_start = Config::verge().await.data_arc().enable_silent_start.unwrap_or(false);
|
||||
if is_silent_start {
|
||||
Handle::global().set_activation_policy_accessory();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_done() {
|
||||
fn resolve_done() {
|
||||
RESOLVE_DONE.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
pub fn is_resolve_done() -> bool {
|
||||
pub(crate) fn is_resolve_done() -> bool {
|
||||
RESOLVE_DONE.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ async fn post_import_updates(uid: &String, had_current_profile: bool) {
|
||||
false
|
||||
} else {
|
||||
let profiles = Config::profiles().await;
|
||||
profiles.latest_arc().is_current_profile_index(uid)
|
||||
profiles.latest_arc().current.as_ref() == Some(uid)
|
||||
};
|
||||
|
||||
if should_update_core {
|
||||
|
||||
Reference in New Issue
Block a user