deviceInfo 保存到数据库

This commit is contained in:
BTMuli
2023-12-14 21:44:23 +08:00
parent 3844e36fdb
commit 3337cfbf6d
3 changed files with 29 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ import TGSqlite from "./plugins/Sqlite";
import { useAppStore } from "./store/modules/app";
import { useUserStore } from "./store/modules/user";
import { getBuildTime } from "./utils/TGBuild";
import TGRequest from "./web/request/TGRequest";
const appStore = useAppStore();
const isMain = ref<boolean>(false);
@@ -64,6 +65,7 @@ async function listenOnInit(): Promise<void> {
await tauri.invoke("register_deep_link");
await getDeepLink();
await checkAppLoad();
await checkDeviceFp();
try {
await checkUserLoad();
} catch (error) {
@@ -94,6 +96,27 @@ async function checkAppLoad(): Promise<void> {
}
}
// 检测 deviceFp
async function checkDeviceFp(): Promise<void> {
const appData = await TGSqlite.getAppData();
const deviceInfo = appData.find((item) => item.key === "deviceInfo")?.value;
const deviceLocal = appStore.deviceInfo;
if (deviceInfo === undefined) {
if (deviceLocal.device_fp === "0000000000000") {
// 获取 deviceFp
appStore.deviceInfo = await TGRequest.Device.getFp(appStore.deviceInfo);
console.info("deviceInfo 已重新获取!");
}
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(deviceLocal));
console.info("deviceInfo 数据已插入!");
} else if (JSON.parse(deviceInfo) !== deviceLocal) {
appStore.deviceInfo = JSON.parse(deviceInfo);
console.info("deviceInfo 数据已加载!");
} else {
console.info("deviceInfo 数据已同步!");
}
}
// 检测 ck,info 数据
async function checkUserLoad(): Promise<void> {
const ckDB = await TGSqlite.getCookie();