mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { QueryGetAPI } from '@/api/query'
|
|
import { BASE_API, apiFail } from '@/data/constants'
|
|
import EasySpeech from 'easy-speech'
|
|
import { NText, createDiscreteApi } from 'naive-ui'
|
|
import { createPinia } from 'pinia'
|
|
import { createApp, h } from 'vue'
|
|
import App from './App.vue'
|
|
import { GetSelfAccount, UpdateAccountLoop } from './api/account'
|
|
import { GetNotifactions } from './data/notifactions'
|
|
import router from './router'
|
|
|
|
const pinia = createPinia()
|
|
|
|
const app = createApp(App)
|
|
app.use(router).use(pinia).mount('#app')
|
|
|
|
let currentVersion: string
|
|
const { notification } = createDiscreteApi(['notification'])
|
|
QueryGetAPI<string>(BASE_API() + '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),
|
|
})
|
|
}
|
|
}
|
|
})
|
|
.catch(() => {
|
|
apiFail.value = true
|
|
console.log('默认API调用失败, 切换至故障转移节点')
|
|
})
|
|
.finally(() => {
|
|
//加载其他数据
|
|
GetSelfAccount()
|
|
GetNotifactions()
|
|
UpdateAccountLoop()
|
|
InitTTS()
|
|
})
|
|
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服务')
|
|
}
|
|
}
|