diff --git a/src/App.vue b/src/App.vue index 07cfdea0..7e05a929 100644 --- a/src/App.vue +++ b/src/App.vue @@ -34,7 +34,7 @@ import { openUrl } from "@tauri-apps/plugin-opener"; import TGLogger from "@utils/TGLogger.js"; import { getWindowSize, resizeWindow } from "@utils/TGWindow.js"; import { storeToRefs } from "pinia"; -import { computed, nextTick, onBeforeMount, onUnmounted, ref } from "vue"; +import { computed, nextTick, onMounted, onUnmounted, ref } from "vue"; import { useRouter } from "vue-router"; const router = useRouter(); @@ -53,7 +53,7 @@ let closeListener: UnlistenFn | null = null; let textScaleListener: UnlistenFn | null = null; let yaeFlag: Array = []; -onBeforeMount(async () => { +onMounted(async () => { const win = getCurrentWindow(); isMain.value = win.label === "TeyvatGuide"; if (isMain.value) { diff --git a/src/plugins/Sqlite/modules/userAccount.ts b/src/plugins/Sqlite/modules/userAccount.ts index f329d004..c9255ffd 100644 --- a/src/plugins/Sqlite/modules/userAccount.ts +++ b/src/plugins/Sqlite/modules/userAccount.ts @@ -148,15 +148,19 @@ async function saveAccount(data: TGApp.App.Account.User): Promise { async function updateAllAccountCk(): Promise { const accounts = await getAllAccount(); const checkTime = 5 * 24 * 3600 * 1000; + let cnt = 0; for (const account of accounts) { const diffTime = Date.now() - new Date(account.updated).getTime(); if (diffTime > checkTime) { + await TGLogger.Info(`更新${account.uid}Cookie,上次更新:${account.updated}`); const update = await updateAccountCk(account); if (update) { showSnackbar.success(`成功更新${account.uid}的Cookie`); + cnt++; } } } + if (cnt > 0) await showLoading.end(); } /** @@ -199,11 +203,22 @@ async function updateAccountCk(data: TGApp.App.Account.User): Promise { const updated = timestampToDate(new Date().getTime()); await showLoading.update("正在写入数据库"); const db = await TGSqlite.getDB(); - await db.execute( - "UPDATE UserAccount SET cookie = '?' AND brief = '?' AND updated = '?' WHERE uid = '?';", - [JSON.stringify(ck), JSON.stringify(briefRes), updated, data.uid], - ); - return true; + try { + // 让 SQLite 在遇到锁时等待(毫秒) + await db.execute("PRAGMA busy_timeout = 1000;"); + // 立即获取写锁,减少中途被抢占的概率 + await db.execute("BEGIN IMMEDIATE;"); + await db.execute( + "UPDATE UserAccount SET cookie = '?' AND brief = '?' AND updated = '?' WHERE uid = '?';", + [JSON.stringify(ck), JSON.stringify(briefRes), updated, data.uid], + ); + await db.execute("COMMIT;"); + return true; + } catch (innerErr) { + await db.execute("ROLLBACK;"); + console.error(innerErr); + return false; + } } /**