(triggers: WatchSource<unknown>[])
| 13 | const TRANSITION_SAMPLE_MS = 420 |
| 14 | |
| 15 | export function useWindowsTitleBarOverlay(triggers: WatchSource<unknown>[]): void { |
| 16 | if (!IS_ELECTRON || typeof navigator === 'undefined' || !navigator.platform.toLowerCase().includes('win')) return |
| 17 | |
| 18 | let frameId = 0 |
| 19 | let lastColor = '' |
| 20 | |
| 21 | const syncTitleBarColor = () => { |
| 22 | const color = sampleTitleBarBackground() |
| 23 | if (!color || color === lastColor) return |
| 24 | |
| 25 | lastColor = color |
| 26 | window.api?.setTitleBarOverlayColor(color) |
| 27 | } |
| 28 | |
| 29 | const scheduleSync = (durationMs = 0) => { |
| 30 | if (frameId) { |
| 31 | cancelAnimationFrame(frameId) |
| 32 | } |
| 33 | |
| 34 | const startedAt = performance.now() |
| 35 | const tick = () => { |
| 36 | syncTitleBarColor() |
| 37 | if (performance.now() - startedAt < durationMs) { |
| 38 | frameId = requestAnimationFrame(tick) |
| 39 | } else { |
| 40 | frameId = 0 |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | nextTick(() => { |
| 45 | frameId = requestAnimationFrame(tick) |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | const handleResize = () => scheduleSync() |
| 50 | |
| 51 | onMounted(() => { |
| 52 | window.addEventListener('resize', handleResize) |
| 53 | scheduleSync(TRANSITION_SAMPLE_MS) |
| 54 | }) |
| 55 | |
| 56 | onUnmounted(() => { |
| 57 | window.removeEventListener('resize', handleResize) |
| 58 | if (frameId) { |
| 59 | cancelAnimationFrame(frameId) |
| 60 | } |
| 61 | }) |
| 62 | |
| 63 | for (const trigger of triggers) { |
| 64 | watch(trigger, () => scheduleSync(TRANSITION_SAMPLE_MS), { flush: 'post' }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // 采样 Windows 标题栏按钮区域下方的真实背景色,并用它推导原生按钮符号颜色。 |
| 69 | // 这里需要沿 elementsFromPoint 返回的层级合成透明背景,才能覆盖设置弹窗淡入淡出时的 blur/backdrop 场景。 |
nothing calls this directly
no test coverage detected