gui: the panel's header icon is named "Open the main window"; a double-click on the Windows tray icon opens it
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.
This commit is contained in:
@@ -37,6 +37,7 @@ three.
|
||||
7. The page's header is the window's title bar. `plainTitlebar` sets it up once the app has started, and again on a window lightweight mode made again (`madeAgain`). On Linux it hides GTK's title bar and keeps the shadow and the resize edges; GTK 3 leaves the corners square. On the Mac the traffic lights are inset into the header (`MacTitleBarHiddenInset`). In the design of macOS 26 a window with a toolbar has larger corners than one with a plain title bar, so `insetLights` ([`titlebar_darwin.go`](../../internal/gui/titlebar_darwin.go)) takes the toolbar off, and `MagpieLights` keeps the lights and the title bar's height where the toolbar had them: after a resize, a new title, light or dark, more contrast or less transparency, and leaving full screen. A sheet, such as the folder chooser, still begins below the title bar. A first press while another app is in front still moves the window from anywhere in that title bar (`firstPress`), as AppKit moved it with the toolbar; AppKit itself now does so only in a plain title bar's top 32pt. AppKit gives a program that design from macOS 26 when the program is linked against the macOS 26 SDK or a later one and its Info.plist doesn't ask for the earlier design (`UIDesignRequiresCompatibility`); `designOf26` reads each at run time, as the SDK depends on the toolchain that built magpie. The toolbar stays in the earlier design, where it doesn't change the corners, with the lights on the right (a right-to-left language), or when the title bar isn't laid out as expected; this is decided once, when the window is set up. In full screen the title bar is AppKit's own. Windows keeps its own title bar.
|
||||
8. On the Mac, Settings › Show in Dock puts magpie in the Dock never (`DockNever`), while the window is open (the default; `DockWindow` records it chosen, for an older magpie that took none for never) or always (`Dock`, which wins). The default was never until ShouguangCao on X found the open window out of Command-Tab, so going back to it to paste a key copied elsewhere took the menu bar; a new install (no settings.json) reads With window, and Hide is a choice of its own (`inDock`, `dockChoice` in app.js, `TestDockFollowsWindowByDefault`, `dock-choice.test.cjs`). A file written before that has no `dockSettled`, and stored Hide as nothing, so a user who chose Hide can't be told from one who never chose: such a file with no Dock choice reads as Hide, and the first save writes it so with `dockSettled` (`settleDock`, `TestOlderSettingsKeepHide`, `TestNewInstallFollowsWindow`). A file nobody can read reads the same way. The page never sends `dockSettled`; the save keeps the file's (`TestSettingsSaveKeepsDockReading`). It is this computer's own, as the Dock choice is (`KeepOwn`). A full-screen window joins it whatever the setting (`inDock`, `dockOnFullscreen`). `openMain` joins before it shows the window (`setDock` runs on the main thread at once). An app activated out of the Dock (the quick panel's focus) that then joins it stays last in Command-Tab's order though it is in front, so joining to the front activates magpie by way of the Dock (`dockStep`, `activateAgain`; #1381, `TestDockStep`, `TestDockJoinLeadsCommandTab`). It does so without asking NSApp whether magpie is active: the Mac makes it the front app at once, and NSApp says so only once the main thread has taken that in, after the join on a busy Mac (#1651).
|
||||
9. Settings › General › Quick panel shortcut binds a key combination that opens the tray's panel from any app (ben hanks on Discord); none is set by default. The page records the keys and posts them to `POST /api/settings/panel-shortcut`, which checks them (`panelShortcut`: a letter, digit, Space or F1–F20 with Ctrl, Alt/Option or Cmd/Super, or an F key alone, written as Wails' accelerator), has the running app bind them (`onPanelShortcut`, `bindPanelKey` through Wails' `GlobalShortcut`: Carbon's hot keys on the Mac, `RegisterHotKey` on Windows, `XGrabKey` on X11) and saves them only once bound. One the system refuses (on Windows and X11, another app holding it) is not saved and the old one stays bound; one saved but refused as magpie starts is retried after a handed-over magpie exits and else said in the row (`panelKeysJSON.Taken`). A pressed shortcut toggles the panel as a tray click does (`togglePanel`). The Mac's Carbon hot keys don't refuse a combination another app registered too, so there both are taken and magpie can't tell the user. The shortcut is per computer (`KeepOwn`), and the Mac's old process lets go of it as it hands over (`leaveMenuBar`). On Wayland no app may grab keys itself, so the field is off and the row says the command to bind in the desktop's own keyboard settings (`magpie panel`); Wails' GlobalShortcuts portal is not used, since the compositor decides its keys and Hyprland binds none unless configured. From there a not-connected Claude Code's or Codex's opened row switches its account (shuizhuyu on X, [Switch accounts only](providers-accounts.md)).
|
||||
10. A click on the tray icon opens the quick panel, or the main window when Settings › General › Click the tray icon to says so. The panel opens the main window from the header's icon (`#open`, named "Open the main window"; its foot keeps Profiles, the status line and Quit, `panel-open-once.test.cjs`). On Windows a double-click on the icon opens the main window too (isaac_bai on Discord): Wails passes the icon's `WM_LBUTTONDBLCLK` on as `OnDoubleClick`, the panel its first click opened is hidden by `openMain`, and the `WM_LBUTTONUP` that ends the double-click is swallowed once (`trayDouble`, within `trayDoubleRelease`) so it does not open the panel over the window. The Mac's status item calls its action on each mouse-down with no click count, and Linux's StatusNotifierItem has only `Activate`, so there a double-click is two clicks and is left as such (`trayDoubleClicks`, `TestTrayDoubleClickOpensTheWindowOnWindowsOnly`, `TestTrayDoubleClickReleaseSwallowedOnce`; [`traydouble.go`](../../internal/gui/traydouble.go)).
|
||||
|
||||
## Constraints and failure behavior
|
||||
|
||||
|
||||
@@ -619,9 +619,22 @@ func Run(version string, showMain bool, link string) error {
|
||||
h.setTrayInBar(barIcon(h)["on"])
|
||||
go h.lighten()
|
||||
h.watchAlerts()
|
||||
// a double-click opens the main window where the tray tells one apart
|
||||
// (trayDoubleClicks: Windows); its first click opened the panel, which
|
||||
// openMain hides, and its last release is no click of its own
|
||||
var double trayDouble
|
||||
if trayDoubleClicks(runtime.GOOS) {
|
||||
h.tray.OnDoubleClick(func() {
|
||||
double.doubled(time.Now())
|
||||
h.ShowMain("")
|
||||
})
|
||||
}
|
||||
// the quick panel by the icon, or the main window if the user would
|
||||
// rather (Settings → Click the tray icon to)
|
||||
h.tray.OnClick(func() {
|
||||
if double.swallow(time.Now()) {
|
||||
return
|
||||
}
|
||||
if cmdClick() {
|
||||
return // Command-drag moves the icon; the system handles it
|
||||
}
|
||||
|
||||
@@ -565,7 +565,6 @@ const I18N = {
|
||||
"Agents looked for again": "已重新检测 Agent",
|
||||
"Usage refreshed": "用量已刷新",
|
||||
"Allowances refreshed": "额度已刷新",
|
||||
"Open as a window": "在窗口中打开",
|
||||
"Quit": "退出",
|
||||
"Filter…": "筛选…",
|
||||
|
||||
@@ -5134,7 +5133,6 @@ const I18N = {
|
||||
"Agents looked for again": "已重新檢測 Agent",
|
||||
"Usage refreshed": "用量已重新整理",
|
||||
"Allowances refreshed": "額度已重新整理",
|
||||
"Open as a window": "在視窗中開啟",
|
||||
"Quit": "退出",
|
||||
"Filter…": "篩選…",
|
||||
"No agents found": "沒有找到 Agent",
|
||||
@@ -9665,7 +9663,6 @@ const I18N = {
|
||||
"Agents looked for again": "エージェントを再検出しました",
|
||||
"Usage refreshed": "使用量を更新しました",
|
||||
"Allowances refreshed": "利用枠を更新しました",
|
||||
"Open as a window": "ウィンドウで開く",
|
||||
"Quit": "終了",
|
||||
"Filter…": "絞り込み…",
|
||||
"No agents found": "エージェントが見つかりません",
|
||||
@@ -14214,7 +14211,6 @@ const I18N = {
|
||||
"Agents looked for again": "Agenten erneut gesucht",
|
||||
"Usage refreshed": "Nutzung aktualisiert",
|
||||
"Allowances refreshed": "Kontingente aktualisiert",
|
||||
"Open as a window": "Als Fenster öffnen",
|
||||
"Quit": "Beenden",
|
||||
"Filter…": "Filtern…",
|
||||
"No agents found": "Keine Agenten gefunden",
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
<button class="icon" id="sync" title="Look for agents on this computer again: one just installed or removed, or its settings changed" data-tt>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2v3h-3" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
</button>
|
||||
<button class="icon" id="open" title="Open as a window" data-tt>
|
||||
<button class="icon" id="open" title="Open the main window" data-tt>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14"><path d="M6 3H3.5A1.5 1.5 0 0 0 2 4.5v8A1.5 1.5 0 0 0 3.5 14h8a1.5 1.5 0 0 0 1.5-1.5V10M9 2h5v5M14 2 8 8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
</button>
|
||||
<button class="icon" id="prefs" title="Settings" data-tt data-keys="⌘,|Ctrl+,">
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// The tray panel opens the main window from one place: the header's
|
||||
// open-as-a-window icon. Its foot had an "Open magpie" button too, which did
|
||||
// the same (yogurt36 on Discord); the foot keeps Profiles, the status line
|
||||
// and Quit, which are its own.
|
||||
// and Quit, which are its own. The icon is named for what it opens, the main
|
||||
// window: isaac_bai on Discord looked for the foot's button and took the
|
||||
// icon's "Open as a window" for this panel in a window.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -47,6 +49,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.goto("http://magpie.test/?mode=panel");
|
||||
await page.locator("#agents .row.agent").first().waitFor();
|
||||
|
||||
// the header's icon is named for what it opens, in the panel's language
|
||||
const name = { en: "Open the main window", zh: "打开主窗口", "zh-TW": "開啟主視窗", ja: "メインウィンドウを開く", de: "Hauptfenster öffnen" }[lang];
|
||||
assert.equal(await page.locator(".top #open").getAttribute("title"), name, "the header icon's name");
|
||||
assert.equal(await page.locator(".top").getByRole("button", { name, exact: true }).count(), 1, "found by its name");
|
||||
|
||||
// the header's icon opens the window
|
||||
await page.locator(".top #open").click();
|
||||
for (let i = 0; i < 100 && !calls.length; i++) await page.waitForTimeout(50);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user