🎨 优化 init_app 逻辑

This commit is contained in:
BTMuli
2023-10-11 20:34:30 +08:00
parent adc96b7649
commit 74320f0e9a
2 changed files with 14 additions and 3 deletions

View File

@@ -5,11 +5,13 @@ use tauri::Manager;
// 放一个常数,用来判断应用是否初始化 // 放一个常数,用来判断应用是否初始化
static mut APP_INITIALIZED: bool = false; static mut APP_INITIALIZED: bool = false;
static mut DEEP_LINK_REGISTERED: bool = false;
#[tauri::command] #[tauri::command]
async fn init_app(app_handle: tauri::AppHandle) { async fn init_app(app_handle: tauri::AppHandle) {
dbg!("init_app");
unsafe { unsafe {
if APP_INITIALIZED { if APP_INITIALIZED == true && DEEP_LINK_REGISTERED == true {
return; return;
} }
} }
@@ -21,6 +23,12 @@ async fn init_app(app_handle: tauri::AppHandle) {
#[tauri::command] #[tauri::command]
async fn register_deep_link(app_handle: tauri::AppHandle) { 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( tauri_plugin_deep_link::register(
"teyvatguide", "teyvatguide",
move |request| { move |request| {
@@ -29,6 +37,9 @@ async fn register_deep_link(app_handle: tauri::AppHandle) {
}, },
) )
.unwrap(); .unwrap();
unsafe {
DEEP_LINK_REGISTERED = true;
}
} }
fn main() { fn main() {

View File

@@ -168,9 +168,8 @@ async function initData(): Promise<void> {
async function getDeepLink(): Promise<void> { async function getDeepLink(): Promise<void> {
await event.listen("active_deep_link", (e) => { await event.listen("active_deep_link", (e) => {
console.log(e.payload);
new TauriWindow.WebviewWindow("TeyvatGuide") new TauriWindow.WebviewWindow("TeyvatGuide")
.center() .setFocus()
.then(async () => { .then(async () => {
if (typeof e.payload !== "string") { if (typeof e.payload !== "string") {
showSnackbar({ showSnackbar({
@@ -180,6 +179,7 @@ async function getDeepLink(): Promise<void> {
}); });
return; return;
} }
if (e.payload === "") return;
// 导入格式: teyvatguide://import_uigf?app=appName // 导入格式: teyvatguide://import_uigf?app=appName
// 跳转格式: localhost:4000/achievements/?app=appName // 跳转格式: localhost:4000/achievements/?app=appName
if (e.payload.startsWith("teyvatguide://import_uigf")) { if (e.payload.startsWith("teyvatguide://import_uigf")) {