diff --git a/src/App.vue b/src/App.vue index 1596194a..ad17c24f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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(false); @@ -64,6 +65,7 @@ async function listenOnInit(): Promise { 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 { } } +// 检测 deviceFp +async function checkDeviceFp(): Promise { + 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 { const ckDB = await TGSqlite.getCookie(); diff --git a/src/pages/common/Config.vue b/src/pages/common/Config.vue index 7b5c67fb..44e19da6 100644 --- a/src/pages/common/Config.vue +++ b/src/pages/common/Config.vue @@ -490,6 +490,7 @@ async function confirmUpdateDevice(): Promise { showSnackbar({ text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp, }); + await TGSqlite.saveAppData("deviceInfo", JSON.stringify(appStore.deviceInfo)); } // 清除用户缓存 diff --git a/src/types/Sqlite/AppData.d.ts b/src/types/Sqlite/AppData.d.ts index 100b6279..d157cce4 100644 --- a/src/types/Sqlite/AppData.d.ts +++ b/src/types/Sqlite/AppData.d.ts @@ -1,18 +1,19 @@ /** - * @file types Sqlite AppData.d.ts + * @file types/Sqlite/AppData.d.ts * @description Sqlite AppData 类型定义文件 - * @since Beta v0.3.3 + * @since Beta v0.3.8 */ declare namespace TGApp.Sqlite.AppData { /** * @description AppData 数据库 - key 枚举 - * @since Beta v0.3.3 + * @since Beta v0.3.8 * @enum {string} * @property {string} APP_VERSION - App 版本 * @property {string} DATA_UPDATED - 数据库更新时间 * @property {string} COOKIE - Cookie * @property {string} USER_INFO - 用户信息 + * @property {string} DEVICE_INFO - 设备信息 * @return {string} */ enum DBKey { @@ -20,6 +21,7 @@ declare namespace TGApp.Sqlite.AppData { DATA_UPDATED = "dataUpdated", COOKIE = "cookie", USER_INFO = "userInfo", + DEVICE_INFO = "deviceInfo", } /**