diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 73934f64..62602921 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6,9 +6,8 @@ mod feat; mod utils; use crate::core::hotkey; use crate::utils::{resolve, resolve::resolve_scheme, server}; -#[cfg(target_os = "macos")] -use tauri::Listener; use tauri_plugin_autostart::MacosLauncher; +use tauri_plugin_deep_link::DeepLinkExt; pub fn run() { // 单例检测 @@ -48,30 +47,22 @@ pub fn run() { .plugin(tauri_plugin_deep_link::init()) .plugin(tauri_plugin_window_state::Builder::default().build()) .setup(|app| { - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "linux", all(debug_assertions, windows)))] { use tauri_plugin_deep_link::DeepLinkExt; log_err!(app.deep_link().register_all()); } - #[cfg(target_os = "macos")] - { - app.listen("deep-link://new-url", |event| { - tauri::async_runtime::spawn(async move { - let payload = event.payload(); - log_err!(resolve_scheme(payload.to_owned()).await); - }); + + app.deep_link().on_open_url(|event| { + tauri::async_runtime::spawn(async move { + if let Some(url) = event.urls().first() { + log_err!(resolve_scheme(url.to_string()).await); + } }); - } + }); + tauri::async_runtime::block_on(async move { resolve::resolve_setup(app).await; - - #[cfg(not(target_os = "macos"))] - { - let argvs: Vec = std::env::args().collect(); - if argvs.len() > 1 { - log_err!(resolve_scheme(argvs[1].to_owned()).await); - } - } }); Ok(()) @@ -86,7 +77,6 @@ pub fn run() { cmds::open_core_dir, cmds::get_portable_flag, cmds::get_network_interfaces, - // cmds::kill_sidecar, cmds::restart_core, cmds::restart_app, // clash @@ -109,7 +99,6 @@ pub fn run() { cmds::open_devtools, cmds::exit_app, cmds::get_network_interfaces_info, - // cmds::update_hotkeys, // profile cmds::get_profiles, cmds::enhance_profiles, diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index af1b7e73..86f5a1e6 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -220,6 +220,8 @@ pub async fn resolve_scheme(param: String) -> Result<()> { Ok(item) => { let uid = item.uid.clone().unwrap(); let _ = wrap_err!(Config::profiles().data().append_item(item)); + handle::Handle::notice_message("import_sub_url::ok", uid); + app_handle .notification() .builder() @@ -227,10 +229,9 @@ pub async fn resolve_scheme(param: String) -> Result<()> { .body("Import profile success") .show() .unwrap(); - - handle::Handle::notice_message("import_sub_url::ok", uid); } Err(e) => { + handle::Handle::notice_message("import_sub_url::error", e.to_string()); app_handle .notification() .builder() @@ -238,8 +239,6 @@ pub async fn resolve_scheme(param: String) -> Result<()> { .body(format!("Import profile failed: {e}")) .show() .unwrap(); - handle::Handle::notice_message("import_sub_url::error", e.to_string()); - bail!("Failed to add subscriptions: {e}"); } } }