细节调整及优化(26.8.3)
This commit is contained in:
@@ -77,31 +77,19 @@ interface OsdConfig {
|
||||
overlayY?: number | null
|
||||
}
|
||||
|
||||
interface SensorEntry {
|
||||
name: string
|
||||
type: string
|
||||
hardwareName: string
|
||||
value: number | null
|
||||
unit: string
|
||||
}
|
||||
|
||||
interface SensorGroup {
|
||||
id: string
|
||||
sensors: SensorEntry[]
|
||||
}
|
||||
|
||||
interface SensorSnapshot {
|
||||
groups: SensorGroup[]
|
||||
}
|
||||
|
||||
interface NetworkSpeed {
|
||||
downloadBps: number
|
||||
uploadBps: number
|
||||
}
|
||||
|
||||
/** 配置通道载荷(低频:配置变化时推送) */
|
||||
interface OsdStatePayload {
|
||||
config: OsdConfig
|
||||
snapshot: SensorSnapshot | null
|
||||
}
|
||||
|
||||
/** 数据通道载荷(高频:仅显示项 key→value 映射 + 网速) */
|
||||
interface OsdDataPayload {
|
||||
data: Record<string, number | null>
|
||||
networkSpeed: NetworkSpeed | null
|
||||
}
|
||||
|
||||
@@ -333,7 +321,8 @@ function fmtFixedUnit(item: OsdItem): string {
|
||||
|
||||
// ===== 状态 =====
|
||||
const config = ref<OsdConfig | null>(null)
|
||||
const snapshot = ref<SensorSnapshot | null>(null)
|
||||
/** 数据通道:显示项 key→value 映射(由主窗口每秒推送,替代全量快照) */
|
||||
const dataMap = ref<Record<string, number | null>>({})
|
||||
const networkSpeed = ref<NetworkSpeed | null>(null)
|
||||
let unlistenFns: UnlistenFn[] = []
|
||||
|
||||
@@ -341,15 +330,7 @@ let unlistenFns: UnlistenFn[] = []
|
||||
function getOsdItemValue(item: OsdItem): number | null {
|
||||
if (item.special === 'net-up') return networkSpeed.value?.uploadBps ?? null
|
||||
if (item.special === 'net-down') return networkSpeed.value?.downloadBps ?? null
|
||||
if (!snapshot.value) return null
|
||||
for (const g of snapshot.value.groups) {
|
||||
if (g.id !== item.groupId) continue
|
||||
const s = g.sensors.find(s =>
|
||||
s.hardwareName === item.hardwareName && s.name === item.sensorName && s.type === item.type
|
||||
)
|
||||
if (s) return s.value ?? null
|
||||
}
|
||||
return null
|
||||
return dataMap.value[item.key] ?? null
|
||||
}
|
||||
|
||||
// ===== 颜色主题 =====
|
||||
@@ -514,15 +495,19 @@ onMounted(async () => {
|
||||
console.error('[OSD] 启动置顶监视失败:', e)
|
||||
}
|
||||
|
||||
// 监听主窗口推送的 OSD 状态
|
||||
unlistenFns.push(await listen<OsdStatePayload>('osd-state-update', (e) => {
|
||||
// 监听主窗口推送的 OSD 配置(低频通道)
|
||||
unlistenFns.push(await listen<OsdStatePayload>(EVENTS.osdStateUpdate, (e) => {
|
||||
config.value = e.payload.config
|
||||
snapshot.value = e.payload.snapshot
|
||||
networkSpeed.value = e.payload.networkSpeed
|
||||
// 数据/配置变化后重新测量尺寸
|
||||
// 配置变化(字号/布局/显示项)后重新测量尺寸
|
||||
scheduleMeasure()
|
||||
}))
|
||||
|
||||
// 监听主窗口推送的 OSD 数据(高频通道:key→value 映射 + 网速)
|
||||
unlistenFns.push(await listen<OsdDataPayload>(EVENTS.osdDataUpdate, (e) => {
|
||||
dataMap.value = e.payload.data
|
||||
networkSpeed.value = e.payload.networkSpeed
|
||||
}))
|
||||
|
||||
// 监听系统 UI 覆盖事件
|
||||
unlistenFns.push(await listen(EVENTS.osdSystemUiActive, async () => {
|
||||
await applyTopmost(false)
|
||||
@@ -531,6 +516,10 @@ onMounted(async () => {
|
||||
unlistenFns.push(await listen(EVENTS.osdSystemUiInactive, async () => {
|
||||
await applyTopmost(true)
|
||||
}))
|
||||
|
||||
// 监听注册完成后,主动请求主窗口补发配置+数据
|
||||
// (数据通道不含配置;若窗口加载慢错过创建时的首推,需主动请求,否则会一直空白)
|
||||
await emit(EVENTS.osdConfigRequest)
|
||||
})
|
||||
|
||||
/** 鼠标按下:仅在关闭穿透时响应左键拖动 */
|
||||
@@ -652,6 +641,13 @@ onUnmounted(() => {
|
||||
display: inline-flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: stretch;
|
||||
/* 文本永不换行:配置变更(如中英文切换)到窗口 resize 之间存在异步窗口期,
|
||||
若允许换行,中文标签(内存/网络)会在旧窗口宽度内竖排;禁止后仅临时溢出,
|
||||
随内容测量上报触发 setSize 立即恢复 */
|
||||
white-space: nowrap;
|
||||
/* 不被 osd-root(100vw 旧窗口宽度)压缩:否则 getBoundingClientRect 测到的是
|
||||
被旧窗口钳制的宽度而非真实内容宽度,上报后 setSize 不变,窗口永远无法变宽 */
|
||||
flex-shrink: 0;
|
||||
backdrop-filter: blur(8px);
|
||||
padding: 3px 4px;
|
||||
gap: 0;
|
||||
|
||||
Reference in New Issue
Block a user