From 90eb4facf9410ce6e318ae12f812e9edd0179f55 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 27 Dec 2025 14:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E7=A7=BB=E9=99=A4isInAdmi?= =?UTF-8?q?n=E7=9A=84store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 9 +-------- src/components/app/t-sidebar.vue | 6 ++++-- src/pages/common/PageAchi.vue | 6 ++++-- src/pages/common/PageBagMaterial.vue | 6 ++++-- src/store/modules/app.ts | 3 --- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7ca33149..ddd6f50a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -31,13 +31,12 @@ import { openUrl } from "@tauri-apps/plugin-opener"; import { getBuildTime } from "@utils/TGBuild.js"; import TGLogger from "@utils/TGLogger.js"; import { getWindowSize, resizeWindow } from "@utils/TGWindow.js"; -import { isRunInAdmin } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; import { computed, nextTick, onMounted, onUnmounted, ref } from "vue"; import { useRouter } from "vue-router"; const router = useRouter(); -const { theme, needResize, deviceInfo, isLogin, userDir, buildTime, closeToTray, isInAdmin } = +const { theme, needResize, deviceInfo, isLogin, userDir, buildTime, closeToTray } = storeToRefs(useAppStore()); const { uid, briefInfo, account, cookie } = storeToRefs(useUserStore()); @@ -63,7 +62,6 @@ onMounted(async () => { yaeListener = await event.listen("yae_read", handleYaeListen); closeListener = await event.listen("main-window-close-requested", handleWindowClose); await nextTick(); - if (isInAdmin.value) await win.setTitle(`${title} - AdminMode`); } if (needResize.value !== "false") await resizeWindow(); document.documentElement.className = theme.value; @@ -228,7 +226,6 @@ async function handleResizeListen(event: Event): Promise { async function listenOnInit(): Promise { console.info("[App][listenOnInit] 监听初始化事件!"); await event.listen("initApp", async () => { - await checkIsAdmin(); await checkAppLoad(); await checkDeviceFp(); try { @@ -242,10 +239,6 @@ async function listenOnInit(): Promise { }); } -async function checkIsAdmin(): Promise { - isInAdmin.value = await isRunInAdmin(); -} - async function checkAppLoad(): Promise { let checkDB = false; try { diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index ea24df2c..42251c3c 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -317,11 +317,12 @@ import { exists } from "@tauri-apps/plugin-fs"; import { Command } from "@tauri-apps/plugin-shell"; import mhyClient from "@utils/TGClient.js"; import TGLogger from "@utils/TGLogger.js"; +import { isRunInAdmin } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue"; const userStore = useUserStore(); -const { sidebar, theme, isLogin, recentNewsType, gameDir, isInAdmin } = storeToRefs(useAppStore()); +const { sidebar, theme, isLogin, recentNewsType, gameDir } = storeToRefs(useAppStore()); const { uid, briefInfo, cookie, account } = storeToRefs(userStore); let themeListener: UnlistenFn | null = null; // @ts-expect-error The import.meta meta-property is not allowed in files which will build into CommonJS output. @@ -720,7 +721,8 @@ async function tryLaunchGame(): Promise { await TGLogger.Error(`[sidebar][tryLaunchGame] resp: ${JSON.stringify(resp)}`); return; } - if (!isInAdmin.value) { + const isInAdmin = await isRunInAdmin(); + if (!isInAdmin) { showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`); const cmd = Command.create("exec-sh", [`&"${gamePath}" login_auth_ticket=${resp}`], { cwd: gameDir.value, diff --git a/src/pages/common/PageAchi.vue b/src/pages/common/PageAchi.vue index 6cc9554d..b72afe64 100644 --- a/src/pages/common/PageAchi.vue +++ b/src/pages/common/PageAchi.vue @@ -99,6 +99,7 @@ import { open, save } from "@tauri-apps/plugin-dialog"; import { exists, writeTextFile } from "@tauri-apps/plugin-fs"; import { platform } from "@tauri-apps/plugin-os"; import TGLogger from "@utils/TGLogger.js"; +import { isRunInAdmin } from "@utils/toolFunc.js"; import { getUiafHeader, readUiafData, @@ -115,7 +116,7 @@ const seriesList = AppAchievementSeriesData.sort((a, b) => a.order - b.order).ma const route = useRoute(); const router = useRouter(); -const { gameDir, isInAdmin, isLogin } = storeToRefs(useAppStore()); +const { gameDir, isLogin } = storeToRefs(useAppStore()); const { account } = storeToRefs(useUserStore()); let achiListener: UnlistenFn | null = null; @@ -327,7 +328,8 @@ async function toYae(): Promise { showSnackbar.warn("未检测到原神本体应用!"); return; } - if (!isInAdmin.value) { + const isInAdmin = await isRunInAdmin(); + if (!isInAdmin) { const check = await showDialog.check("是否以管理员模式重启?", "该功能需要管理员权限才能使用"); if (!check) { showSnackbar.cancel("已取消以管理员模式重启"); diff --git a/src/pages/common/PageBagMaterial.vue b/src/pages/common/PageBagMaterial.vue index ffc60aba..e6855bb2 100644 --- a/src/pages/common/PageBagMaterial.vue +++ b/src/pages/common/PageBagMaterial.vue @@ -126,6 +126,7 @@ import { invoke } from "@tauri-apps/api/core"; import { exists } from "@tauri-apps/plugin-fs"; import { platform } from "@tauri-apps/plugin-os"; import TGLogger from "@utils/TGLogger.js"; +import { isRunInAdmin } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; import { nextTick, onMounted, ref, shallowRef, triggerRef, watch } from "vue"; @@ -165,7 +166,7 @@ export type MaterialInfo = { info: TGApp.App.Material.WikiItem; }; -const { gameDir, isInAdmin, isLogin } = storeToRefs(useAppStore()); +const { gameDir, isLogin } = storeToRefs(useAppStore()); const { account } = storeToRefs(useUserStore()); const sortList: Array = [ @@ -347,7 +348,8 @@ async function tryCallYae(): Promise { showSnackbar.warn("未检测到原神本体应用!"); return; } - if (!isInAdmin.value) { + const isInAdmin = await isRunInAdmin(); + if (!isInAdmin) { const check = await showDialog.check("是否以管理员模式重启?", "该功能需要管理员权限才能使用"); if (!check) { showSnackbar.cancel("已取消以管理员模式重启"); diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index 9e9d9446..d6ab19f5 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -65,8 +65,6 @@ const useAppStore = defineStore( const cancelLike = ref(true); /** 关闭窗口时最小化到托盘 */ const closeToTray = ref(false); - /** 是否是管理员模式 */ - const isInAdmin = ref(false); /** * 初始化应用状态 @@ -150,7 +148,6 @@ const useAppStore = defineStore( init, changeTheme, getImageUrl, - isInAdmin, }; }, {