diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 37dc5492..b6e76dd7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -5,11 +5,13 @@ use tauri::Manager; // 放一个常数,用来判断应用是否初始化 static mut APP_INITIALIZED: bool = false; +static mut DEEP_LINK_REGISTERED: bool = false; #[tauri::command] async fn init_app(app_handle: tauri::AppHandle) { + dbg!("init_app"); unsafe { - if APP_INITIALIZED { + if APP_INITIALIZED == true && DEEP_LINK_REGISTERED == true { return; } } @@ -21,6 +23,12 @@ async fn init_app(app_handle: tauri::AppHandle) { #[tauri::command] async fn register_deep_link(app_handle: tauri::AppHandle) { + dbg!("register_deep_link"); + unsafe { + if DEEP_LINK_REGISTERED == true { + return; + } + } tauri_plugin_deep_link::register( "teyvatguide", move |request| { @@ -29,6 +37,9 @@ async fn register_deep_link(app_handle: tauri::AppHandle) { }, ) .unwrap(); + unsafe { + DEEP_LINK_REGISTERED = true; + } } fn main() { diff --git a/src/App.vue b/src/App.vue index 6f29c440..d6ee3707 100644 --- a/src/App.vue +++ b/src/App.vue @@ -168,9 +168,8 @@ async function initData(): Promise { async function getDeepLink(): Promise { await event.listen("active_deep_link", (e) => { - console.log(e.payload); new TauriWindow.WebviewWindow("TeyvatGuide") - .center() + .setFocus() .then(async () => { if (typeof e.payload !== "string") { showSnackbar({ @@ -180,6 +179,7 @@ async function getDeepLink(): Promise { }); return; } + if (e.payload === "") return; // 导入格式: teyvatguide://import_uigf?app=appName // 跳转格式: localhost:4000/achievements/?app=appName if (e.payload.startsWith("teyvatguide://import_uigf")) {