chore: deeplink uses the latest API

This commit is contained in:
huzibaca 2024-12-08 15:54:46 +08:00
parent ba8c1e5eb2
commit ba18e64be0
2 changed files with 13 additions and 25 deletions

View File

@ -6,9 +6,8 @@ mod feat;
mod utils; mod utils;
use crate::core::hotkey; use crate::core::hotkey;
use crate::utils::{resolve, resolve::resolve_scheme, server}; use crate::utils::{resolve, resolve::resolve_scheme, server};
#[cfg(target_os = "macos")]
use tauri::Listener;
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_deep_link::DeepLinkExt;
pub fn run() { pub fn run() {
// 单例检测 // 单例检测
@ -48,30 +47,22 @@ pub fn run() {
.plugin(tauri_plugin_deep_link::init()) .plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_window_state::Builder::default().build()) .plugin(tauri_plugin_window_state::Builder::default().build())
.setup(|app| { .setup(|app| {
#[cfg(target_os = "linux")] #[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
{ {
use tauri_plugin_deep_link::DeepLinkExt; use tauri_plugin_deep_link::DeepLinkExt;
log_err!(app.deep_link().register_all()); log_err!(app.deep_link().register_all());
} }
#[cfg(target_os = "macos")]
{ app.deep_link().on_open_url(|event| {
app.listen("deep-link://new-url", |event| {
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
let payload = event.payload(); if let Some(url) = event.urls().first() {
log_err!(resolve_scheme(payload.to_owned()).await); log_err!(resolve_scheme(url.to_string()).await);
});
});
} }
});
});
tauri::async_runtime::block_on(async move { tauri::async_runtime::block_on(async move {
resolve::resolve_setup(app).await; resolve::resolve_setup(app).await;
#[cfg(not(target_os = "macos"))]
{
let argvs: Vec<String> = std::env::args().collect();
if argvs.len() > 1 {
log_err!(resolve_scheme(argvs[1].to_owned()).await);
}
}
}); });
Ok(()) Ok(())
@ -86,7 +77,6 @@ pub fn run() {
cmds::open_core_dir, cmds::open_core_dir,
cmds::get_portable_flag, cmds::get_portable_flag,
cmds::get_network_interfaces, cmds::get_network_interfaces,
// cmds::kill_sidecar,
cmds::restart_core, cmds::restart_core,
cmds::restart_app, cmds::restart_app,
// clash // clash
@ -109,7 +99,6 @@ pub fn run() {
cmds::open_devtools, cmds::open_devtools,
cmds::exit_app, cmds::exit_app,
cmds::get_network_interfaces_info, cmds::get_network_interfaces_info,
// cmds::update_hotkeys,
// profile // profile
cmds::get_profiles, cmds::get_profiles,
cmds::enhance_profiles, cmds::enhance_profiles,

View File

@ -220,6 +220,8 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
Ok(item) => { Ok(item) => {
let uid = item.uid.clone().unwrap(); let uid = item.uid.clone().unwrap();
let _ = wrap_err!(Config::profiles().data().append_item(item)); let _ = wrap_err!(Config::profiles().data().append_item(item));
handle::Handle::notice_message("import_sub_url::ok", uid);
app_handle app_handle
.notification() .notification()
.builder() .builder()
@ -227,10 +229,9 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
.body("Import profile success") .body("Import profile success")
.show() .show()
.unwrap(); .unwrap();
handle::Handle::notice_message("import_sub_url::ok", uid);
} }
Err(e) => { Err(e) => {
handle::Handle::notice_message("import_sub_url::error", e.to_string());
app_handle app_handle
.notification() .notification()
.builder() .builder()
@ -238,8 +239,6 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
.body(format!("Import profile failed: {e}")) .body(format!("Import profile failed: {e}"))
.show() .show()
.unwrap(); .unwrap();
handle::Handle::notice_message("import_sub_url::error", e.to_string());
bail!("Failed to add subscriptions: {e}");
} }
} }
} }