isaac_bai on Discord missed the "Open magpie" button beside the quick panel's Quit, and was setting the tray click to open the main window just to get back to it; he asked for a double-click on the tray icon. History: the foot's button (#openMain) was taken out on purpose ine0ad48641(10-30, yogurt36 on Discord): the panel had two buttons to the same window, the header's open-as-a-window icon (#open) and the foot's "Open magpie". The header icon stayed, but its tooltip said "Open as a window", which reads as this panel in a window. Rather than bring the second button back (and undo yogurt36's ask four days later), the icon now says what it opens: "Open the main window", a string every language already had (Settings' tray-click choice). "Open as a window" is out of i18n.js, nothing else used it. Double-click, per OS, from Wails v3.0.0-beta.24's source: - Windows: systemtray_windows.go passes WM_LBUTTONDBLCLK on as OnDoubleClick. A double-click arrives as LBUTTONUP (the click: the panel opens), LBUTTONDBLCLK (now: ShowMain, whose openMain hides the panel), LBUTTONUP again; that last one is swallowed once (trayDouble, within 2s) so it doesn't open the panel over the window. - macOS: the status item's action runs per mouse-down with no click count (systemtray_darwin.m statusItemClicked); a double-click would be the panel opened and closed. Not added. - Linux: StatusNotifierItem has Activate only (systemtray_linux.go); the same. Not added. docs/subsystems/gui-shell.md step 10 says so. Tests: - TestTrayDoubleClickOpensTheWindowOnWindowsOnly: windows on, darwin and linux off, and app.go wires OnDoubleClick to ShowMain and checks the swallow first in OnClick. - TestTrayDoubleClickReleaseSwallowedOnce: the release after a double-click opens nothing, once; the next click, or one past the bound, opens the panel. Fixed instants, no sleeps. - panel-open-once.test.cjs: the header icon's title and accessible name are "Open the main window" in en, zh, zh-TW, ja and de, both engines. Run (at the pushed head's tree before rebase onto78667e9b7, which changes only docs/subsystems/gui-shell.md among these files): - mote: gofmt -l internal/gui clean; GOOS=windows go vet ./internal/gui ok; go test -run TrayDouble ./internal/gui ok. - Linux (wsl-run, magpie-desktop): go vet -tags gtk3 ./internal/gui ok; go test -tags gtk3 -run 'TrayDouble|TrayMenu' ./internal/gui ok. - Windows (win-run, xiaomi-gpu): go test -run TrayDouble ./internal/gui ok. - mote GUI, both engines: panel-*, phone-web, old-webkit and i18n-keys (24 files), 280/280 ok. - Broken by hand (a copy on mote): trayDoubleClicks false for windows and the swallow never reset are both red; the old "Open as a window" title is red in every language, Chromium 0/5 and WebKit 0/5. At the pushed head (rebased on78667e9b7), mote: gofmt clean, go test -run TrayDouble ./internal/gui ok, panel-open-once + i18n-keys 14/14 ok. Not run: the whole GUI suite (a tooltip only, no layout or API change) or the whole Go suite. Not tried: a real double-click on the Windows tray icon in the built app, or the panel in the real tray on any OS.
58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A double-click on the tray icon opens the main window on Windows, the one
|
|
// tray that reports it (isaac_bai on Discord); the Mac and Linux keep one
|
|
// click for the panel, since a double-click there is two clicks.
|
|
func TestTrayDoubleClickOpensTheWindowOnWindowsOnly(t *testing.T) {
|
|
for goos, want := range map[string]bool{"windows": true, "darwin": false, "linux": false} {
|
|
if got := trayDoubleClicks(goos); got != want {
|
|
t.Errorf("%s: double-click opens the window = %v, want %v", goos, got, want)
|
|
}
|
|
}
|
|
src, err := os.ReadFile("app.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// the handler is set where it applies, opens the window, and the click
|
|
// handler asks first whether it is a double-click's release
|
|
if !regexp.MustCompile(`(?s)if trayDoubleClicks\(runtime\.GOOS\) \{\s*h\.tray\.OnDoubleClick\(func\(\) \{\s*double\.doubled\(time\.Now\(\)\)\s*h\.ShowMain\(""\)`).Match(src) {
|
|
t.Error("app.go doesn't open the window on a double-click where trayDoubleClicks says")
|
|
}
|
|
if !regexp.MustCompile(`(?s)h\.tray\.OnClick\(func\(\) \{\s*if double\.swallow\(time\.Now\(\)\) \{\s*return`).Match(src) {
|
|
t.Error("the tray's click handler doesn't let a double-click's release go first")
|
|
}
|
|
}
|
|
|
|
// Windows sends a double-click as up, double-click, up: the last up is the
|
|
// double-click's and opens nothing, once; a click after it, or one long
|
|
// after, is a click again.
|
|
func TestTrayDoubleClickReleaseSwallowedOnce(t *testing.T) {
|
|
t0 := time.Date(2026, 11, 3, 20, 28, 0, 0, time.UTC)
|
|
var d trayDouble
|
|
if d.swallow(t0) {
|
|
t.Fatal("a click with no double-click before it was swallowed")
|
|
}
|
|
d.doubled(t0)
|
|
if !d.swallow(t0.Add(120 * time.Millisecond)) {
|
|
t.Fatal("the double-click's own release opened the panel again")
|
|
}
|
|
if d.swallow(t0.Add(time.Second)) {
|
|
t.Fatal("the click after a double-click's release was swallowed too")
|
|
}
|
|
// a release that never came: the user's next click, long after, opens
|
|
d.doubled(t0)
|
|
if d.swallow(t0.Add(trayDoubleRelease + time.Second)) {
|
|
t.Fatal("a click long after a double-click was swallowed")
|
|
}
|
|
if d.swallow(t0.Add(trayDoubleRelease + 2*time.Second)) {
|
|
t.Fatal("a late click left the double-click waiting")
|
|
}
|
|
}
|