mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
feat: 添加更新日志功能;优化组件和状态管理;修复部分逻辑错误
This commit is contained in:
155
src/data/Initializer.ts
Normal file
155
src/data/Initializer.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
import { GetSelfAccount, useAccount, UpdateAccountLoop } from "@/api/account";
|
||||
import { QueryGetAPI } from "@/api/query";
|
||||
import { useAuthStore } from "@/store/useAuthStore";
|
||||
import { useNotificationStore } from "@/store/useNotificationStore";
|
||||
import { createDiscreteApi, NText, NFlex, NButton } from "naive-ui";
|
||||
import { BASE_API_URL, isTauri, apiFail } from "./constants";
|
||||
import { GetNotifactions } from "./notifactions";
|
||||
import HyperDX from '@hyperdx/browser'
|
||||
import EasySpeech from "easy-speech";
|
||||
import { checkUpdateNote } from "./UpdateNote";
|
||||
|
||||
let currentVersion: string
|
||||
let isHaveNewVersion = false
|
||||
|
||||
const { notification } = createDiscreteApi(['notification'])
|
||||
|
||||
export function InitVTsuru() {
|
||||
QueryGetAPI<string>(`${BASE_API_URL}vtsuru/version`)
|
||||
.then((version) => {
|
||||
if (version.code == 200) {
|
||||
currentVersion = version.data
|
||||
const savedVersion = localStorage.getItem('Version')
|
||||
localStorage.setItem('Version', currentVersion)
|
||||
|
||||
if (currentVersion && savedVersion && savedVersion !== currentVersion) {
|
||||
setTimeout(() => {
|
||||
location.reload()
|
||||
}, 1000)
|
||||
// alert('发现新的版本更新, 请按 Ctrl+F5 强制刷新页面')
|
||||
notification.info({
|
||||
title: '发现新的版本更新',
|
||||
content: '将自动刷新页面',
|
||||
duration: 5000,
|
||||
meta: () => h(NText, { depth: 3 }, () => currentVersion),
|
||||
})
|
||||
}
|
||||
else {
|
||||
InitVersionCheck();
|
||||
}
|
||||
}
|
||||
InitOther();
|
||||
})
|
||||
.catch(() => {
|
||||
apiFail.value = true
|
||||
console.log('默认API调用失败, 切换至故障转移节点')
|
||||
})
|
||||
.finally(async () => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
async function InitOther() {
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
HyperDX.init({
|
||||
apiKey: '7d1eb66c-24b8-445e-a406-dc2329fa9423',
|
||||
service: 'vtsuru.live',
|
||||
tracePropagationTargets: [/vtsuru.suki.club/i], // Set to link traces from frontend to backend requests
|
||||
consoleCapture: true, // Capture console logs (default false)
|
||||
advancedNetworkCapture: true, // Capture full HTTP request/response headers and bodies (default false)
|
||||
})
|
||||
}
|
||||
// 加载其他数据
|
||||
InitTTS()
|
||||
await GetSelfAccount()
|
||||
const account = useAccount()
|
||||
const useAuth = useAuthStore()
|
||||
if (account.value.id) {
|
||||
if (account.value.biliUserAuthInfo && !useAuth.currentToken) {
|
||||
useAuth.currentToken = account.value.biliUserAuthInfo.token
|
||||
}
|
||||
HyperDX.setGlobalAttributes({
|
||||
userId: account.value.id.toString(),
|
||||
userName: account.value.name,
|
||||
})
|
||||
}
|
||||
useAuth.getAuthInfo()
|
||||
GetNotifactions()
|
||||
UpdateAccountLoop()
|
||||
|
||||
useNotificationStore().init()
|
||||
}
|
||||
function InitVersionCheck() {
|
||||
setInterval(() => {
|
||||
if (isHaveNewVersion) {
|
||||
return
|
||||
}
|
||||
QueryGetAPI<string>(`${BASE_API_URL}vtsuru/version`).then(
|
||||
(keepCheckData) => {
|
||||
if (
|
||||
keepCheckData.code == 200
|
||||
&& keepCheckData.data != currentVersion
|
||||
) {
|
||||
isHaveNewVersion = true
|
||||
currentVersion = keepCheckData.data
|
||||
localStorage.setItem('Version', currentVersion)
|
||||
console.log(`[vtsuru] 发现新版本: ${currentVersion}`)
|
||||
|
||||
const url = new URL(window.location.href)
|
||||
const path = url.pathname
|
||||
|
||||
if (!path.startsWith('/obs')) {
|
||||
if (isTauri) {
|
||||
location.reload();
|
||||
}
|
||||
else {
|
||||
const n = notification.info({
|
||||
title: '发现新的版本更新',
|
||||
content: '是否现在刷新?',
|
||||
meta: () => h(NText, { depth: 3 }, () => currentVersion),
|
||||
action: () =>
|
||||
h(NFlex, null, () => [
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
text: true,
|
||||
type: 'primary',
|
||||
onClick: () => location.reload(),
|
||||
size: 'small',
|
||||
},
|
||||
{ default: () => '刷新' },
|
||||
),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
text: true,
|
||||
onClick: () => n.destroy(),
|
||||
size: 'small',
|
||||
},
|
||||
{ default: () => '稍后' },
|
||||
),
|
||||
]),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}, 60 * 1000)
|
||||
}
|
||||
function InitTTS() {
|
||||
try {
|
||||
const result = EasySpeech.detect()
|
||||
if (result.speechSynthesis) {
|
||||
EasySpeech.init({ maxTimeout: 5000, interval: 250 })
|
||||
.then(() => console.log('[SpeechSynthesis] 已加载tts服务'))
|
||||
.catch(e => console.error(e))
|
||||
}
|
||||
else {
|
||||
console.log('[SpeechSynthesis] 当前浏览器不支持tts服务')
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log('[SpeechSynthesis] 当前浏览器不支持tts服务')
|
||||
}
|
||||
}
|
||||
91
src/data/UpdateNote.ts
Normal file
91
src/data/UpdateNote.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import UpdateNoteContainer from "@/components/UpdateNoteContainer.vue";
|
||||
import { NButton, NImage, NTag } from "naive-ui";
|
||||
import { VNode } from "vue";
|
||||
import { FETCH_API } from "./constants";
|
||||
|
||||
export const updateNotes: updateNoteType[] = [
|
||||
{
|
||||
ver: 2,
|
||||
date: '2025.4.8',
|
||||
items: [
|
||||
{
|
||||
type: 'new',
|
||||
title: 'EventFetcher Tauri 客户端开始测试',
|
||||
content: [
|
||||
['比当前所有 EventFetcher 部署方法都更要简单且支持扫码登录的客户端开始测试力, 支持Windows, Linux, MacOS (后两个没测试过'],
|
||||
[
|
||||
'如果对此感兴趣的话可以使用 ',
|
||||
() => h(NButton, {
|
||||
text: true, tag: 'a', href: FETCH_API + 'https://github.com/Megghy/vtsuru-fetcher-client/releases/download/app-v0.1.0/vtsuru-fetcher-client_0.1.0_x64-setup.exe', target: '_blank', type: 'info'
|
||||
}, () => '这个链接'),
|
||||
' 下载Windows客户端, 其他平台请在下面的客户端 Repo 中的 Release 下载',
|
||||
],
|
||||
[
|
||||
'当前可能存在一些问题, 可以加入秋秋群 873260337 进行反馈, 有功能需求也可以提出'
|
||||
],
|
||||
[],
|
||||
[
|
||||
'源码: ',
|
||||
() => h(NButton, {
|
||||
text: true, tag: 'a', href: 'https://github.com/Megghy/vtsuru-fetvher-client', target: '_blank', type: 'info'
|
||||
}, () => ' 客户端 Repo '),
|
||||
' | ',
|
||||
() => h(NButton, {
|
||||
text: true, tag: 'a', href: 'https://github.com/Megghy/vtsuru.live/tree/master/src/client', target: '_blank', type: 'info'
|
||||
}, () => ' UI/逻辑 '),
|
||||
],
|
||||
[
|
||||
() => h(NImage, { src: 'https://pan.suki.club/d/vtsuru/imgur/01295402D7FBBF192FE5608179A4A7A6.png', width: 200 }),
|
||||
]
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
ver: 1,
|
||||
date: '2025.3.18',
|
||||
items: [
|
||||
{
|
||||
title: '歌单',
|
||||
type: 'optimize',
|
||||
content: [
|
||||
[
|
||||
'新增一个歌单样式: 列表',
|
||||
() => h(NImage, { src: 'https://pan.suki.club/d/vtsuru/imgur/QQ20250408-134631.png', width: 300, height: 200 }),
|
||||
]
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const currentUpdateNoteVer = updateNotes.sort((a, b) => b.ver - a.ver)[0].ver;
|
||||
export const currentUpdateNote = updateNotes.sort((a, b) => b.ver - a.ver)[0].items;
|
||||
export const savedUpdateNoteVer = useStorage('UpdateNoteVer', 0);
|
||||
|
||||
export function checkUpdateNote() {
|
||||
if (savedUpdateNoteVer.value < currentUpdateNoteVer) {
|
||||
window.$dialog.create({
|
||||
title: '更新日志',
|
||||
content: () => h(UpdateNoteContainer),
|
||||
negativeText: '确定',
|
||||
positiveText: '下次更新前不再提示',
|
||||
onPositiveClick: () => {
|
||||
savedUpdateNoteVer.value = currentUpdateNoteVer;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export type updateType = 'fix' | 'new' | 'optimize' | 'other';
|
||||
export type updateNoteType = {
|
||||
ver: number;
|
||||
date: string;
|
||||
items: updateNoteItemType[];
|
||||
};
|
||||
export type updateNoteItemType = {
|
||||
title?: string | (() => VNode);
|
||||
type: updateType;
|
||||
content: updateNoteItemContentType[];
|
||||
};
|
||||
export type updateNoteItemContentType = (() => VNode) | string | updateNoteItemContentType[];
|
||||
Reference in New Issue
Block a user