- 单进程:托盘常驻 + 原生设置窗口(internal/settings),移除 Wails 前端与 IPC - 触发器(鼠标角落 / 边缘滚轮 / 热键)+ 规则引擎 + 动作注册表 - 调节提示条:截屏 + glass.Blur 三层毛玻璃、背景跟随屏幕变化、悬停光感与拖动 - 音量 Core Audio COM、亮度 DDC/CI(gamma 兜底)、多显示器求平均 - 配置热重载 + 版本迁移 v1→v5、便携模式、崩溃取证三件套 - updater/native 插件 + 托盘「检查更新…」,watchdog 识别更新重启 - 自建 Gitea 发布:scripts/publish-gitea.ps1(updates.url 指向 latest Release)
108 lines
3.5 KiB
Go
108 lines
3.5 KiB
Go
package windows
|
||
|
||
import (
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
// TestIsFullscreenRect 验证覆盖判定边界(94%/95%/96%、无交集、跨屏)。
|
||
func TestIsFullscreenRect(t *testing.T) {
|
||
screen := MonitorRect{Left: 0, Top: 0, Right: 1920, Bottom: 1080}
|
||
cases := []struct {
|
||
name string
|
||
win MonitorRect
|
||
want bool
|
||
}{
|
||
{"完全覆盖", MonitorRect{0, 0, 1920, 1080}, true},
|
||
{"无边框全屏", MonitorRect{0, 0, 1920, 1080}, true},
|
||
{"任务栏遮挡(94%)", MonitorRect{0, 0, 1920, 1015}, false}, // 1015/1080 ≈ 93.9%
|
||
{"任务栏遮挡(96%)", MonitorRect{0, 0, 1920, 1040}, true}, // 1040/1080 ≈ 96.3%
|
||
{"普通窗口", MonitorRect{100, 100, 1200, 800}, false},
|
||
{"无交集", MonitorRect{3000, 3000, 4000, 4000}, false},
|
||
{"覆盖95%临界", MonitorRect{0, 0, 1920, 1026}, true}, // 1026/1080 = 95.0%
|
||
}
|
||
for _, c := range cases {
|
||
if got := IsFullscreenRect(c.win, screen, 0); got != c.want {
|
||
t.Errorf("%s: IsFullscreenRect = %v, want %v", c.name, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestIsFullscreenRectMultiMonitor 验证跨屏窗口按交集最大屏幕判定。
|
||
func TestIsFullscreenRectMultiMonitor(t *testing.T) {
|
||
screen := MonitorRect{Left: 1920, Top: 0, Right: 3840, Bottom: 1080}
|
||
win := MonitorRect{Left: 1900, Top: 0, Right: 3840, Bottom: 1080} // 几乎全盖副屏
|
||
if !IsFullscreenRect(win, screen, 0) {
|
||
t.Fatal("near-fullscreen on secondary monitor should be true")
|
||
}
|
||
}
|
||
|
||
// TestIsDesktopClass 验证 Shell 桌面窗口类名识别(空桌面场景回归)。
|
||
func TestIsDesktopClass(t *testing.T) {
|
||
cases := []struct {
|
||
cls string
|
||
want bool
|
||
}{
|
||
{"Progman", true}, // Shell 桌面主窗口
|
||
{"WorkerW", true}, // 壁纸层(Win11 前台焦点)
|
||
{"#32769", true}, // 系统桌面窗口(GetDesktopWindow)
|
||
{"SHELLDLL_DefView", true}, // 桌面图标宿主
|
||
{"SysListView32", true}, // 桌面图标列表
|
||
{"Chrome_WidgetWin_1", false},
|
||
{"ConsoleWindowClass", false},
|
||
{"CabinetWClass", false}, // 资源管理器(普通窗口,不算桌面)
|
||
{"", false},
|
||
}
|
||
for _, c := range cases {
|
||
if got := isDesktopClass(c.cls); got != c.want {
|
||
t.Errorf("isDesktopClass(%q) = %v, want %v", c.cls, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestIsShellOverlayClass 验证任务视图覆盖层类名识别(打开任务视图时
|
||
// 不应抑制全部规则,回归:音量滚轮无反应)。
|
||
func TestIsShellOverlayClass(t *testing.T) {
|
||
cases := []struct {
|
||
cls string
|
||
want bool
|
||
}{
|
||
{"XamlExplorerHostIslandWindow", true}, // Win11 任务视图
|
||
{"Progman", false},
|
||
{"Chrome_WidgetWin_1", false},
|
||
{"", false},
|
||
}
|
||
for _, c := range cases {
|
||
if got := isShellOverlayClass(c.cls); got != c.want {
|
||
t.Errorf("isShellOverlayClass(%q) = %v, want %v", c.cls, got, c.want)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestIsDesktopWindowReal 集成验证:GetDesktopWindow 返回的系统桌面窗口
|
||
// (类名 #32769)必须判定为桌面(防止空桌面被误判全屏导致规则抑制)。
|
||
func TestIsDesktopWindowReal(t *testing.T) {
|
||
hwnd, _, _ := procGetDesktopWindow.Call()
|
||
if hwnd == 0 {
|
||
t.Skip("GetDesktopWindow returned 0")
|
||
}
|
||
if !isDesktopWindow(hwnd) {
|
||
t.Fatal("desktop window (#32769) should be detected as desktop")
|
||
}
|
||
}
|
||
|
||
// TestFullscreenWatcherLifecycle 验证轮询器 Start/Stop 幂等与状态可读。
|
||
func TestFullscreenWatcherLifecycle(t *testing.T) {
|
||
w := NewFullscreenWatcher()
|
||
w.Start()
|
||
w.Start() // 幂等
|
||
time.Sleep(100 * time.Millisecond)
|
||
_ = w.IsFullscreen() // 可读(值不校验:取决于会话前台窗口)
|
||
w.Stop()
|
||
w.Stop() // 幂等
|
||
// 重启
|
||
w.Start()
|
||
time.Sleep(50 * time.Millisecond)
|
||
w.Stop()
|
||
}
|