2025-03-01 22:52:43 +08:00
|
|
|
mod cmd;
|
2025-07-04 22:43:23 +08:00
|
|
|
pub mod config;
|
2024-09-15 06:24:53 +08:00
|
|
|
mod core;
|
|
|
|
|
mod enhance;
|
|
|
|
|
mod feat;
|
feat: migrate mihomo to use kode-bridge IPC on Windows and Unix (#4051)
* Refactor Mihomo API integration and remove crate_mihomo_api
- Removed the `mihomo_api` crate and its dependencies from the project.
- Introduced `IpcManager` for handling IPC communication with Mihomo.
- Implemented IPC methods for managing proxies, connections, and configurations.
- Updated `MihomoManager` to utilize `IpcManager` instead of the removed crate.
- Added platform-specific IPC socket path handling for macOS, Linux, and Windows.
- Cleaned up related tests and configuration files.
* fix: remove duplicate permission entry in desktop capabilities
* refactor: replace MihomoManager with IpcManager and remove Mihomo module
* fix: restore tempfile dependency in dev-dependencies
* fix: update kode-bridge dependency to use git source from the dev branch
* feat: migrate mihomo to use kode-bridge IPC on Windows
This commit implements a comprehensive migration from legacy service IPC to the kode-bridge library for Windows IPC communication. Key changes include:
Replace service_ipc with kode-bridge IpcManager for all mihomo communications
Simplify proxy commands using new caching mechanism with ProxyRequestCache
Add Windows named pipe (\.\pipe\mihomo) and Unix socket IPC endpoint configuration
Update Tauri permissions and dependencies (dashmap, tauri-plugin-notification)
Add IPC logging support and improve error handling
Fix Windows IPC path handling in directory utilities
This migration enables better cross-platform IPC support and improved performance for mihomo proxy core communication.
* doc: add IPC communication with Mihomo kernel, removing Restful API dependency
* fix: standardize logging type naming from IPC to Ipc for consistency
* refactor: clean up and optimize code structure across multiple components and services
- Removed unnecessary comments and whitespace in various files.
- Improved code readability and maintainability by restructuring functions and components.
- Updated localization files for consistency and accuracy.
- Enhanced performance by optimizing hooks and utility functions.
- General code cleanup in settings, pages, and services to adhere to best practices.
* fix: simplify URL formatting in test_proxy_delay method
* fix: update kode-bridge dependency to version 0.1.3 and change source to crates.io
* fix: update macOS target versions in development workflow
* Revert "fix: update macOS target versions in development workflow"
This reverts commit b9831357e462e0f308d11a9a53cb718f98ae1295.
* feat: enhance IPC path handling for Unix systems and improve directory safety checks
* feat: add conditional compilation for Unix-specific IPC path handling
* chore: update cagro.lock
* feat: add external controller configuration and UI support
* Refactor proxy and connection management to use IPC-based commands
- Updated `get_proxies` function in `proxy.rs` to call the new IPC command.
- Renamed `get_refresh_proxies` to `get_proxies` in `ipc/general.rs` for consistency.
- Added new IPC commands for managing proxies, connections, and configurations in `cmds.ts`.
- Refactored API calls in various components to use the new IPC commands instead of HTTP requests.
- Improved error handling and response management in the new IPC functions.
- Cleaned up unused API functions in `api.ts` and redirected relevant calls to `cmds.ts`.
- Enhanced connection management features including health checks and updates for proxy providers.
* chore: update dependencies and improve error handling in IPC manager
* fix: downgrade zip dependency from 4.3.0 to 4.2.0
* feat: Implement traffic and memory data monitoring service
- Added `TrafficService` and `TrafficManager` to manage traffic and memory data collection.
- Introduced commands to get traffic and memory data, start and stop the traffic service.
- Integrated IPC calls for traffic and memory data retrieval in the frontend.
- Updated `AppDataProvider` and `EnhancedTrafficStats` components to utilize new data fetching methods.
- Removed WebSocket connections for traffic and memory data, replaced with IPC polling.
- Added logging for better traceability of data fetching and service status.
* refactor: unify external controller handling and improve IPC path resolution
* fix: replace direct IPC path retrieval with guard function for external controller
* fix: convert external controller IPC path to string for proper insertion in config map
* fix: update dependencies and improve IPC response handling
* fix: remove unnecessary unix conditional for ipc path import
* Refactor traffic and memory monitoring to use IPC stream; remove TrafficService and TrafficManager. Introduce new IPC-based data retrieval methods for traffic and memory, including formatted data and system overview. Update frontend components to utilize new APIs for enhanced data display and management.
* chore: bump crate rand version to 0.9.2
* feat: Implement enhanced traffic monitoring system with data compression and sampling
- Introduced `useTrafficMonitorEnhanced` hook for advanced traffic data management.
- Added `TrafficDataSampler` class for handling raw and compressed traffic data.
- Implemented reference counting to manage data collection based on component usage.
- Enhanced data validation with `SystemMonitorValidator` for API responses.
- Created diagnostic tools for monitoring performance and error tracking.
- Updated existing hooks to utilize the new enhanced monitoring features.
- Added utility functions for generating and formatting diagnostic reports.
* feat(ipc): improve URL encoding and error handling for IPC requests
- Add percent-encoding for URL paths to handle special characters properly
- Enhance error handling in update_proxy with proper logging
- Remove excessive debug logging to reduce noise
- Update kode-bridge dependency to v0.1.5
- Fix JSON parsing error handling in PUT requests
Changes include:
- Proper URL encoding for connection IDs, proxy names, and test URLs
- Enhanced error handling with fallback responses in updateProxy
- Comment out verbose debug logs in traffic monitoring and data validation
- Update dependency version for improved IPC functionality
* feat: major improvements in architecture, traffic monitoring, and data validation
* Refactor traffic graph components: Replace EnhancedTrafficGraph with EnhancedCanvasTrafficGraph, improve rendering performance, and enhance visual elements. Remove deprecated code and ensure compatibility with global data management.
* chore: update UPDATELOG.md for v2.4.0 release, refine traffic monitoring system details, and enhance IPC functionality
* chore: update UPDATELOG.md to reflect removal of deprecated MihomoManager and unify IPC control
* refactor: remove global traffic service testing method from cmds.ts
* Update src/components/home/enhanced-canvas-traffic-graph.tsx
* Update src/hooks/use-traffic-monitor-enhanced.ts
* Update src/components/layout/layout-traffic.tsx
* refactor: remove debug state management from LayoutTraffic component
---------
2025-07-24 00:47:42 +08:00
|
|
|
mod ipc;
|
2025-03-03 05:58:12 +08:00
|
|
|
mod module;
|
2025-04-11 17:27:56 +08:00
|
|
|
mod process;
|
2025-06-05 13:43:02 +08:00
|
|
|
mod state;
|
2025-03-13 12:51:20 +08:00
|
|
|
mod utils;
|
|
|
|
|
use crate::{
|
|
|
|
|
core::hotkey,
|
2025-04-11 17:27:56 +08:00
|
|
|
process::AsyncHandler,
|
2025-03-13 12:51:20 +08:00
|
|
|
utils::{resolve, resolve::resolve_scheme, server},
|
|
|
|
|
};
|
2025-02-09 07:45:22 +08:00
|
|
|
use config::Config;
|
2025-07-06 02:14:48 +08:00
|
|
|
use parking_lot::Mutex;
|
|
|
|
|
use std::sync::Once;
|
2025-03-20 18:14:18 +08:00
|
|
|
use tauri::AppHandle;
|
2025-07-06 02:14:48 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2025-03-03 02:27:45 +08:00
|
|
|
use tauri::Manager;
|
2025-06-11 00:19:06 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2025-03-13 12:51:20 +08:00
|
|
|
use tauri_plugin_autostart::MacosLauncher;
|
|
|
|
|
use tauri_plugin_deep_link::DeepLinkExt;
|
2025-04-25 18:24:16 +08:00
|
|
|
use tokio::time::{timeout, Duration};
|
2025-04-16 00:10:06 +08:00
|
|
|
use utils::logging::Type;
|
2025-03-01 18:29:40 +08:00
|
|
|
|
|
|
|
|
/// A global singleton handle to the application.
|
|
|
|
|
pub struct AppHandleManager {
|
|
|
|
|
inner: Mutex<Option<AppHandle>>,
|
|
|
|
|
init: Once,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AppHandleManager {
|
|
|
|
|
/// Get the global instance of the app handle manager.
|
|
|
|
|
pub fn global() -> &'static Self {
|
|
|
|
|
static INSTANCE: AppHandleManager = AppHandleManager {
|
|
|
|
|
inner: Mutex::new(None),
|
|
|
|
|
init: Once::new(),
|
|
|
|
|
};
|
|
|
|
|
&INSTANCE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Initialize the app handle manager with an app handle.
|
|
|
|
|
pub fn init(&self, handle: AppHandle) {
|
|
|
|
|
self.init.call_once(|| {
|
2025-07-06 02:14:48 +08:00
|
|
|
let mut app_handle = self.inner.lock();
|
2025-03-01 18:29:40 +08:00
|
|
|
*app_handle = Some(handle);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the app handle if it has been initialized.
|
|
|
|
|
pub fn get(&self) -> Option<AppHandle> {
|
2025-07-06 02:14:48 +08:00
|
|
|
self.inner.lock().clone()
|
2025-03-01 18:29:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the app handle, panics if it hasn't been initialized.
|
|
|
|
|
pub fn get_handle(&self) -> AppHandle {
|
|
|
|
|
self.get().expect("AppHandle not initialized")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_activation_policy_regular(&self) {
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-07-06 02:14:48 +08:00
|
|
|
let app_handle = self.inner.lock();
|
2025-03-01 18:29:40 +08:00
|
|
|
let app_handle = app_handle.as_ref().unwrap();
|
|
|
|
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Regular);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-13 12:51:20 +08:00
|
|
|
|
2025-03-01 18:29:40 +08:00
|
|
|
pub fn set_activation_policy_accessory(&self) {
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-07-06 02:14:48 +08:00
|
|
|
let app_handle = self.inner.lock();
|
2025-03-01 18:29:40 +08:00
|
|
|
let app_handle = app_handle.as_ref().unwrap();
|
|
|
|
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-13 12:51:20 +08:00
|
|
|
|
2025-03-01 18:29:40 +08:00
|
|
|
pub fn set_activation_policy_prohibited(&self) {
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-07-06 02:14:48 +08:00
|
|
|
let app_handle = self.inner.lock();
|
2025-03-01 18:29:40 +08:00
|
|
|
let app_handle = app_handle.as_ref().unwrap();
|
|
|
|
|
let _ = app_handle.set_activation_policy(tauri::ActivationPolicy::Prohibited);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
|
|
|
|
|
pub fn run() {
|
2025-04-30 21:30:28 +08:00
|
|
|
utils::network::NetworkManager::global().init();
|
|
|
|
|
|
2025-05-10 01:25:50 +08:00
|
|
|
let _ = utils::dirs::init_portable_flag();
|
|
|
|
|
|
2025-06-13 22:58:55 +08:00
|
|
|
// 异步单例检测
|
|
|
|
|
AsyncHandler::spawn(move || async move {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "开始检查单例实例...");
|
2025-04-25 18:24:16 +08:00
|
|
|
match timeout(Duration::from_secs(3), server::check_singleton()).await {
|
|
|
|
|
Ok(result) => {
|
|
|
|
|
if result.is_err() {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "检测到已有应用实例运行");
|
2025-06-13 22:58:55 +08:00
|
|
|
if let Some(app_handle) = AppHandleManager::global().get() {
|
2025-06-14 02:43:58 +08:00
|
|
|
app_handle.exit(0);
|
2025-06-13 22:58:55 +08:00
|
|
|
} else {
|
|
|
|
|
std::process::exit(0);
|
|
|
|
|
}
|
2025-04-25 18:24:16 +08:00
|
|
|
} else {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "未检测到其他应用实例");
|
2025-04-25 18:24:16 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(
|
|
|
|
|
warn,
|
|
|
|
|
Type::Setup,
|
|
|
|
|
true,
|
|
|
|
|
"单例检查超时,假定没有其他实例运行"
|
|
|
|
|
);
|
2025-04-25 18:24:16 +08:00
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
|
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
let devtools = tauri_plugin_devtools::init();
|
2025-05-26 22:26:52 +08:00
|
|
|
|
2024-09-15 06:24:53 +08:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
|
let mut builder = tauri::Builder::default()
|
2025-06-26 23:09:07 +08:00
|
|
|
.plugin(tauri_plugin_notification::init())
|
2024-09-15 06:24:53 +08:00
|
|
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
|
|
|
|
.plugin(tauri_plugin_clipboard_manager::init())
|
|
|
|
|
.plugin(tauri_plugin_process::init())
|
|
|
|
|
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
|
|
|
|
.plugin(tauri_plugin_fs::init())
|
|
|
|
|
.plugin(tauri_plugin_dialog::init())
|
|
|
|
|
.plugin(tauri_plugin_shell::init())
|
|
|
|
|
.plugin(tauri_plugin_deep_link::init())
|
2025-07-06 02:14:48 +08:00
|
|
|
.manage(Mutex::new(state::lightweight::LightWeightState::default()))
|
2024-09-15 06:24:53 +08:00
|
|
|
.setup(|app| {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "开始应用初始化...");
|
2025-05-26 22:26:52 +08:00
|
|
|
let mut auto_start_plugin_builder = tauri_plugin_autostart::Builder::new();
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
|
|
|
|
auto_start_plugin_builder = auto_start_plugin_builder
|
|
|
|
|
.macos_launcher(MacosLauncher::LaunchAgent)
|
|
|
|
|
.app_name(app.config().identifier.clone());
|
|
|
|
|
}
|
|
|
|
|
let _ = app.handle().plugin(auto_start_plugin_builder.build());
|
|
|
|
|
|
2024-12-08 15:54:46 +08:00
|
|
|
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
|
2024-11-17 01:01:36 +08:00
|
|
|
{
|
|
|
|
|
use tauri_plugin_deep_link::DeepLinkExt;
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "注册深层链接...");
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(Type::System, true, app.deep_link().register_all());
|
2024-11-17 01:01:36 +08:00
|
|
|
}
|
2025-05-26 22:26:52 +08:00
|
|
|
|
2024-12-08 15:54:46 +08:00
|
|
|
app.deep_link().on_open_url(|event| {
|
2025-04-11 17:27:56 +08:00
|
|
|
AsyncHandler::spawn(move || {
|
|
|
|
|
let url = event.urls().first().map(|u| u.to_string());
|
|
|
|
|
async move {
|
|
|
|
|
if let Some(url) = url {
|
|
|
|
|
logging_error!(Type::Setup, true, resolve_scheme(url).await);
|
|
|
|
|
}
|
2024-12-08 15:54:46 +08:00
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
});
|
2024-12-08 15:54:46 +08:00
|
|
|
});
|
|
|
|
|
|
2025-06-18 02:21:00 +08:00
|
|
|
// 窗口管理
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化窗口状态管理...");
|
|
|
|
|
let window_state_plugin = tauri_plugin_window_state::Builder::new()
|
|
|
|
|
.with_filename("window_state.json")
|
|
|
|
|
.with_state_flags(tauri_plugin_window_state::StateFlags::default())
|
|
|
|
|
.build();
|
|
|
|
|
let _ = app.handle().plugin(window_state_plugin);
|
|
|
|
|
|
2025-05-10 01:25:50 +08:00
|
|
|
// 异步处理
|
2025-05-10 01:45:39 +08:00
|
|
|
let app_handle = app.handle().clone();
|
2025-05-10 01:25:50 +08:00
|
|
|
AsyncHandler::spawn(move || async move {
|
|
|
|
|
logging!(info, Type::Setup, true, "异步执行应用设置...");
|
|
|
|
|
match timeout(
|
|
|
|
|
Duration::from_secs(30),
|
|
|
|
|
resolve::resolve_setup_async(&app_handle),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-04-25 18:24:16 +08:00
|
|
|
Ok(_) => {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "应用设置成功完成");
|
2025-04-25 18:24:16 +08:00
|
|
|
}
|
|
|
|
|
Err(_) => {
|
|
|
|
|
logging!(
|
|
|
|
|
error,
|
|
|
|
|
Type::Setup,
|
|
|
|
|
true,
|
2025-05-10 01:25:50 +08:00
|
|
|
"应用设置超时(30秒),继续执行后续流程"
|
2025-04-25 18:24:16 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
});
|
|
|
|
|
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Setup, true, "执行主要设置操作...");
|
|
|
|
|
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化AppHandleManager...");
|
2025-05-10 01:45:39 +08:00
|
|
|
AppHandleManager::global().init(app.handle().clone());
|
2025-05-10 01:25:50 +08:00
|
|
|
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化核心句柄...");
|
2025-05-10 01:45:39 +08:00
|
|
|
core::handle::Handle::global().init(app.handle());
|
2025-05-10 01:25:50 +08:00
|
|
|
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化配置...");
|
|
|
|
|
if let Err(e) = utils::init::init_config() {
|
|
|
|
|
logging!(error, Type::Setup, true, "初始化配置失败: {}", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化资源...");
|
|
|
|
|
if let Err(e) = utils::init::init_resources() {
|
|
|
|
|
logging!(error, Type::Setup, true, "初始化资源失败: {}", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logging!(info, Type::Setup, true, "初始化完成,继续执行");
|
2024-09-15 06:24:53 +08:00
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
// common
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::get_sys_proxy,
|
|
|
|
|
cmd::get_auto_proxy,
|
|
|
|
|
cmd::open_app_dir,
|
|
|
|
|
cmd::open_logs_dir,
|
|
|
|
|
cmd::open_web_url,
|
|
|
|
|
cmd::open_core_dir,
|
|
|
|
|
cmd::get_portable_flag,
|
|
|
|
|
cmd::get_network_interfaces,
|
2025-04-16 10:22:53 +08:00
|
|
|
cmd::get_system_hostname,
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::restart_app,
|
2025-05-13 01:56:19 +08:00
|
|
|
// 内核管理
|
|
|
|
|
cmd::start_core,
|
|
|
|
|
cmd::stop_core,
|
|
|
|
|
cmd::restart_core,
|
2025-05-10 01:25:50 +08:00
|
|
|
// 启动命令
|
2025-04-16 00:10:06 +08:00
|
|
|
cmd::notify_ui_ready,
|
2025-05-10 01:25:50 +08:00
|
|
|
cmd::update_ui_stage,
|
2025-04-20 23:47:09 +08:00
|
|
|
cmd::reset_ui_ready_state,
|
2025-03-03 14:42:31 +08:00
|
|
|
cmd::get_running_mode,
|
2025-03-14 13:31:34 +08:00
|
|
|
cmd::get_app_uptime,
|
2025-03-17 09:48:44 +08:00
|
|
|
cmd::get_auto_launch_status,
|
2025-03-31 03:22:24 +08:00
|
|
|
cmd::is_admin,
|
2025-04-20 23:47:09 +08:00
|
|
|
// 添加轻量模式相关命令
|
|
|
|
|
cmd::entry_lightweight_mode,
|
|
|
|
|
cmd::exit_lightweight_mode,
|
2025-03-26 15:02:08 +08:00
|
|
|
// service 管理
|
|
|
|
|
cmd::install_service,
|
|
|
|
|
cmd::uninstall_service,
|
|
|
|
|
cmd::reinstall_service,
|
|
|
|
|
cmd::repair_service,
|
2025-05-12 19:04:08 +08:00
|
|
|
cmd::is_service_available,
|
2024-09-15 06:24:53 +08:00
|
|
|
// clash
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::get_clash_info,
|
|
|
|
|
cmd::patch_clash_config,
|
|
|
|
|
cmd::patch_clash_mode,
|
|
|
|
|
cmd::change_clash_core,
|
|
|
|
|
cmd::get_runtime_config,
|
|
|
|
|
cmd::get_runtime_yaml,
|
|
|
|
|
cmd::get_runtime_exists,
|
|
|
|
|
cmd::get_runtime_logs,
|
|
|
|
|
cmd::invoke_uwp_tool,
|
|
|
|
|
cmd::copy_clash_env,
|
2025-03-04 01:01:24 +08:00
|
|
|
cmd::get_proxies,
|
2025-06-17 11:38:53 +08:00
|
|
|
cmd::force_refresh_proxies,
|
2025-03-04 01:01:24 +08:00
|
|
|
cmd::get_providers_proxies,
|
2025-03-08 11:25:00 +08:00
|
|
|
cmd::save_dns_config,
|
|
|
|
|
cmd::apply_dns_config,
|
|
|
|
|
cmd::check_dns_config_exists,
|
|
|
|
|
cmd::get_dns_config_content,
|
2025-05-11 22:55:31 +08:00
|
|
|
cmd::validate_dns_config,
|
feat: migrate mihomo to use kode-bridge IPC on Windows and Unix (#4051)
* Refactor Mihomo API integration and remove crate_mihomo_api
- Removed the `mihomo_api` crate and its dependencies from the project.
- Introduced `IpcManager` for handling IPC communication with Mihomo.
- Implemented IPC methods for managing proxies, connections, and configurations.
- Updated `MihomoManager` to utilize `IpcManager` instead of the removed crate.
- Added platform-specific IPC socket path handling for macOS, Linux, and Windows.
- Cleaned up related tests and configuration files.
* fix: remove duplicate permission entry in desktop capabilities
* refactor: replace MihomoManager with IpcManager and remove Mihomo module
* fix: restore tempfile dependency in dev-dependencies
* fix: update kode-bridge dependency to use git source from the dev branch
* feat: migrate mihomo to use kode-bridge IPC on Windows
This commit implements a comprehensive migration from legacy service IPC to the kode-bridge library for Windows IPC communication. Key changes include:
Replace service_ipc with kode-bridge IpcManager for all mihomo communications
Simplify proxy commands using new caching mechanism with ProxyRequestCache
Add Windows named pipe (\.\pipe\mihomo) and Unix socket IPC endpoint configuration
Update Tauri permissions and dependencies (dashmap, tauri-plugin-notification)
Add IPC logging support and improve error handling
Fix Windows IPC path handling in directory utilities
This migration enables better cross-platform IPC support and improved performance for mihomo proxy core communication.
* doc: add IPC communication with Mihomo kernel, removing Restful API dependency
* fix: standardize logging type naming from IPC to Ipc for consistency
* refactor: clean up and optimize code structure across multiple components and services
- Removed unnecessary comments and whitespace in various files.
- Improved code readability and maintainability by restructuring functions and components.
- Updated localization files for consistency and accuracy.
- Enhanced performance by optimizing hooks and utility functions.
- General code cleanup in settings, pages, and services to adhere to best practices.
* fix: simplify URL formatting in test_proxy_delay method
* fix: update kode-bridge dependency to version 0.1.3 and change source to crates.io
* fix: update macOS target versions in development workflow
* Revert "fix: update macOS target versions in development workflow"
This reverts commit b9831357e462e0f308d11a9a53cb718f98ae1295.
* feat: enhance IPC path handling for Unix systems and improve directory safety checks
* feat: add conditional compilation for Unix-specific IPC path handling
* chore: update cagro.lock
* feat: add external controller configuration and UI support
* Refactor proxy and connection management to use IPC-based commands
- Updated `get_proxies` function in `proxy.rs` to call the new IPC command.
- Renamed `get_refresh_proxies` to `get_proxies` in `ipc/general.rs` for consistency.
- Added new IPC commands for managing proxies, connections, and configurations in `cmds.ts`.
- Refactored API calls in various components to use the new IPC commands instead of HTTP requests.
- Improved error handling and response management in the new IPC functions.
- Cleaned up unused API functions in `api.ts` and redirected relevant calls to `cmds.ts`.
- Enhanced connection management features including health checks and updates for proxy providers.
* chore: update dependencies and improve error handling in IPC manager
* fix: downgrade zip dependency from 4.3.0 to 4.2.0
* feat: Implement traffic and memory data monitoring service
- Added `TrafficService` and `TrafficManager` to manage traffic and memory data collection.
- Introduced commands to get traffic and memory data, start and stop the traffic service.
- Integrated IPC calls for traffic and memory data retrieval in the frontend.
- Updated `AppDataProvider` and `EnhancedTrafficStats` components to utilize new data fetching methods.
- Removed WebSocket connections for traffic and memory data, replaced with IPC polling.
- Added logging for better traceability of data fetching and service status.
* refactor: unify external controller handling and improve IPC path resolution
* fix: replace direct IPC path retrieval with guard function for external controller
* fix: convert external controller IPC path to string for proper insertion in config map
* fix: update dependencies and improve IPC response handling
* fix: remove unnecessary unix conditional for ipc path import
* Refactor traffic and memory monitoring to use IPC stream; remove TrafficService and TrafficManager. Introduce new IPC-based data retrieval methods for traffic and memory, including formatted data and system overview. Update frontend components to utilize new APIs for enhanced data display and management.
* chore: bump crate rand version to 0.9.2
* feat: Implement enhanced traffic monitoring system with data compression and sampling
- Introduced `useTrafficMonitorEnhanced` hook for advanced traffic data management.
- Added `TrafficDataSampler` class for handling raw and compressed traffic data.
- Implemented reference counting to manage data collection based on component usage.
- Enhanced data validation with `SystemMonitorValidator` for API responses.
- Created diagnostic tools for monitoring performance and error tracking.
- Updated existing hooks to utilize the new enhanced monitoring features.
- Added utility functions for generating and formatting diagnostic reports.
* feat(ipc): improve URL encoding and error handling for IPC requests
- Add percent-encoding for URL paths to handle special characters properly
- Enhance error handling in update_proxy with proper logging
- Remove excessive debug logging to reduce noise
- Update kode-bridge dependency to v0.1.5
- Fix JSON parsing error handling in PUT requests
Changes include:
- Proper URL encoding for connection IDs, proxy names, and test URLs
- Enhanced error handling with fallback responses in updateProxy
- Comment out verbose debug logs in traffic monitoring and data validation
- Update dependency version for improved IPC functionality
* feat: major improvements in architecture, traffic monitoring, and data validation
* Refactor traffic graph components: Replace EnhancedTrafficGraph with EnhancedCanvasTrafficGraph, improve rendering performance, and enhance visual elements. Remove deprecated code and ensure compatibility with global data management.
* chore: update UPDATELOG.md for v2.4.0 release, refine traffic monitoring system details, and enhance IPC functionality
* chore: update UPDATELOG.md to reflect removal of deprecated MihomoManager and unify IPC control
* refactor: remove global traffic service testing method from cmds.ts
* Update src/components/home/enhanced-canvas-traffic-graph.tsx
* Update src/hooks/use-traffic-monitor-enhanced.ts
* Update src/components/layout/layout-traffic.tsx
* refactor: remove debug state management from LayoutTraffic component
---------
2025-07-24 00:47:42 +08:00
|
|
|
cmd::get_clash_version,
|
|
|
|
|
cmd::get_clash_config,
|
2025-07-24 01:56:18 +08:00
|
|
|
cmd::force_refresh_clash_config,
|
feat: migrate mihomo to use kode-bridge IPC on Windows and Unix (#4051)
* Refactor Mihomo API integration and remove crate_mihomo_api
- Removed the `mihomo_api` crate and its dependencies from the project.
- Introduced `IpcManager` for handling IPC communication with Mihomo.
- Implemented IPC methods for managing proxies, connections, and configurations.
- Updated `MihomoManager` to utilize `IpcManager` instead of the removed crate.
- Added platform-specific IPC socket path handling for macOS, Linux, and Windows.
- Cleaned up related tests and configuration files.
* fix: remove duplicate permission entry in desktop capabilities
* refactor: replace MihomoManager with IpcManager and remove Mihomo module
* fix: restore tempfile dependency in dev-dependencies
* fix: update kode-bridge dependency to use git source from the dev branch
* feat: migrate mihomo to use kode-bridge IPC on Windows
This commit implements a comprehensive migration from legacy service IPC to the kode-bridge library for Windows IPC communication. Key changes include:
Replace service_ipc with kode-bridge IpcManager for all mihomo communications
Simplify proxy commands using new caching mechanism with ProxyRequestCache
Add Windows named pipe (\.\pipe\mihomo) and Unix socket IPC endpoint configuration
Update Tauri permissions and dependencies (dashmap, tauri-plugin-notification)
Add IPC logging support and improve error handling
Fix Windows IPC path handling in directory utilities
This migration enables better cross-platform IPC support and improved performance for mihomo proxy core communication.
* doc: add IPC communication with Mihomo kernel, removing Restful API dependency
* fix: standardize logging type naming from IPC to Ipc for consistency
* refactor: clean up and optimize code structure across multiple components and services
- Removed unnecessary comments and whitespace in various files.
- Improved code readability and maintainability by restructuring functions and components.
- Updated localization files for consistency and accuracy.
- Enhanced performance by optimizing hooks and utility functions.
- General code cleanup in settings, pages, and services to adhere to best practices.
* fix: simplify URL formatting in test_proxy_delay method
* fix: update kode-bridge dependency to version 0.1.3 and change source to crates.io
* fix: update macOS target versions in development workflow
* Revert "fix: update macOS target versions in development workflow"
This reverts commit b9831357e462e0f308d11a9a53cb718f98ae1295.
* feat: enhance IPC path handling for Unix systems and improve directory safety checks
* feat: add conditional compilation for Unix-specific IPC path handling
* chore: update cagro.lock
* feat: add external controller configuration and UI support
* Refactor proxy and connection management to use IPC-based commands
- Updated `get_proxies` function in `proxy.rs` to call the new IPC command.
- Renamed `get_refresh_proxies` to `get_proxies` in `ipc/general.rs` for consistency.
- Added new IPC commands for managing proxies, connections, and configurations in `cmds.ts`.
- Refactored API calls in various components to use the new IPC commands instead of HTTP requests.
- Improved error handling and response management in the new IPC functions.
- Cleaned up unused API functions in `api.ts` and redirected relevant calls to `cmds.ts`.
- Enhanced connection management features including health checks and updates for proxy providers.
* chore: update dependencies and improve error handling in IPC manager
* fix: downgrade zip dependency from 4.3.0 to 4.2.0
* feat: Implement traffic and memory data monitoring service
- Added `TrafficService` and `TrafficManager` to manage traffic and memory data collection.
- Introduced commands to get traffic and memory data, start and stop the traffic service.
- Integrated IPC calls for traffic and memory data retrieval in the frontend.
- Updated `AppDataProvider` and `EnhancedTrafficStats` components to utilize new data fetching methods.
- Removed WebSocket connections for traffic and memory data, replaced with IPC polling.
- Added logging for better traceability of data fetching and service status.
* refactor: unify external controller handling and improve IPC path resolution
* fix: replace direct IPC path retrieval with guard function for external controller
* fix: convert external controller IPC path to string for proper insertion in config map
* fix: update dependencies and improve IPC response handling
* fix: remove unnecessary unix conditional for ipc path import
* Refactor traffic and memory monitoring to use IPC stream; remove TrafficService and TrafficManager. Introduce new IPC-based data retrieval methods for traffic and memory, including formatted data and system overview. Update frontend components to utilize new APIs for enhanced data display and management.
* chore: bump crate rand version to 0.9.2
* feat: Implement enhanced traffic monitoring system with data compression and sampling
- Introduced `useTrafficMonitorEnhanced` hook for advanced traffic data management.
- Added `TrafficDataSampler` class for handling raw and compressed traffic data.
- Implemented reference counting to manage data collection based on component usage.
- Enhanced data validation with `SystemMonitorValidator` for API responses.
- Created diagnostic tools for monitoring performance and error tracking.
- Updated existing hooks to utilize the new enhanced monitoring features.
- Added utility functions for generating and formatting diagnostic reports.
* feat(ipc): improve URL encoding and error handling for IPC requests
- Add percent-encoding for URL paths to handle special characters properly
- Enhance error handling in update_proxy with proper logging
- Remove excessive debug logging to reduce noise
- Update kode-bridge dependency to v0.1.5
- Fix JSON parsing error handling in PUT requests
Changes include:
- Proper URL encoding for connection IDs, proxy names, and test URLs
- Enhanced error handling with fallback responses in updateProxy
- Comment out verbose debug logs in traffic monitoring and data validation
- Update dependency version for improved IPC functionality
* feat: major improvements in architecture, traffic monitoring, and data validation
* Refactor traffic graph components: Replace EnhancedTrafficGraph with EnhancedCanvasTrafficGraph, improve rendering performance, and enhance visual elements. Remove deprecated code and ensure compatibility with global data management.
* chore: update UPDATELOG.md for v2.4.0 release, refine traffic monitoring system details, and enhance IPC functionality
* chore: update UPDATELOG.md to reflect removal of deprecated MihomoManager and unify IPC control
* refactor: remove global traffic service testing method from cmds.ts
* Update src/components/home/enhanced-canvas-traffic-graph.tsx
* Update src/hooks/use-traffic-monitor-enhanced.ts
* Update src/components/layout/layout-traffic.tsx
* refactor: remove debug state management from LayoutTraffic component
---------
2025-07-24 00:47:42 +08:00
|
|
|
cmd::update_geo_data,
|
|
|
|
|
cmd::upgrade_clash_core,
|
|
|
|
|
cmd::get_clash_rules,
|
|
|
|
|
cmd::update_proxy_choice,
|
|
|
|
|
cmd::get_proxy_providers,
|
|
|
|
|
cmd::get_rule_providers,
|
|
|
|
|
cmd::proxy_provider_health_check,
|
|
|
|
|
cmd::update_proxy_provider,
|
|
|
|
|
cmd::update_rule_provider,
|
|
|
|
|
cmd::get_clash_connections,
|
|
|
|
|
cmd::delete_clash_connection,
|
|
|
|
|
cmd::close_all_clash_connections,
|
|
|
|
|
cmd::get_group_proxy_delays,
|
|
|
|
|
cmd::is_clash_debug_enabled,
|
|
|
|
|
cmd::clash_gc,
|
2025-07-30 23:11:21 +08:00
|
|
|
cmd::get_clash_logs,
|
|
|
|
|
cmd::start_logs_monitoring,
|
|
|
|
|
cmd::clear_logs,
|
feat: migrate mihomo to use kode-bridge IPC on Windows and Unix (#4051)
* Refactor Mihomo API integration and remove crate_mihomo_api
- Removed the `mihomo_api` crate and its dependencies from the project.
- Introduced `IpcManager` for handling IPC communication with Mihomo.
- Implemented IPC methods for managing proxies, connections, and configurations.
- Updated `MihomoManager` to utilize `IpcManager` instead of the removed crate.
- Added platform-specific IPC socket path handling for macOS, Linux, and Windows.
- Cleaned up related tests and configuration files.
* fix: remove duplicate permission entry in desktop capabilities
* refactor: replace MihomoManager with IpcManager and remove Mihomo module
* fix: restore tempfile dependency in dev-dependencies
* fix: update kode-bridge dependency to use git source from the dev branch
* feat: migrate mihomo to use kode-bridge IPC on Windows
This commit implements a comprehensive migration from legacy service IPC to the kode-bridge library for Windows IPC communication. Key changes include:
Replace service_ipc with kode-bridge IpcManager for all mihomo communications
Simplify proxy commands using new caching mechanism with ProxyRequestCache
Add Windows named pipe (\.\pipe\mihomo) and Unix socket IPC endpoint configuration
Update Tauri permissions and dependencies (dashmap, tauri-plugin-notification)
Add IPC logging support and improve error handling
Fix Windows IPC path handling in directory utilities
This migration enables better cross-platform IPC support and improved performance for mihomo proxy core communication.
* doc: add IPC communication with Mihomo kernel, removing Restful API dependency
* fix: standardize logging type naming from IPC to Ipc for consistency
* refactor: clean up and optimize code structure across multiple components and services
- Removed unnecessary comments and whitespace in various files.
- Improved code readability and maintainability by restructuring functions and components.
- Updated localization files for consistency and accuracy.
- Enhanced performance by optimizing hooks and utility functions.
- General code cleanup in settings, pages, and services to adhere to best practices.
* fix: simplify URL formatting in test_proxy_delay method
* fix: update kode-bridge dependency to version 0.1.3 and change source to crates.io
* fix: update macOS target versions in development workflow
* Revert "fix: update macOS target versions in development workflow"
This reverts commit b9831357e462e0f308d11a9a53cb718f98ae1295.
* feat: enhance IPC path handling for Unix systems and improve directory safety checks
* feat: add conditional compilation for Unix-specific IPC path handling
* chore: update cagro.lock
* feat: add external controller configuration and UI support
* Refactor proxy and connection management to use IPC-based commands
- Updated `get_proxies` function in `proxy.rs` to call the new IPC command.
- Renamed `get_refresh_proxies` to `get_proxies` in `ipc/general.rs` for consistency.
- Added new IPC commands for managing proxies, connections, and configurations in `cmds.ts`.
- Refactored API calls in various components to use the new IPC commands instead of HTTP requests.
- Improved error handling and response management in the new IPC functions.
- Cleaned up unused API functions in `api.ts` and redirected relevant calls to `cmds.ts`.
- Enhanced connection management features including health checks and updates for proxy providers.
* chore: update dependencies and improve error handling in IPC manager
* fix: downgrade zip dependency from 4.3.0 to 4.2.0
* feat: Implement traffic and memory data monitoring service
- Added `TrafficService` and `TrafficManager` to manage traffic and memory data collection.
- Introduced commands to get traffic and memory data, start and stop the traffic service.
- Integrated IPC calls for traffic and memory data retrieval in the frontend.
- Updated `AppDataProvider` and `EnhancedTrafficStats` components to utilize new data fetching methods.
- Removed WebSocket connections for traffic and memory data, replaced with IPC polling.
- Added logging for better traceability of data fetching and service status.
* refactor: unify external controller handling and improve IPC path resolution
* fix: replace direct IPC path retrieval with guard function for external controller
* fix: convert external controller IPC path to string for proper insertion in config map
* fix: update dependencies and improve IPC response handling
* fix: remove unnecessary unix conditional for ipc path import
* Refactor traffic and memory monitoring to use IPC stream; remove TrafficService and TrafficManager. Introduce new IPC-based data retrieval methods for traffic and memory, including formatted data and system overview. Update frontend components to utilize new APIs for enhanced data display and management.
* chore: bump crate rand version to 0.9.2
* feat: Implement enhanced traffic monitoring system with data compression and sampling
- Introduced `useTrafficMonitorEnhanced` hook for advanced traffic data management.
- Added `TrafficDataSampler` class for handling raw and compressed traffic data.
- Implemented reference counting to manage data collection based on component usage.
- Enhanced data validation with `SystemMonitorValidator` for API responses.
- Created diagnostic tools for monitoring performance and error tracking.
- Updated existing hooks to utilize the new enhanced monitoring features.
- Added utility functions for generating and formatting diagnostic reports.
* feat(ipc): improve URL encoding and error handling for IPC requests
- Add percent-encoding for URL paths to handle special characters properly
- Enhance error handling in update_proxy with proper logging
- Remove excessive debug logging to reduce noise
- Update kode-bridge dependency to v0.1.5
- Fix JSON parsing error handling in PUT requests
Changes include:
- Proper URL encoding for connection IDs, proxy names, and test URLs
- Enhanced error handling with fallback responses in updateProxy
- Comment out verbose debug logs in traffic monitoring and data validation
- Update dependency version for improved IPC functionality
* feat: major improvements in architecture, traffic monitoring, and data validation
* Refactor traffic graph components: Replace EnhancedTrafficGraph with EnhancedCanvasTrafficGraph, improve rendering performance, and enhance visual elements. Remove deprecated code and ensure compatibility with global data management.
* chore: update UPDATELOG.md for v2.4.0 release, refine traffic monitoring system details, and enhance IPC functionality
* chore: update UPDATELOG.md to reflect removal of deprecated MihomoManager and unify IPC control
* refactor: remove global traffic service testing method from cmds.ts
* Update src/components/home/enhanced-canvas-traffic-graph.tsx
* Update src/hooks/use-traffic-monitor-enhanced.ts
* Update src/components/layout/layout-traffic.tsx
* refactor: remove debug state management from LayoutTraffic component
---------
2025-07-24 00:47:42 +08:00
|
|
|
cmd::get_traffic_data,
|
|
|
|
|
cmd::get_memory_data,
|
|
|
|
|
cmd::get_formatted_traffic_data,
|
|
|
|
|
cmd::get_formatted_memory_data,
|
|
|
|
|
cmd::get_system_monitor_overview,
|
|
|
|
|
cmd::start_traffic_service,
|
|
|
|
|
cmd::stop_traffic_service,
|
2024-09-15 06:24:53 +08:00
|
|
|
// verge
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::get_verge_config,
|
|
|
|
|
cmd::patch_verge_config,
|
|
|
|
|
cmd::test_delay,
|
|
|
|
|
cmd::get_app_dir,
|
|
|
|
|
cmd::copy_icon_file,
|
|
|
|
|
cmd::download_icon_cache,
|
|
|
|
|
cmd::open_devtools,
|
|
|
|
|
cmd::exit_app,
|
|
|
|
|
cmd::get_network_interfaces_info,
|
2024-09-15 06:24:53 +08:00
|
|
|
// profile
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::get_profiles,
|
|
|
|
|
cmd::enhance_profiles,
|
|
|
|
|
cmd::patch_profiles_config,
|
|
|
|
|
cmd::view_profile,
|
|
|
|
|
cmd::patch_profile,
|
|
|
|
|
cmd::create_profile,
|
|
|
|
|
cmd::import_profile,
|
|
|
|
|
cmd::reorder_profile,
|
|
|
|
|
cmd::update_profile,
|
|
|
|
|
cmd::delete_profile,
|
|
|
|
|
cmd::read_profile_file,
|
|
|
|
|
cmd::save_profile_file,
|
2025-04-25 17:17:34 +08:00
|
|
|
cmd::get_next_update_time,
|
2025-02-26 05:21:14 +08:00
|
|
|
// script validation
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::script_validate_notice,
|
|
|
|
|
cmd::validate_script_file,
|
2024-09-15 06:24:53 +08:00
|
|
|
// clash api
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::clash_api_get_proxy_delay,
|
2024-11-08 21:46:15 +08:00
|
|
|
// backup
|
2025-03-01 22:52:43 +08:00
|
|
|
cmd::create_webdav_backup,
|
|
|
|
|
cmd::save_webdav_config,
|
|
|
|
|
cmd::list_webdav_backup,
|
|
|
|
|
cmd::delete_webdav_backup,
|
|
|
|
|
cmd::restore_webdav_backup,
|
2025-03-03 05:58:12 +08:00
|
|
|
// export diagnostic info for issue reporting
|
|
|
|
|
cmd::export_diagnostic_info,
|
2025-03-14 13:31:34 +08:00
|
|
|
// get system info for display
|
|
|
|
|
cmd::get_system_info,
|
2025-03-16 12:15:35 +08:00
|
|
|
// media unlock checker
|
|
|
|
|
cmd::get_unlock_items,
|
|
|
|
|
cmd::check_media_unlock,
|
2025-03-20 03:23:14 +08:00
|
|
|
// light-weight model
|
|
|
|
|
cmd::entry_lightweight_mode,
|
2024-09-15 06:24:53 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
{
|
|
|
|
|
builder = builder.plugin(devtools);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-18 18:40:53 +08:00
|
|
|
// Macos Application Menu
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-03-20 18:14:18 +08:00
|
|
|
// Temporary Achived due to cannot CMD+C/V/A
|
2025-03-18 18:40:53 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-15 06:24:53 +08:00
|
|
|
let app = builder
|
|
|
|
|
.build(tauri::generate_context!())
|
|
|
|
|
.expect("error while running tauri application");
|
|
|
|
|
|
2025-03-01 18:29:40 +08:00
|
|
|
app.run(|app_handle, e| match e {
|
|
|
|
|
tauri::RunEvent::Ready | tauri::RunEvent::Resumed => {
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::System, true, "应用就绪或恢复");
|
2025-03-01 18:29:40 +08:00
|
|
|
AppHandleManager::global().init(app_handle.clone());
|
2025-03-03 02:27:45 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-03-20 15:43:52 +08:00
|
|
|
if let Some(window) = AppHandleManager::global()
|
2025-03-13 12:51:20 +08:00
|
|
|
.get_handle()
|
|
|
|
|
.get_webview_window("main")
|
2025-03-20 15:43:52 +08:00
|
|
|
{
|
2025-05-10 01:25:50 +08:00
|
|
|
logging!(info, Type::Window, true, "设置macOS窗口标题");
|
2025-03-20 15:43:52 +08:00
|
|
|
let _ = window.set_title("Clash Verge");
|
|
|
|
|
}
|
2025-03-03 02:27:45 +08:00
|
|
|
}
|
2025-03-01 18:29:40 +08:00
|
|
|
}
|
2025-03-01 19:52:42 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2025-03-13 12:51:20 +08:00
|
|
|
tauri::RunEvent::Reopen {
|
|
|
|
|
has_visible_windows,
|
|
|
|
|
..
|
|
|
|
|
} => {
|
2025-03-01 18:29:40 +08:00
|
|
|
if !has_visible_windows {
|
|
|
|
|
AppHandleManager::global().set_activation_policy_regular();
|
|
|
|
|
}
|
|
|
|
|
AppHandleManager::global().init(app_handle.clone());
|
|
|
|
|
}
|
2024-09-25 11:47:01 +08:00
|
|
|
tauri::RunEvent::ExitRequested { api, code, .. } => {
|
|
|
|
|
if code.is_none() {
|
|
|
|
|
api.prevent_exit();
|
|
|
|
|
}
|
2024-09-22 00:41:20 +08:00
|
|
|
}
|
2025-04-26 18:09:53 +08:00
|
|
|
tauri::RunEvent::Exit => {
|
|
|
|
|
// avoid duplicate cleanup
|
|
|
|
|
if core::handle::Handle::global().is_exiting() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
feat::clean();
|
|
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
|
|
|
|
if label == "main" {
|
|
|
|
|
match event {
|
2024-10-30 06:27:29 +08:00
|
|
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
2025-03-03 02:27:45 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
2025-03-01 18:29:40 +08:00
|
|
|
AppHandleManager::global().set_activation_policy_accessory();
|
2024-11-20 00:27:53 +08:00
|
|
|
if core::handle::Handle::global().is_exiting() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-16 21:03:45 +08:00
|
|
|
log::info!(target: "app", "closing window...");
|
2024-10-30 06:27:29 +08:00
|
|
|
api.prevent_close();
|
2025-05-10 01:25:50 +08:00
|
|
|
if let Some(window) = core::handle::Handle::global().get_window() {
|
|
|
|
|
let _ = window.hide();
|
|
|
|
|
} else {
|
|
|
|
|
logging!(warn, Type::Window, true, "尝试隐藏窗口但窗口不存在");
|
|
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
}
|
2024-09-18 15:16:43 +08:00
|
|
|
tauri::WindowEvent::Focused(true) => {
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().register("CMD+Q", "quit")
|
|
|
|
|
);
|
|
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().register("CMD+W", "hide")
|
|
|
|
|
);
|
2024-09-18 15:16:43 +08:00
|
|
|
}
|
2025-03-13 12:51:20 +08:00
|
|
|
{
|
|
|
|
|
let is_enable_global_hotkey = Config::verge()
|
2025-07-04 22:43:23 +08:00
|
|
|
.latest_ref()
|
2025-03-13 12:51:20 +08:00
|
|
|
.enable_global_hotkey
|
|
|
|
|
.unwrap_or(true);
|
2025-02-09 07:45:22 +08:00
|
|
|
if !is_enable_global_hotkey {
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(Type::Hotkey, true, hotkey::Hotkey::global().init())
|
2025-02-09 07:45:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-18 15:16:43 +08:00
|
|
|
}
|
2024-10-23 09:26:14 +08:00
|
|
|
tauri::WindowEvent::Focused(false) => {
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().unregister("CMD+Q")
|
|
|
|
|
);
|
|
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().unregister("CMD+W")
|
|
|
|
|
);
|
2024-10-23 09:26:14 +08:00
|
|
|
}
|
2025-03-13 12:51:20 +08:00
|
|
|
{
|
|
|
|
|
let is_enable_global_hotkey = Config::verge()
|
2025-07-04 22:43:23 +08:00
|
|
|
.latest_ref()
|
2025-03-13 12:51:20 +08:00
|
|
|
.enable_global_hotkey
|
|
|
|
|
.unwrap_or(true);
|
2025-02-09 07:45:22 +08:00
|
|
|
if !is_enable_global_hotkey {
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(Type::Hotkey, true, hotkey::Hotkey::global().reset())
|
2025-02-09 07:45:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 09:26:14 +08:00
|
|
|
}
|
2024-10-20 06:06:47 +08:00
|
|
|
tauri::WindowEvent::Destroyed => {
|
2024-09-18 15:16:43 +08:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
{
|
2025-03-28 03:39:21 +08:00
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().unregister("CMD+Q")
|
|
|
|
|
);
|
|
|
|
|
logging_error!(
|
|
|
|
|
Type::Hotkey,
|
|
|
|
|
true,
|
|
|
|
|
hotkey::Hotkey::global().unregister("CMD+W")
|
|
|
|
|
);
|
2024-09-18 15:16:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-15 06:24:53 +08:00
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
});
|
|
|
|
|
}
|