diff --git a/src/client/data/initialize.ts b/src/client/data/initialize.ts index 64ee7f6..5ccc40e 100644 --- a/src/client/data/initialize.ts +++ b/src/client/data/initialize.ts @@ -29,6 +29,35 @@ const accountInfo = useAccount() export const clientInited = ref(false) 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) { const setting = useSettings() if (clientInited.value) { @@ -150,6 +179,7 @@ export async function initAll(isOnBoot: boolean) { useAutoAction().init() useBiliFunction().init() + startHeartbeat() clientInited.value = true } export function OnClientUnmounted() { @@ -157,6 +187,7 @@ export function OnClientUnmounted() { clientInited.value = false } + stopHeartbeat() tray.close() // useDanmakuWindow().closeWindow(); } diff --git a/src/components.d.ts b/src/components.d.ts index 382f8ff..886add7 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -22,19 +22,13 @@ declare module 'vue' { NAvatar: typeof import('naive-ui')['NAvatar'] NButton: typeof import('naive-ui')['NButton'] NCard: typeof import('naive-ui')['NCard'] - NEllipsis: typeof import('naive-ui')['NEllipsis'] - NEmpty: typeof import('naive-ui')['NEmpty'] NFlex: typeof import('naive-ui')['NFlex'] - NFormItemGi: typeof import('naive-ui')['NFormItemGi'] - NGridItem: typeof import('naive-ui')['NGridItem'] NIcon: typeof import('naive-ui')['NIcon'] NImage: typeof import('naive-ui')['NImage'] NPopconfirm: typeof import('naive-ui')['NPopconfirm'] - NScrollbar: typeof import('naive-ui')['NScrollbar'] NSpace: typeof import('naive-ui')['NSpace'] NTag: typeof import('naive-ui')['NTag'] NText: typeof import('naive-ui')['NText'] - NTime: typeof import('naive-ui')['NTime'] PointGoodsItem: typeof import('./components/manage/PointGoodsItem.vue')['default'] PointHistoryCard: typeof import('./components/manage/PointHistoryCard.vue')['default'] PointOrderCard: typeof import('./components/manage/PointOrderCard.vue')['default']