Skip to content

Commit 06018d2

Browse files
committed
fix: 恢复主进程交互状态同步并与本地状态结合
- 重新添加 onCaptionInteractiveChanged 监听 - 新增 isInteractive 状态与本地 isHoverLocal 配合 - 鼠标离开时同步重置交互状态
1 parent ec72747 commit 06018d2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

frontend/src/components/CaptionOverlay.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function CaptionOverlay() {
5252
const [style, setStyle] = useState<CaptionStyle>(defaultStyle)
5353
const [isDraggable, setIsDraggable] = useState(false)
5454
const [isDragging, setIsDragging] = useState(false)
55+
const [isInteractive, setIsInteractive] = useState(false)
5556
const [isHoverLocal, setIsHoverLocal] = useState(false)
5657
const containerRef = useRef<HTMLDivElement>(null)
5758
const contentRef = useRef<HTMLDivElement>(null)
@@ -123,6 +124,20 @@ export function CaptionOverlay() {
123124
return cleanup
124125
}, [])
125126

127+
// 监听交互状态变化(主进程检测鼠标命中字幕窗口)
128+
useEffect(() => {
129+
if (!window.electronAPI?.onCaptionInteractiveChanged) return
130+
131+
const cleanup = window.electronAPI.onCaptionInteractiveChanged((interactive) => {
132+
setIsInteractive(interactive)
133+
if (!interactive) {
134+
setIsHoverLocal(false)
135+
}
136+
})
137+
138+
return cleanup
139+
}, [])
140+
126141
// 本地悬停处理,避免依赖轮询事件
127142
const handleMouseEnter = useCallback(() => {
128143
setIsHoverLocal(true)
@@ -131,6 +146,7 @@ export function CaptionOverlay() {
131146

132147
const handleMouseLeave = useCallback(() => {
133148
setIsHoverLocal(false)
149+
setIsInteractive(false)
134150
// 不在拖拽时才允许关闭交互
135151
if (!isDragging) {
136152
window.electronAPI?.captionSetInteractive?.(false)
@@ -215,7 +231,7 @@ export function CaptionOverlay() {
215231
const showPlaceholder = !hasContent && !isDraggable
216232

217233
// 是否显示锁按钮:鼠标悬停时或处于拖拽模式时
218-
const showLockButton = isHoverLocal || isDraggable
234+
const showLockButton = isInteractive || isHoverLocal || isDraggable
219235

220236
return (
221237
<div

0 commit comments

Comments
 (0)