mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-06 18:36:55 +08:00
feat: implement client heartbeat mechanism with 2-second interval
This commit is contained in:
@@ -29,6 +29,35 @@ const accountInfo = useAccount()
|
|||||||
|
|
||||||
export const clientInited = ref(false)
|
export const clientInited = ref(false)
|
||||||
let tray: TrayIcon
|
let tray: TrayIcon
|
||||||
|
let heartbeatTimer: number | null = null
|
||||||
|
|
||||||
|
async function sendHeartbeat() {
|
||||||
|
try {
|
||||||
|
await invoke('heartbeat')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('发送心跳失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startHeartbeat() {
|
||||||
|
// 立即发送一次,确保后端在加载后快速收到心跳
|
||||||
|
void sendHeartbeat()
|
||||||
|
|
||||||
|
// 之后每 5 秒发送一次心跳(后端超时时间为 15 秒)
|
||||||
|
heartbeatTimer = window.setInterval(() => {
|
||||||
|
void sendHeartbeat()
|
||||||
|
}, 2000)
|
||||||
|
info('[心跳] 定时器已启动,间隔 2 秒')
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopHeartbeat() {
|
||||||
|
if (heartbeatTimer !== null) {
|
||||||
|
clearInterval(heartbeatTimer)
|
||||||
|
heartbeatTimer = null
|
||||||
|
info('[心跳] 定时器已停止')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function initAll(isOnBoot: boolean) {
|
export async function initAll(isOnBoot: boolean) {
|
||||||
const setting = useSettings()
|
const setting = useSettings()
|
||||||
if (clientInited.value) {
|
if (clientInited.value) {
|
||||||
@@ -150,6 +179,7 @@ export async function initAll(isOnBoot: boolean) {
|
|||||||
useAutoAction().init()
|
useAutoAction().init()
|
||||||
useBiliFunction().init()
|
useBiliFunction().init()
|
||||||
|
|
||||||
|
startHeartbeat()
|
||||||
clientInited.value = true
|
clientInited.value = true
|
||||||
}
|
}
|
||||||
export function OnClientUnmounted() {
|
export function OnClientUnmounted() {
|
||||||
@@ -157,6 +187,7 @@ export function OnClientUnmounted() {
|
|||||||
clientInited.value = false
|
clientInited.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopHeartbeat()
|
||||||
tray.close()
|
tray.close()
|
||||||
// useDanmakuWindow().closeWindow();
|
// useDanmakuWindow().closeWindow();
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/components.d.ts
vendored
6
src/components.d.ts
vendored
@@ -22,19 +22,13 @@ declare module 'vue' {
|
|||||||
NAvatar: typeof import('naive-ui')['NAvatar']
|
NAvatar: typeof import('naive-ui')['NAvatar']
|
||||||
NButton: typeof import('naive-ui')['NButton']
|
NButton: typeof import('naive-ui')['NButton']
|
||||||
NCard: typeof import('naive-ui')['NCard']
|
NCard: typeof import('naive-ui')['NCard']
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
|
||||||
NEmpty: typeof import('naive-ui')['NEmpty']
|
|
||||||
NFlex: typeof import('naive-ui')['NFlex']
|
NFlex: typeof import('naive-ui')['NFlex']
|
||||||
NFormItemGi: typeof import('naive-ui')['NFormItemGi']
|
|
||||||
NGridItem: typeof import('naive-ui')['NGridItem']
|
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
NImage: typeof import('naive-ui')['NImage']
|
NImage: typeof import('naive-ui')['NImage']
|
||||||
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
|
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
NSpace: typeof import('naive-ui')['NSpace']
|
||||||
NTag: typeof import('naive-ui')['NTag']
|
NTag: typeof import('naive-ui')['NTag']
|
||||||
NText: typeof import('naive-ui')['NText']
|
NText: typeof import('naive-ui')['NText']
|
||||||
NTime: typeof import('naive-ui')['NTime']
|
|
||||||
PointGoodsItem: typeof import('./components/manage/PointGoodsItem.vue')['default']
|
PointGoodsItem: typeof import('./components/manage/PointGoodsItem.vue')['default']
|
||||||
PointHistoryCard: typeof import('./components/manage/PointHistoryCard.vue')['default']
|
PointHistoryCard: typeof import('./components/manage/PointHistoryCard.vue')['default']
|
||||||
PointOrderCard: typeof import('./components/manage/PointOrderCard.vue')['default']
|
PointOrderCard: typeof import('./components/manage/PointOrderCard.vue')['default']
|
||||||
|
|||||||
Reference in New Issue
Block a user