mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-18 04:56:47 +08:00
🌱 构建脚本
This commit is contained in:
@@ -28,7 +28,6 @@ import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
|
||||
import { mkdir } from "@tauri-apps/plugin-fs";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { getWindowSize, resizeWindow } from "@utils/TGWindow.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -384,7 +383,8 @@ async function checkUpdate(): Promise<void> {
|
||||
showSnackbar.error("请到设置页手动更新数据库!", 3000);
|
||||
return;
|
||||
}
|
||||
buildTime.value = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
buildTime.value = import.meta.env.VITE_SENTRY_RELEASE;
|
||||
await TGSqlite.update();
|
||||
showSnackbar.success("数据库已更新!", 3000);
|
||||
await openUrl("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html");
|
||||
|
||||
@@ -8,8 +8,6 @@ import * as Sentry from "@sentry/vue";
|
||||
import { createApp } from "vue";
|
||||
import { createVuetify } from "vuetify";
|
||||
|
||||
import pkgJson from "../package.json" with { type: "json" };
|
||||
|
||||
import App from "./App.vue";
|
||||
import router from "./router/index.js";
|
||||
import store from "./store/index.js";
|
||||
@@ -23,7 +21,7 @@ const app = createApp(App);
|
||||
Sentry.init({
|
||||
app,
|
||||
dsn: "https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768",
|
||||
release: `TeyvatGuide@${pkgJson.version}`,
|
||||
release: import.meta.env.VITE_SENTRY_RELEASE,
|
||||
enableLogs: true,
|
||||
integrations: [
|
||||
Sentry.feedbackAsyncIntegration(<FeedbackInternalOptions>{
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
{{ deviceInfo.device_name }}({{ deviceInfo.product }}) - {{ deviceInfo.device_fp }}
|
||||
</v-list-item-subtitle>
|
||||
<template #append>
|
||||
<v-icon @click="confirmUpdateDevice(true)" title="强制刷新设备信息">mdi-bug</v-icon>
|
||||
<v-icon title="强制刷新设备信息" @click="confirmUpdateDevice(true)">mdi-bug</v-icon>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="清除缓存" @click="confirmDelCache">
|
||||
@@ -64,7 +64,7 @@
|
||||
</v-list-item>
|
||||
<v-list-subheader :inset="true" class="config-header" title="调试" @click="tryShowReset" />
|
||||
<v-divider :inset="true" class="border-opacity-75" />
|
||||
<v-list-item v-if="isDevEnv" title="调试模式" subtitle="开启后将显示调试信息">
|
||||
<v-list-item v-if="isDevEnv" subtitle="开启后将显示调试信息" title="调试模式">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-bug-play</v-icon>
|
||||
@@ -73,15 +73,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="devMode"
|
||||
:label="devMode ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
color="#FAC51E"
|
||||
:label="devMode ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="submitDevMode"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="窗口回正" subtitle="根据分辨率动态调整窗体大小">
|
||||
<v-list-item subtitle="根据分辨率动态调整窗体大小" title="窗口回正">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-window-restore</v-icon>
|
||||
@@ -90,15 +90,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="isNeedResize"
|
||||
:label="isNeedResize ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
color="#FAC51E"
|
||||
:label="isNeedResize ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="submitResize"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="关闭到托盘" subtitle="关闭窗口时最小化到系统托盘而不是退出应用">
|
||||
<v-list-item subtitle="关闭窗口时最小化到系统托盘而不是退出应用" title="关闭到托盘">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-tray-arrow-down</v-icon>
|
||||
@@ -107,14 +107,14 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="closeToTray"
|
||||
:label="closeToTray ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
:label="closeToTray ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="无痕浏览" subtitle="关闭后将记录帖子浏览记录">
|
||||
<v-list-item subtitle="关闭后将记录帖子浏览记录" title="无痕浏览">
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
<v-icon>mdi-incognito</v-icon>
|
||||
@@ -123,15 +123,15 @@
|
||||
<template #append>
|
||||
<v-switch
|
||||
v-model="appStore.incognito"
|
||||
:label="appStore.incognito ? '开启' : '关闭'"
|
||||
:inset="true"
|
||||
:label="appStore.incognito ? '开启' : '关闭'"
|
||||
class="config-switch"
|
||||
color="#FAC51E"
|
||||
@click="switchIncognito"
|
||||
/>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="分享设置" v-if="platform() === 'windows'">
|
||||
<v-list-item v-if="platform() === 'windows'" title="分享设置">
|
||||
<template #subtitle>默认保存到剪贴板,超过{{ shareDefaultFile }}MB时保存到文件</template>
|
||||
<template #prepend>
|
||||
<div class="config-icon">
|
||||
@@ -184,7 +184,6 @@ import { remove } from "@tauri-apps/plugin-fs";
|
||||
import { platform } from "@tauri-apps/plugin-os";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { backUpUserData, restoreUserData } from "@utils/dataBS.js";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
import TGLogger from "@utils/TGLogger.js";
|
||||
import { bytesToSize, getCacheDir, getDeviceInfo, getRandomString } from "@utils/toolFunc.js";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -292,7 +291,8 @@ async function confirmUpdate(title?: string): Promise<void> {
|
||||
}
|
||||
await showLoading.start("正在更新数据库", "");
|
||||
await TGSqlite.update();
|
||||
buildTime.value = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
buildTime.value = import.meta.env.VITE_SENTRY_RELEASE;
|
||||
await showLoading.end();
|
||||
showSnackbar.success("数据库已更新!即将刷新页面");
|
||||
await TGLogger.Info("[Config][confirmUpdate] 数据库更新完成");
|
||||
@@ -446,9 +446,8 @@ async function tryShowReset(): Promise<void> {
|
||||
showSnackbar.cancel("已取消");
|
||||
return;
|
||||
}
|
||||
const time = getBuildTime();
|
||||
const code = time.startsWith("dev.") ? "dev" : time;
|
||||
if (codeInput === code || codeInput === "reset1128") {
|
||||
// @ts-expect-error import.meta
|
||||
if (codeInput === import.meta.env.VITE_SENTRY_RELEASE || codeInput === "reset1128") {
|
||||
showReset.value = true;
|
||||
showSnackbar.success("已开启重置数据库选项");
|
||||
return;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Sqlite 初始化数据 sql 语句
|
||||
* @since Beta v0.7.2
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
|
||||
import { app } from "@tauri-apps/api";
|
||||
import { getBuildTime } from "@utils/TGBuild.js";
|
||||
|
||||
import createTable from "./createTable.sql?raw";
|
||||
|
||||
@@ -16,7 +15,8 @@ import createTable from "./createTable.sql?raw";
|
||||
async function initAppData(): Promise<Array<string>> {
|
||||
const sqlRes: Array<string> = [];
|
||||
const appVersion = await app.getVersion();
|
||||
const buildTime: string = getBuildTime();
|
||||
// @ts-expect-error import.meta
|
||||
const buildTime: string = import.meta.VITE_SENTRY_RELEASE;
|
||||
// 初始化应用版本
|
||||
sqlRes.push(`
|
||||
INSERT INTO AppData (key, value, updated)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* 用于获取 vite 打包时间
|
||||
* @see https://gitee.com/lihanspace/vite-plugin-build-time
|
||||
* @since Alpha v0.1.4
|
||||
*/
|
||||
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
const buildTimeKey = "buildTime";
|
||||
|
||||
const buildTimePlugin = (modes: Array<string> = []): Plugin => {
|
||||
let _mode = "";
|
||||
return {
|
||||
name: "build-time",
|
||||
config(uc, { mode }) {
|
||||
_mode = mode;
|
||||
},
|
||||
transformIndexHtml() {
|
||||
if (_mode !== "production" && !modes.includes(_mode)) return;
|
||||
return [
|
||||
{
|
||||
tag: "script",
|
||||
children: `window.${buildTimeKey} = '${Math.floor(Date.now() / 1000)}'`,
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getBuildTime = (): string => {
|
||||
if (typeof window === "undefined") {
|
||||
console.warn("getBuildTime() should only be called in the browser");
|
||||
return "dev";
|
||||
}
|
||||
const windowEnv = <typeof window & { [buildTimeKey]?: string }>window;
|
||||
if (!windowEnv[buildTimeKey]) {
|
||||
console.info("当前环境为开发环境");
|
||||
return `dev.${Math.floor(Date.now() / 1000)}`;
|
||||
}
|
||||
return windowEnv[buildTimeKey];
|
||||
};
|
||||
|
||||
export default buildTimePlugin;
|
||||
4
src/vite-env.d.ts
vendored
4
src/vite-env.d.ts
vendored
@@ -26,6 +26,10 @@ declare type ImportMeta = {
|
||||
* - `"test"` 测试模式
|
||||
*/
|
||||
MODE: string;
|
||||
/**
|
||||
* Sentry Release
|
||||
*/
|
||||
VITE_SENTRY_RELEASE: string;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user