性能优化

This commit is contained in:
zhongluofeng
2026-08-06 10:33:16 +08:00
parent c7578a2e6b
commit e66c53e66d
105 changed files with 7273 additions and 5002 deletions
+7 -6
View File
@@ -3,6 +3,7 @@ import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { listen, emit, type UnlistenFn } from '@tauri-apps/api/event'
import { getCurrentWindow } from '@tauri-apps/api/window'
import { invoke } from '@tauri-apps/api/core'
import { EVENTS, WINDOWS } from '@/lib/constants'
// ===== 数据契约(与主窗口 MonitorModule 共享,此处独立声明避免循环依赖) =====
interface OsdItem {
@@ -450,7 +451,7 @@ async function measureAndReportSize() {
const rect = bar.getBoundingClientRect()
if (rect.width === 0 || rect.height === 0) return
// 额外留 1px 余量避免边缘裁切
await emit('osd-content-size', { width: Math.ceil(rect.width) + 1, height: Math.ceil(rect.height) + 1 })
await emit(EVENTS.osdContentSize, { width: Math.ceil(rect.width) + 1, height: Math.ceil(rect.height) + 1 })
}
/** 防抖测量(数据频繁更新时合并) */
@@ -474,7 +475,7 @@ async function applyClickThrough(ignore: boolean) {
}
// 2. Rust 原生:设置 WS_EX_TRANSPARENT 扩展样式(更可靠的原生层穿透)
try {
await invoke('osd_set_click_through', { label: 'osd-overlay', enabled: ignore })
await invoke('osd_set_click_through', { label: WINDOWS.osdOverlay, enabled: ignore })
} catch (e) {
console.error('[OSD] osd_set_click_through 失败:', e)
}
@@ -483,7 +484,7 @@ async function applyClickThrough(ignore: boolean) {
// ===== 应用置顶(使用 Rust 原生命令) =====
async function applyTopmost(topmost: boolean) {
try {
await invoke('osd_set_topmost', { label: 'osd-overlay', topmost })
await invoke('osd_set_topmost', { label: WINDOWS.osdOverlay, topmost })
} catch (e) {
console.error('[OSD] 设置置顶失败:', e)
}
@@ -498,7 +499,7 @@ watch(() => config.value?.clickThrough, (ignore) => {
onMounted(async () => {
// 应用原生样式(NoActivate + ToolWindow,不获取焦点)
try {
await invoke('osd_apply_overlay_style', { label: 'osd-overlay' })
await invoke('osd_apply_overlay_style', { label: WINDOWS.osdOverlay })
} catch (e) {
console.error('[OSD] 应用原生样式失败:', e)
}
@@ -523,11 +524,11 @@ onMounted(async () => {
}))
// 监听系统 UI 覆盖事件
unlistenFns.push(await listen('osd-system-ui-active', async () => {
unlistenFns.push(await listen(EVENTS.osdSystemUiActive, async () => {
await applyTopmost(false)
}))
unlistenFns.push(await listen('osd-system-ui-inactive', async () => {
unlistenFns.push(await listen(EVENTS.osdSystemUiInactive, async () => {
await applyTopmost(true)
}))
})