♻️ 调整窗口显示逻辑

This commit is contained in:
目棃
2024-12-07 19:13:32 +08:00
parent c7f24d2345
commit d5ec4b1b0e
3 changed files with 37 additions and 41 deletions

View File

@@ -3,9 +3,7 @@
<TSidebar v-if="isMain" /> <TSidebar v-if="isMain" />
<v-main> <v-main>
<v-container :fluid="true" class="app-container"> <v-container :fluid="true" class="app-container">
<Suspense> <router-view />
<router-view />
</Suspense>
</v-container> </v-container>
</v-main> </v-main>
<TBackTop /> <TBackTop />
@@ -13,9 +11,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { app, core, event, webviewWindow, window as TauriWindow } from "@tauri-apps/api"; import { app, core, event, webviewWindow } from "@tauri-apps/api";
import { PhysicalSize } from "@tauri-apps/api/dpi"; import { PhysicalSize } from "@tauri-apps/api/dpi";
import { Event, UnlistenFn } from "@tauri-apps/api/event"; import { Event, UnlistenFn } from "@tauri-apps/api/event";
import { currentMonitor, getCurrentWindow } from "@tauri-apps/api/window";
import { mkdir } from "@tauri-apps/plugin-fs"; import { mkdir } from "@tauri-apps/plugin-fs";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue"; import { computed, onBeforeMount, onMounted, onUnmounted, ref } from "vue";
@@ -33,18 +32,17 @@ import { getBuildTime } from "./utils/TGBuild.js";
import TGLogger from "./utils/TGLogger.js"; import TGLogger from "./utils/TGLogger.js";
import OtherApi from "./web/request/otherReq.js"; import OtherApi from "./web/request/otherReq.js";
const appStore = useAppStore();
const router = useRouter(); const router = useRouter();
const { theme, needResize, deviceInfo, isLogin, userDir, buildTime } = storeToRefs(useAppStore());
const { uid, briefInfo, account, cookie } = storeToRefs(useUserStore()); const { uid, briefInfo, account, cookie } = storeToRefs(useUserStore());
const isMain = ref<boolean>(false); const isMain = ref<boolean>(false);
const theme = ref<string>(appStore.theme); const vuetifyTheme = computed<string>(() => (theme.value === "dark" ? "dark" : "light"));
const vuetifyTheme = computed<string>(() => (appStore.theme === "dark" ? "dark" : "light"));
let themeListener: UnlistenFn | null = null; let themeListener: UnlistenFn | null = null;
let urlListener: UnlistenFn | null = null; let urlListener: UnlistenFn | null = null;
onBeforeMount(async () => { onBeforeMount(async () => {
const win = webviewWindow.getCurrentWebviewWindow(); const win = getCurrentWindow();
isMain.value = win.label === "TeyvatGuide"; isMain.value = win.label === "TeyvatGuide";
if (isMain.value) { if (isMain.value) {
const title = "Teyvat Guide v" + (await app.getVersion()) + " Beta"; const title = "Teyvat Guide v" + (await app.getVersion()) + " Beta";
@@ -53,17 +51,28 @@ onBeforeMount(async () => {
await core.invoke("init_app"); await core.invoke("init_app");
urlListener = await getDeepLink(); urlListener = await getDeepLink();
} }
if (appStore.needResize !== "false") await checkResize(); if (needResize.value !== "false") await checkResize();
await win.show(); document.documentElement.className = theme.value;
});
onMounted(async () => {
await getCurrentWindow().show();
themeListener = await event.listen("readTheme", async (e: Event<string>) => {
const themeGet = e.payload;
if (theme.value !== themeGet) {
theme.value = themeGet;
document.documentElement.className = theme.value;
}
});
}); });
async function checkResize(): Promise<void> { async function checkResize(): Promise<void> {
const screen = await TauriWindow.currentMonitor(); const screen = await currentMonitor();
if (screen === null) { if (screen === null) {
showSnackbar.error("获取屏幕信息失败!", 3000); showSnackbar.error("获取屏幕信息失败!", 3000);
return; return;
} }
const windowCur = await webviewWindow.getCurrentWebviewWindow(); const windowCur = webviewWindow.getCurrentWebviewWindow();
if (await windowCur.isMaximized()) return; if (await windowCur.isMaximized()) return;
const designSize = getSize(windowCur.label); const designSize = getSize(windowCur.label);
const widthScale = screen.size.width / 1920; const widthScale = screen.size.width / 1920;
@@ -85,17 +94,6 @@ function getSize(label: string): PhysicalSize {
return new PhysicalSize(1280, 720); return new PhysicalSize(1280, 720);
} }
onMounted(async () => {
document.documentElement.className = theme.value;
themeListener = await event.listen("readTheme", async (e: Event<string>) => {
const themeGet = e.payload;
if (theme.value !== themeGet) {
theme.value = themeGet;
document.documentElement.className = theme.value;
}
});
});
// 启动后只执行一次的监听 // 启动后只执行一次的监听
function listenOnInit(): void { function listenOnInit(): void {
console.info("[App][listenOnInit] 监听初始化事件!"); console.info("[App][listenOnInit] 监听初始化事件!");
@@ -129,35 +127,34 @@ async function checkAppLoad(): Promise<void> {
// 检测 deviceFp // 检测 deviceFp
async function checkDeviceFp(): Promise<void> { async function checkDeviceFp(): Promise<void> {
const appData = await TGSqlite.getAppData(); const appData = await TGSqlite.getAppData();
const deviceLocal = appStore.deviceInfo;
const deviceFind = appData.find((item) => item.key === "deviceInfo"); const deviceFind = appData.find((item) => item.key === "deviceInfo");
if (typeof deviceFind === "undefined") { if (typeof deviceFind === "undefined") {
if (deviceLocal.device_fp === "0000000000000") { if (deviceInfo.value.device_fp === "0000000000000") {
appStore.deviceInfo = await OtherApi.fp(appStore.deviceInfo); deviceInfo.value = await OtherApi.fp(deviceInfo.value);
} }
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(deviceLocal)); await TGSqlite.saveAppData("deviceInfo", JSON.stringify(deviceInfo.value));
return; return;
} }
if (JSON.parse(deviceFind.value) !== deviceLocal) { if (JSON.parse(deviceFind.value) !== deviceInfo.value) {
appStore.deviceInfo = JSON.parse(deviceFind.value); deviceInfo.value = JSON.parse(deviceFind.value);
} }
} }
async function checkUserLoad(): Promise<void> { async function checkUserLoad(): Promise<void> {
// 检测用户数据目录 // 检测用户数据目录
const appData = await TGSqlite.getAppData(); const appData = await TGSqlite.getAppData();
const userDir = appData.find((item) => item.key === "userDir")?.value; const userDirGet = appData.find((item) => item.key === "userDir")?.value;
if (typeof userDir === "undefined") await TGSqlite.saveAppData("userDir", appStore.userDir); if (typeof userDirGet === "undefined") await TGSqlite.saveAppData("userDir", userDir.value);
else if (userDir !== appStore.userDir) appStore.userDir = userDir; else if (userDirGet !== userDir.value) userDir.value = userDirGet;
await mkdir(appStore.userDir, { recursive: true }); await mkdir(userDir.value, { recursive: true });
// 检测用户数据 // 检测用户数据
const uidDB = await TSUserAccount.account.getAllUid(); const uidDB = await TSUserAccount.account.getAllUid();
if (uidDB.length === 0 && appStore.isLogin) { if (uidDB.length === 0 && isLogin.value) {
showSnackbar.warn("未检测到可用UID请重新登录"); showSnackbar.warn("未检测到可用UID请重新登录");
appStore.isLogin = false; isLogin.value = false;
return; return;
} }
if (!appStore.isLogin) appStore.isLogin = true; if (!isLogin.value) isLogin.value = true;
// 然后获取最近的UID // 然后获取最近的UID
if (uid.value === undefined || !uidDB.includes(uid.value)) { if (uid.value === undefined || !uidDB.includes(uid.value)) {
uid.value = uidDB[0]; uid.value = uidDB[0];
@@ -252,7 +249,7 @@ async function checkUpdate(): Promise<void> {
showSnackbar.error("请到设置页手动更新数据库!", 3000); showSnackbar.error("请到设置页手动更新数据库!", 3000);
return; return;
} }
appStore.buildTime = getBuildTime(); buildTime.value = getBuildTime();
await TGSqlite.update(); await TGSqlite.update();
showSnackbar.success("数据库已更新!", 3000); showSnackbar.success("数据库已更新!", 3000);
window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html"); window.open("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");

View File

@@ -66,9 +66,7 @@ export async function createPost(
} }
const postPath = `/post_detail/${postId}`; const postPath = `/post_detail/${postId}`;
await createTGWindow(postPath, "Sub_window", postTitle, 960, 720, false, false); await createTGWindow(postPath, "Sub_window", postTitle, 960, 720, false, false);
TGLogger.Info(`[createPost][${postId}] 打开帖子`).catch((err) => { await TGLogger.Info(`[createPost][${postId}] 打开帖子`);
console.error(err);
});
} }
/** /**

View File

@@ -105,7 +105,7 @@ import TGLogger from "../utils/TGLogger.js";
import { createTGWindow } from "../utils/TGWindow.js"; import { createTGWindow } from "../utils/TGWindow.js";
import TGConstant from "../web/constant/TGConstant.js"; import TGConstant from "../web/constant/TGConstant.js";
const appVersion = await app.getVersion(); const appVersion = ref<string>();
const postId = Number(useRoute().params.post_id); const postId = Number(useRoute().params.post_id);
const showCollection = ref<boolean>(false); const showCollection = ref<boolean>(false);
const shareTime = ref<number>(Math.floor(Date.now() / 1000)); const shareTime = ref<number>(Math.floor(Date.now() / 1000));
@@ -121,6 +121,7 @@ function getGameIcon(gameId: number): string {
} }
onMounted(async () => { onMounted(async () => {
appVersion.value = await app.getVersion();
showLoading.start(`正在加载帖子数据...`); showLoading.start(`正在加载帖子数据...`);
// 检查数据 // 检查数据
if (!postId) { if (!postId) {