mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-21 05:25:45 +08:00
@@ -34,7 +34,7 @@ import { openUrl } from "@tauri-apps/plugin-opener";
|
|||||||
import TGLogger from "@utils/TGLogger.js";
|
import TGLogger from "@utils/TGLogger.js";
|
||||||
import { getWindowSize, resizeWindow } from "@utils/TGWindow.js";
|
import { getWindowSize, resizeWindow } from "@utils/TGWindow.js";
|
||||||
import { storeToRefs } from "pinia";
|
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";
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -53,7 +53,7 @@ let closeListener: UnlistenFn | null = null;
|
|||||||
let textScaleListener: UnlistenFn | null = null;
|
let textScaleListener: UnlistenFn | null = null;
|
||||||
let yaeFlag: Array<string> = [];
|
let yaeFlag: Array<string> = [];
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
onMounted(async () => {
|
||||||
const win = getCurrentWindow();
|
const win = getCurrentWindow();
|
||||||
isMain.value = win.label === "TeyvatGuide";
|
isMain.value = win.label === "TeyvatGuide";
|
||||||
if (isMain.value) {
|
if (isMain.value) {
|
||||||
|
|||||||
@@ -148,15 +148,19 @@ async function saveAccount(data: TGApp.App.Account.User): Promise<void> {
|
|||||||
async function updateAllAccountCk(): Promise<void> {
|
async function updateAllAccountCk(): Promise<void> {
|
||||||
const accounts = await getAllAccount();
|
const accounts = await getAllAccount();
|
||||||
const checkTime = 5 * 24 * 3600 * 1000;
|
const checkTime = 5 * 24 * 3600 * 1000;
|
||||||
|
let cnt = 0;
|
||||||
for (const account of accounts) {
|
for (const account of accounts) {
|
||||||
const diffTime = Date.now() - new Date(account.updated).getTime();
|
const diffTime = Date.now() - new Date(account.updated).getTime();
|
||||||
if (diffTime > checkTime) {
|
if (diffTime > checkTime) {
|
||||||
|
await TGLogger.Info(`更新${account.uid}Cookie,上次更新:${account.updated}`);
|
||||||
const update = await updateAccountCk(account);
|
const update = await updateAccountCk(account);
|
||||||
if (update) {
|
if (update) {
|
||||||
showSnackbar.success(`成功更新${account.uid}的Cookie`);
|
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());
|
const updated = timestampToDate(new Date().getTime());
|
||||||
await showLoading.update("正在写入数据库");
|
await showLoading.update("正在写入数据库");
|
||||||
const db = await TGSqlite.getDB();
|
const db = await TGSqlite.getDB();
|
||||||
await db.execute(
|
try {
|
||||||
"UPDATE UserAccount SET cookie = '?' AND brief = '?' AND updated = '?' WHERE uid = '?';",
|
// 让 SQLite 在遇到锁时等待(毫秒)
|
||||||
[JSON.stringify(ck), JSON.stringify(briefRes), updated, data.uid],
|
await db.execute("PRAGMA busy_timeout = 1000;");
|
||||||
);
|
// 立即获取写锁,减少中途被抢占的概率
|
||||||
return true;
|
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