NovaStudiosss wanted to watch Usage and Routing while working in other apps. The main window's toolbar now has a pin between Refresh and Settings. A click keeps the window above other apps' windows (Wails SetAlwaysOnTop through POST /api/window/ontop?on=1|0) and saves it as settings.json's onTop, which this computer keeps for itself (KeepOwn, not synced). makeMain opens the window pinned on the next start, and boot.js shows the pin pressed before the first paint. There is no pin in the panel, in a browser's page (magpie web) or under Wayland, where always-on-top is ignored (GDK_BACKEND=x11 keeps it). A refused pin goes back up. Tooltips "Keep on top" and "Stop keeping on top" are in every language. A Settings save keeps onTop (settingsapi.Merge), which a test showed was lost before. Run (rebased ona80a920f5): - go test -tags nogui ./internal/gui ./internal/settings ./internal/settingsapi on mica: ok. TestPinKeepsWindowOnTop, TestPinRefusedWithoutAWindowToPin, TestSetOnTop*, TestOnTopOwn and the settings-save keep test. - At the rebased head, TestPinRefused had served webHost through Handler and left webPage set, which turned TestSessionTitlesName- OtherAgents and TestCursorEditorChatsAreNotCalledCursorCLI red in a full package run. It now goes through webPageHandler, and the package is ok. TestWebPageHandlerEveryWhere misses a webHost passed in a variable. - window-pin.test.cjs (chromium + webkit, en zh zh-TW ja de) and i18n-keys: 36 pass. - Full GUI suite on mote (pre-rebase tree, still running at push): about 380 reds so far, none in window-pin. Seven of the red files (account-arrange, agent-details-ready, api-key-theme, bark, agent-switch-accounts, allow-ips, agent-bulk-visibility) were run on origin/main30de93e9e: 77 of the same reds, and none red only here. - go vet for darwin, windows, linux nogui and linux gtk3. Windows go test ./internal/gui ./internal/settings: ok. gofmt clean. - Broken by hand: without the route, or without renderOnTop, the Go and GUI tests go red. Without the Merge line the settings-save test goes red. - Real app on mote: with onTop saved, the main window opens at the floating level (CGWindowList layer 3, 0 unpinned). Not tried: clicking the pin in the real app (no Accessibility over ssh), a real Windows or Linux window, Wayland (hidden by design). At the default 660px window, the English tabs now scroll about 15px, as Japanese and German already did on main.
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package settings
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// The main window's pin (NovaStudiosss on X) is saved alone, keeping what
|
|
// the user set elsewhere, and turns back off the same way.
|
|
func TestSetOnTop(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if Load().OnTop {
|
|
t.Fatal("the window is pinned by default")
|
|
}
|
|
s := Load()
|
|
s.Theme, s.NoBird = "dark", true
|
|
if err := Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := SetOnTop(true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := Load(); !got.OnTop || got.Theme != "dark" || !got.NoBird {
|
|
t.Fatalf("after SetOnTop(true): onTop %v, theme %q, noBird %v", got.OnTop, got.Theme, got.NoBird)
|
|
}
|
|
if err := SetOnTop(false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := Load(); got.OnTop || got.Theme != "dark" {
|
|
t.Fatalf("after SetOnTop(false): onTop %v, theme %q", got.OnTop, got.Theme)
|
|
}
|
|
}
|
|
|
|
// A settings file that can't be read is not written over with defaults by
|
|
// the pin: the save fails and the file stays as it was.
|
|
func TestSetOnTopLeavesAnUnreadFile(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if err := Save(Settings{Theme: "dark"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := Path()
|
|
if err := os.WriteFile(p, []byte("{not json"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := SetOnTop(true); err == nil {
|
|
t.Fatal("SetOnTop saved over a file it couldn't read")
|
|
}
|
|
if b, _ := os.ReadFile(p); string(b) != "{not json" {
|
|
t.Fatalf("the unread file was written: %q", b)
|
|
}
|
|
}
|
|
|
|
// The pin is this computer's own, as the window's size and place are: a
|
|
// synced or restored bundle neither brings another's nor drops this one's.
|
|
func TestOnTopOwn(t *testing.T) {
|
|
from := Settings{Theme: "dark"}
|
|
from.KeepOwn(Settings{OnTop: true})
|
|
if !from.OnTop || from.Theme != "dark" {
|
|
t.Fatalf("KeepOwn dropped it: %+v", from.OnTop)
|
|
}
|
|
from = Settings{OnTop: true}
|
|
from.KeepOwn(Settings{})
|
|
if from.OnTop {
|
|
t.Fatal("another computer's pin here")
|
|
}
|
|
}
|