diff --git a/src-tauri/src/cmd/lightweight.rs b/src-tauri/src/cmd/lightweight.rs index 470254969..af1fe7ad9 100644 --- a/src-tauri/src/cmd/lightweight.rs +++ b/src-tauri/src/cmd/lightweight.rs @@ -1,4 +1,4 @@ -use crate::module::lightweight; +use crate::core::lightweight; use super::CmdResult; diff --git a/src-tauri/src/cmd/save_profile.rs b/src-tauri/src/cmd/save_profile.rs index e1000847f..cfefc7133 100644 --- a/src-tauri/src/cmd/save_profile.rs +++ b/src-tauri/src/cmd/save_profile.rs @@ -3,11 +3,11 @@ use crate::{ cmd::StringifyErr as _, cmd::validate::{ValidationNoticeTarget, handle_validation_notice}, config::{Config, IProfiles, PrfItem}, + core::auto_backup::{AutoBackupManager, AutoBackupTrigger}, core::{ CoreManager, handle, validate::{CoreConfigValidator, ValidationOutcome}, }, - module::auto_backup::{AutoBackupManager, AutoBackupTrigger}, utils::dirs, }; use clash_verge_logging::{Type, logging, logging_error}; diff --git a/src-tauri/src/core/app_effects.rs b/src-tauri/src/core/app_effects.rs new file mode 100644 index 000000000..ffddae685 --- /dev/null +++ b/src-tauri/src/core/app_effects.rs @@ -0,0 +1,57 @@ +use crate::{ + config::{Config, IVerge}, + core::{autostart, hotkey, lightweight, tray}, +}; +use anyhow::Result; +use futures::future::BoxFuture; + +pub(crate) fn ensure_autostart(_patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { autostart::update_launch().await }) +} + +pub(crate) fn ensure_hotkey(patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { + if let Some(hotkeys) = &patch.hotkeys { + hotkey::Hotkey::global().update(hotkeys.to_owned()).await?; + } + Ok(()) + }) +} + +pub(crate) fn ensure_tray_menu(_patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { tray::Tray::global().update_menu().await }) +} + +pub(crate) fn ensure_tray_icon(patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { + tray::Tray::global() + .update_icon(&Config::verge().await.latest_arc()) + .await?; + #[cfg(target_os = "macos")] + if let Some(enabled) = patch.enable_tray_speed { + tray::Tray::global().update_speed_task(enabled); + } + #[cfg(not(target_os = "macos"))] + let _ = patch; + Ok(()) + }) +} + +pub(crate) fn ensure_tray_tooltip(_patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { tray::Tray::global().update_tooltip().await }) +} + +pub(crate) fn ensure_tray_click(_patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { tray::Tray::global().update_click_behavior().await }) +} + +pub(crate) fn ensure_lightweight(patch: &IVerge) -> BoxFuture<'_, Result<()>> { + Box::pin(async move { + if patch.enable_auto_light_weight_mode.unwrap_or(false) { + lightweight::enable_auto_light_weight_mode().await; + } else { + lightweight::disable_auto_light_weight_mode(); + } + Ok(()) + }) +} diff --git a/src-tauri/src/module/auto_backup.rs b/src-tauri/src/core/auto_backup.rs similarity index 100% rename from src-tauri/src/module/auto_backup.rs rename to src-tauri/src/core/auto_backup.rs diff --git a/src-tauri/src/core/hotkey.rs b/src-tauri/src/core/hotkey.rs index 72d44f811..75027d176 100755 --- a/src-tauri/src/core/hotkey.rs +++ b/src-tauri/src/core/hotkey.rs @@ -3,7 +3,7 @@ use crate::process::AsyncHandler; use crate::singleton; use crate::utils::notification::{NotificationEvent, notify_event}; use crate::utils::window_manager::WindowManager; -use crate::{config::Config, core::handle, feat, module::lightweight::entry_lightweight_mode}; +use crate::{config::Config, core::handle, core::lightweight::entry_lightweight_mode, feat}; use anyhow::{Result, bail}; use arc_swap::ArcSwap; use clash_verge_logging::{Type, logging}; diff --git a/src-tauri/src/module/lightweight.rs b/src-tauri/src/core/lightweight.rs similarity index 100% rename from src-tauri/src/module/lightweight.rs rename to src-tauri/src/core/lightweight.rs diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index 402d4bdce..fefd3d059 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -1,6 +1,9 @@ +pub(crate) mod app_effects; +pub mod auto_backup; pub mod autostart; pub mod backup; pub mod hotkey; +pub mod lightweight; pub mod listener; pub mod logger; pub mod manager; diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 8f9f5ba06..62ed45434 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -1,14 +1,14 @@ use crate::config::{IProfilePreview, IVerge}; +use crate::core::lightweight; use crate::core::tray::menu_def::TrayAction; -use crate::module::lightweight; use crate::process::AsyncHandler; use crate::singleton; use crate::utils::window_manager::WindowManager; use crate::{ Type, cmd, config::Config, + core::lightweight::is_in_lightweight_mode, feat, logging, - module::lightweight::is_in_lightweight_mode, utils::{dirs::find_target_icons, help}, }; use clash_verge_limiter::{Limiter, SystemClock, SystemLimiter}; diff --git a/src-tauri/src/feat/executor.rs b/src-tauri/src/feat/executor.rs index 0c26660db..fd095e8ef 100644 --- a/src-tauri/src/feat/executor.rs +++ b/src-tauri/src/feat/executor.rs @@ -5,8 +5,8 @@ use crate::{ Config, IVerge, snapshot::{capture_config_files, restore_files}, }, - core::{CoreManager, autostart, hotkey, logger, manager::ConfigUpdateGuard, proxy_control, tray}, - module::{auto_backup::AutoBackupManager, lightweight}, + core::auto_backup::AutoBackupManager, + core::{CoreManager, logger, manager::ConfigUpdateGuard, proxy_control}, }; use anyhow::Result; use clash_verge_draft::DraftTransaction; @@ -63,7 +63,9 @@ ensure!(ensure_clash, ctx, { Ok(()) }); ensure!(ensure_verge, _ctx, { Ok(()) }); -ensure!(ensure_autostart, _ctx, { autostart::update_launch().await }); +ensure!(ensure_autostart, ctx, { + crate::core::app_effects::ensure_autostart(ctx.patch).await +}); ensure!(ensure_language, ctx, { if let Some(language) = &ctx.patch.language { clash_verge_i18n::set_locale(language.as_str()); @@ -86,37 +88,22 @@ ensure!(ensure_system_proxy, ctx, { } }); ensure!(ensure_hotkey, ctx, { - if let Some(hotkeys) = &ctx.patch.hotkeys { - hotkey::Hotkey::global().update(hotkeys.to_owned()).await?; - } - Ok(()) + crate::core::app_effects::ensure_hotkey(ctx.patch).await +}); +ensure!(ensure_tray_menu, ctx, { + crate::core::app_effects::ensure_tray_menu(ctx.patch).await }); -ensure!(ensure_tray_menu, _ctx, { tray::Tray::global().update_menu().await }); ensure!(ensure_tray_icon, ctx, { - tray::Tray::global() - .update_icon(&Config::verge().await.latest_arc()) - .await?; - #[cfg(target_os = "macos")] - if let Some(enabled) = ctx.patch.enable_tray_speed { - tray::Tray::global().update_speed_task(enabled); - } - #[cfg(not(target_os = "macos"))] - let _ = ctx; - Ok(()) + crate::core::app_effects::ensure_tray_icon(ctx.patch).await }); -ensure!(ensure_tray_tooltip, _ctx, { - tray::Tray::global().update_tooltip().await +ensure!(ensure_tray_tooltip, ctx, { + crate::core::app_effects::ensure_tray_tooltip(ctx.patch).await }); -ensure!(ensure_tray_click, _ctx, { - tray::Tray::global().update_click_behavior().await +ensure!(ensure_tray_click, ctx, { + crate::core::app_effects::ensure_tray_click(ctx.patch).await }); ensure!(ensure_lightweight, ctx, { - if ctx.patch.enable_auto_light_weight_mode.unwrap_or(false) { - lightweight::enable_auto_light_weight_mode().await; - } else { - lightweight::disable_auto_light_weight_mode(); - } - Ok(()) + crate::core::app_effects::ensure_lightweight(ctx.patch).await }); ensure!(ensure_log_level, ctx, { logger::Logger::global().update_log_level(ctx.patch.get_log_level()) diff --git a/src-tauri/src/feat/window.rs b/src-tauri/src/feat/window.rs index 66fb2fdda..e22d4eca8 100644 --- a/src-tauri/src/feat/window.rs +++ b/src-tauri/src/feat/window.rs @@ -1,7 +1,7 @@ use crate::config::Config; +use crate::core::lightweight; use crate::core::notify::NoticeStatus; use crate::core::{CoreManager, handle}; -use crate::module::lightweight; use crate::utils; use crate::utils::window_manager::WindowManager; use clash_verge_logging::{Type, logging}; @@ -231,7 +231,7 @@ pub async fn clean_session_ending_best_effort() -> CleanupResult { #[cfg(target_os = "macos")] pub async fn hide() { - use crate::module::lightweight::add_light_weight_timer; + use crate::core::lightweight::add_light_weight_timer; let enable_auto_light_weight_mode = Config::verge() .await diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c186457c7..ff27a1815 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -7,7 +7,6 @@ mod constants; mod core; mod enhance; mod feat; -mod module; mod process; pub mod utils; @@ -333,7 +332,7 @@ pub fn run() -> std::process::ExitCode { mod event_handlers { #[cfg(target_os = "macos")] - use crate::module::lightweight; + use crate::core::lightweight; use crate::utils::window_manager::WindowManager; use crate::{ config::Config, @@ -488,7 +487,7 @@ pub fn run() -> std::process::ExitCode { }), #[allow(unused_variables)] tauri::RunEvent::ExitRequested { api, code, .. } => { - if module::lightweight::is_in_lightweight_mode() && !handle::Handle::global().is_exiting() { + if core::lightweight::is_in_lightweight_mode() && !handle::Handle::global().is_exiting() { api.prevent_exit(); } else if code.is_none() { api.prevent_exit(); diff --git a/src-tauri/src/module/mod.rs b/src-tauri/src/module/mod.rs deleted file mode 100644 index 97494e8f3..000000000 --- a/src-tauri/src/module/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod auto_backup; -pub mod lightweight; diff --git a/src-tauri/src/utils/resolve/mod.rs b/src-tauri/src/utils/resolve/mod.rs index c3c9fbe12..696931257 100644 --- a/src-tauri/src/utils/resolve/mod.rs +++ b/src-tauri/src/utils/resolve/mod.rs @@ -14,8 +14,8 @@ use crate::{ service::{SERVICE_MANAGER, ServiceManager}, tray::Tray, }, + core::{auto_backup::AutoBackupManager, lightweight::auto_lightweight_boot}, feat, - module::{auto_backup::AutoBackupManager, lightweight::auto_lightweight_boot}, process::AsyncHandler, utils::{init, server, window_manager::WindowManager}, }; diff --git a/src-tauri/src/utils/server.rs b/src-tauri/src/utils/server.rs index 91e9946b5..40d87b769 100644 --- a/src-tauri/src/utils/server.rs +++ b/src-tauri/src/utils/server.rs @@ -1,7 +1,7 @@ use super::resolve; use crate::{ config::{Config, DEFAULT_PAC, MixedPort}, - module::lightweight, + core::lightweight, process::AsyncHandler, utils::{dirs, window_manager::WindowManager}, };