🐛 修复外部唤起失效

This commit is contained in:
目棃
2024-02-02 17:29:27 +08:00
parent 8f8056622c
commit 7120745211
2 changed files with 9 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { app, event, fs, tauri, window as TauriWindow } from "@tauri-apps/api"; import { app, event, fs, tauri, window as TauriWindow } from "@tauri-apps/api";
import { UnlistenFn } from "@tauri-apps/api/helpers/event";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue"; import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
@@ -36,7 +37,8 @@ const vuetifyTheme = computed(() => {
return appStore.theme === "dark" ? "dark" : "light"; return appStore.theme === "dark" ? "dark" : "light";
}); });
let themeListener: () => void; let themeListener: UnlistenFn;
let urlListener: UnlistenFn;
onBeforeMount(async () => { onBeforeMount(async () => {
const win = TauriWindow.getCurrent(); const win = TauriWindow.getCurrent();
@@ -46,6 +48,7 @@ onBeforeMount(async () => {
await win.setTitle(title); await win.setTitle(title);
await listenOnInit(); await listenOnInit();
await tauri.invoke("init_app"); await tauri.invoke("init_app");
urlListener = await getDeepLink();
} }
}); });
@@ -64,7 +67,6 @@ onMounted(async () => {
async function listenOnInit(): Promise<void> { async function listenOnInit(): Promise<void> {
await event.listen("initApp", async () => { await event.listen("initApp", async () => {
await tauri.invoke("register_deep_link"); await tauri.invoke("register_deep_link");
await getDeepLink();
await checkAppLoad(); await checkAppLoad();
await checkDeviceFp(); await checkDeviceFp();
try { try {
@@ -164,8 +166,8 @@ async function checkUserLoad(): Promise<void> {
await fs.createDir(appStore.userDir, { recursive: true }); await fs.createDir(appStore.userDir, { recursive: true });
} }
async function getDeepLink(): Promise<void> { async function getDeepLink(): Promise<UnlistenFn> {
await event.listen("active_deep_link", async (e) => { return await event.listen("active_deep_link", async (e) => {
const windowGet = new TauriWindow.WebviewWindow("TeyvatGuide"); const windowGet = new TauriWindow.WebviewWindow("TeyvatGuide");
if (await windowGet.isMinimized()) { if (await windowGet.isMinimized()) {
await windowGet.unminimize(); await windowGet.unminimize();
@@ -229,7 +231,8 @@ async function checkUpdate(): Promise<void> {
} }
onUnmounted(() => { onUnmounted(() => {
themeListener(); if (themeListener) themeListener();
if (urlListener) urlListener();
}); });
</script> </script>
<style lang="css"> <style lang="css">

View File

@@ -172,7 +172,7 @@ async function switchHideFin() {
}); });
if (!res) { if (!res) {
showSnackbar({ showSnackbar({
color: "warn", color: "cancel",
text: "已取消切换", text: "已取消切换",
}); });
return; return;