From 7b76432b1ec8c786f3e4b066d33a30496d2459cb Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sun, 15 Oct 2023 17:34:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BC=B9=E7=AA=97=E6=9C=BA=E5=88=B6=20#45?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/Home.vue | 4 +++- src/plugins/Sqlite/index.ts | 14 ++++++++++++++ src/types/Sqlite/AppData.d.ts | 26 +++++++++++++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/pages/common/Home.vue b/src/pages/common/Home.vue index 9377d95e..48d02529 100644 --- a/src/pages/common/Home.vue +++ b/src/pages/common/Home.vue @@ -13,6 +13,7 @@ import TCalendar from "../../components/home/t-calendar.vue"; import TPool from "../../components/home/t-pool.vue"; import TPosition from "../../components/home/t-position.vue"; import ToLoading from "../../components/overlay/to-loading.vue"; +import TGSqlite from "../../plugins/Sqlite"; import { useAppStore } from "../../store/modules/app"; import { useHomeStore } from "../../store/modules/home"; import { getBuildTime } from "../../utils/TGBuild"; @@ -68,7 +69,8 @@ onMounted(async () => { }), ); timer.value = setInterval(readLoading, 100); - if (appStore.buildTime !== getBuildTime() && isProdEnv) { + const needUpdate = await TGSqlite.checkUpdate(); + if (needUpdate && isProdEnv) { const confirm = await showConfirm({ title: "检测到版本更新", text: "请到设置页手动更新版本,即将弹出更新说明子页面", diff --git a/src/plugins/Sqlite/index.ts b/src/plugins/Sqlite/index.ts index 4ec03598..565c8a82 100644 --- a/src/plugins/Sqlite/index.ts +++ b/src/plugins/Sqlite/index.ts @@ -4,6 +4,7 @@ * @since Beta v0.3.3 */ +import { app } from "@tauri-apps/api"; import Database from "tauri-plugin-sql-api"; import initDataSql from "./sql/initData"; @@ -87,6 +88,19 @@ class Sqlite { return await db.select(sql); } + /** + * @description 对比数据判断是否需要更新 + * @since Beta v0.3.3 + * @returns {Promise} + */ + public async checkUpdate(): Promise { + const dbData = await this.getAppData(); + const localVersion = await app.getVersion(); + const dbVersion = dbData.find((item) => item.key === "appVersion")?.value; + if (dbVersion === undefined) return true; + return localVersion !== dbVersion; + } + /** * @description 获取 cookie * @since Beta v0.3.3 diff --git a/src/types/Sqlite/AppData.d.ts b/src/types/Sqlite/AppData.d.ts index 152e789d..100b6279 100644 --- a/src/types/Sqlite/AppData.d.ts +++ b/src/types/Sqlite/AppData.d.ts @@ -1,22 +1,38 @@ /** * @file types Sqlite AppData.d.ts * @description Sqlite AppData 类型定义文件 - * @author BTMuli - * @since Alpha v0.1.5 + * @since Beta v0.3.3 */ declare namespace TGApp.Sqlite.AppData { + /** + * @description AppData 数据库 - key 枚举 + * @since Beta v0.3.3 + * @enum {string} + * @property {string} APP_VERSION - App 版本 + * @property {string} DATA_UPDATED - 数据库更新时间 + * @property {string} COOKIE - Cookie + * @property {string} USER_INFO - 用户信息 + * @return {string} + */ + enum DBKey { + APP_VERSION = "appVersion", + DATA_UPDATED = "dataUpdated", + COOKIE = "cookie", + USER_INFO = "userInfo", + } + /** * @description AppData 数据 - * @since Alpha v0.1.5 + * @since Beta v0.3.3 * @interface Item - * @property {string} key - 键 + * @property {DBKey} key - 键 * @property {string} value - 值 * @property {string} updated - 数据库更新时间 * @return Item */ export interface Item { - key: string; + key: DBKey; value: string; updated: string; }