mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-10 08:58:15 +08:00
🎨 优化 init_app 逻辑
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -168,9 +168,8 @@ async function initData(): Promise<void> {
|
||||
|
||||
async function getDeepLink(): Promise<void> {
|
||||
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<void> {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (e.payload === "") return;
|
||||
// 导入格式: teyvatguide://import_uigf?app=appName
|
||||
// 跳转格式: localhost:4000/achievements/?app=appName
|
||||
if (e.payload.startsWith("teyvatguide://import_uigf")) {
|
||||
|
||||
Reference in New Issue
Block a user