MCPcopy
hub / github.com/ZToolsCenter/ZTools / toggleWindow

Method toggleWindow

src/main/managers/windowManager.ts:725–752  ·  view source on GitHub ↗

* 切换窗口显示/隐藏

()

Source from the content-addressed store, hash-verified

723 * 切换窗口显示/隐藏
724 */
725 private toggleWindow(): void {
726 if (!this.mainWindow) return
727
728 const isFocused = this.mainWindow.isFocused()
729 const isVisible = this.mainWindow.isVisible()
730
731 // 判断窗口是否聚焦显示
732 // 修复:同时检查聚焦和可见状态,避免alert弹窗后判断错误
733 if (isFocused && isVisible) {
734 // 窗口已显示且聚焦 → 隐藏
735
736 // 记录当前的焦点状态(在隐藏之前)
737 this.recordFocusState()
738
739 this.mainWindow.blur()
740 this.mainWindow.hide()
741 this.restorePreviousWindow()
742 } else {
743 // 窗口已隐藏或失焦 → 显示并强制激活
744 // 但如果是刚刚因为 blur 事件隐藏的(点击托盘图标导致失焦),
745 // 说明用户意图是隐藏窗口,不应再重新显示
746 const timeSinceBlurHide = Date.now() - this.lastBlurHideTime
747 if (timeSinceBlurHide < 300) {
748 return
749 }
750 this.showWindow()
751 }
752 }
753
754 private toggleWindowFromDoubleTap(): void {
755 if (!this.mainWindow) return

Callers 4

createTrayMethod · 0.95
createTrayMenuMethod · 0.95
registerShortcutMethod · 0.95

Calls 4

recordFocusStateMethod · 0.95
restorePreviousWindowMethod · 0.95
showWindowMethod · 0.95
hideMethod · 0.80

Tested by

no test coverage detected