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.
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// trayDoubleClicks says whether a double-click on the tray icon opens the
|
|
// main window on this system (isaac_bai on Discord). Only Windows' tray
|
|
// tells a double-click apart: Wails passes the icon's WM_LBUTTONDBLCLK on
|
|
// as OnDoubleClick there. The Mac's status item runs its action on the
|
|
// mouse-down, one call per click with no click count, and Linux's
|
|
// StatusNotifierItem has Activate alone, so a double-click there is two
|
|
// clicks: the panel open and closed again.
|
|
func trayDoubleClicks(goos string) bool { return goos == "windows" }
|
|
|
|
// trayDoubleRelease bounds how long after a double-click its own release
|
|
// may come. Windows sends a double-click as WM_LBUTTONUP, WM_LBUTTONDBLCLK
|
|
// and WM_LBUTTONUP again; that last one is the double-click's, not a click
|
|
// of its own, and would open the panel over the window just shown.
|
|
const trayDoubleRelease = 2 * time.Second
|
|
|
|
// trayDouble swallows the release that ends a double-click on the tray
|
|
// icon, once, and no click after it.
|
|
type trayDouble struct {
|
|
mu sync.Mutex
|
|
until time.Time
|
|
}
|
|
|
|
// doubled records a double-click at now.
|
|
func (d *trayDouble) doubled(now time.Time) {
|
|
d.mu.Lock()
|
|
d.until = now.Add(trayDoubleRelease)
|
|
d.mu.Unlock()
|
|
}
|
|
|
|
// swallow says the click at now is the release of a double-click, which
|
|
// does nothing; it is so only once per double-click.
|
|
func (d *trayDouble) swallow(now time.Time) bool {
|
|
d.mu.Lock()
|
|
defer d.mu.Unlock()
|
|
if d.until.IsZero() {
|
|
return false
|
|
}
|
|
ours := now.Before(d.until)
|
|
d.until = time.Time{}
|
|
return ours
|
|
}
|