* 切换窗口显示/隐藏
()
| 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 |
no test coverage detected