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;
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| {
app.deep_link().on_open_url(|event| {
tauri::async_runtime::spawn(async move {
let payload = event.payload();
log_err!(resolve_scheme(payload.to_owned()).await);
});
});
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<String> = 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,

View File

@ -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}");
}
}
}