mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-26 05:39:45 +08:00
@@ -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<string> = [];
|
||||
|
||||
onBeforeMount(async () => {
|
||||
onMounted(async () => {
|
||||
const win = getCurrentWindow();
|
||||
isMain.value = win.label === "TeyvatGuide";
|
||||
if (isMain.value) {
|
||||
|
||||
@@ -148,15 +148,19 @@ async function saveAccount(data: TGApp.App.Account.User): Promise<void> {
|
||||
async function updateAllAccountCk(): Promise<void> {
|
||||
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<boolean> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user