Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

settings: an older settings.json with no Dock choice keeps Hide

yetone8e5567161e1f
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md
index 395d1800a..8ac7c4c62 100644
--- a/docs/subsystems/gui-shell.md
+++ b/docs/subsystems/gui-shell.md
@@ -32,7 +32,7 @@ three.
5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`).
6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. The window's position is not kept.
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 file that chose nothing now reads With window, and Hide is a choice of its own (`inDock`, `dockChoice` in app.js, `TestDockFollowsWindowByDefault`, `dock-choice.test.cjs`). 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).
+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).
## Constraints and failure behavior
diff --git a/internal/gui/api.go b/internal/gui/api.go
index aae6f2a22..c3ebdeb05 100644
--- a/internal/gui/api.go
+++ b/internal/gui/api.go
@@ -1429,6 +1429,10 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
in.CodexWarmAtOf = cur.CodexWarmAtOf
// and the text size, which the keyboard changes too (text-size below)
in.TextSize = cur.TextSize
+ // the Dock choice's reading, which the page never sets: the file's
+ // as read (settings.DockSettled), so a save from the page doesn't
+ // read its With window as an older file's Hide
+ in.DockSettled = cur.DockSettled
// the version the Update pill was hidden for, set from the pill
in.UpdateSkip = cur.UpdateSkip
// the GitHub mirror updates come through, set by magpie update mirror
diff --git a/internal/gui/dock_settled_test.go b/internal/gui/dock_settled_test.go
new file mode 100644
index 000000000..838362014
--- /dev/null
+++ b/internal/gui/dock_settled_test.go
@@ -0,0 +1,51 @@
+//go:build !nogui
+
+package gui
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/settings"
+)
+
+// A save from the Settings page keeps how the file's Dock choice is read,
+// which the page never sends: a new install's With window stays With
+// window (in the Dock while its window is open), and an older file's Hide
+// stays Hide.
+func TestSettingsSaveKeepsDockReading(t *testing.T) {
+ page := `{"theme":"dark","dock":false,"dockWindow":false,"dockNever":%s}`
+ for _, c := range []struct {
+ name, file, never string
+ inDock bool
+ }{
+ {"a new install", "", "false", true},
+ {"an older file with no choice", `{}`, "true", false},
+ } {
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+ if c.file != "" {
+ if err := os.MkdirAll(settings.Dir(), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(settings.Path(), []byte(c.file), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if got := settings.Load(); inDock(got, true, false) != c.inDock {
+ t.Fatalf("%s: in the Dock with its window open read as %v", c.name, !c.inDock)
+ }
+ // what the page posts is what it was shown
+ rec := httptest.NewRecorder()
+ Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings", strings.NewReader(strings.Replace(page, "%s", c.never, 1))))
+ if rec.Code != http.StatusOK {
+ t.Fatalf("%s: %d %s", c.name, rec.Code, rec.Body)
+ }
+ got := settings.Load()
+ if got.Theme != "dark" || inDock(got, true, false) != c.inDock {
+ t.Fatalf("%s: after a save from the page, theme %q, in the Dock with its window open %v", c.name, got.Theme, inDock(got, true, false))
+ }
+ }
+}
diff --git a/internal/settings/dock_test.go b/internal/settings/dock_test.go
index 56c87aca3..d2f200657 100644
--- a/internal/settings/dock_test.go
+++ b/internal/settings/dock_test.go
@@ -1,6 +1,13 @@
package settings
-import "testing"
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/yetone/magpie/internal/lastgood"
+)
// Show in Dock's Hide (DockNever) is this computer's own, as Dock and
// DockWindow are: a sync or restored backup from a Mac that left it as it
@@ -16,4 +23,88 @@ func TestDockNeverIsMachineLocal(t *testing.T) {
if from.DockNever {
t.Fatal("a sync brought another Mac's Hide")
}
+ from = Settings{}
+ from.KeepOwn(Settings{DockSettled: true})
+ if !from.DockSettled {
+ t.Fatal("a sync took how this Mac's Dock choice is read")
+ }
+}
+
+func dockHome(t *testing.T) {
+ t.Helper()
+ h := t.TempDir()
+ t.Setenv("HOME", h)
+ t.Setenv("USERPROFILE", h)
+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
+ lastgood.Reset()
+ t.Cleanup(lastgood.Reset)
+ if err := os.MkdirAll(Dir(), 0o755); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// A settings file written before With window became the default (no
+// dockSettled) stored Hide as nothing, so one with no Dock choice is read,
+// and written back, as Hide: the new default never moves a user who chose
+// Hide into the Dock. A choice the file has is kept as it is.
+func TestOlderSettingsKeepHide(t *testing.T) {
+ for _, c := range []struct {
+ file string
+ dock, wind bool
+ never bool
+ }{
+ {`{"theme":"dark"}`, false, false, true},
+ {`{}`, false, false, true},
+ {`{"dockWindow":true}`, false, true, false},
+ {`{"dock":true}`, true, false, false},
+ {`{"dockNever":true}`, false, false, true},
+ } {
+ dockHome(t)
+ if err := os.WriteFile(Path(), []byte(c.file), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ s, err := LoadChecked()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if s.Dock != c.dock || s.DockWindow != c.wind || s.DockNever != c.never || !s.DockSettled {
+ t.Fatalf("%s read as dock %v window %v never %v settled %v", c.file, s.Dock, s.DockWindow, s.DockNever, s.DockSettled)
+ }
+ if err := Save(s); err != nil {
+ t.Fatal(err)
+ }
+ b, _ := os.ReadFile(Path())
+ var w Settings
+ if err := json.Unmarshal(b, &w); err != nil {
+ t.Fatal(err)
+ }
+ if w.DockNever != c.never || !w.DockSettled {
+ t.Fatalf("%s written back as %s", c.file, b)
+ }
+ // read again, it stays: the migration runs once
+ if s, _ = LoadChecked(); s.DockNever != c.never {
+ t.Fatalf("%s changed on a second read: never %v", c.file, s.DockNever)
+ }
+ }
+}
+
+// A new install (no settings file) has With window: no Hide, and what it
+// saves says so, so the next read doesn't take it for an older file.
+func TestNewInstallFollowsWindow(t *testing.T) {
+ dockHome(t)
+ os.Remove(Path())
+ s, err := LoadChecked()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if s.Dock || s.DockNever || !s.DockSettled {
+ t.Fatalf("a new install: dock %v never %v settled %v", s.Dock, s.DockNever, s.DockSettled)
+ }
+ s.Theme = "dark"
+ if err := Save(s); err != nil {
+ t.Fatal(err)
+ }
+ if s, _ = LoadChecked(); s.DockNever || !s.DockSettled {
+ t.Fatalf("a new install's first save read back as never %v settled %v", s.DockNever, s.DockSettled)
+ }
}
diff --git a/internal/settings/loadchecked_test.go b/internal/settings/loadchecked_test.go
index d8f03899b..fa47935e0 100644
--- a/internal/settings/loadchecked_test.go
+++ b/internal/settings/loadchecked_test.go
@@ -61,7 +61,9 @@ func TestLoadChecked(t *testing.T) {
if s, err := LoadChecked(); err == nil {
t.Fatalf("garbled with no backup read as good: %v", s.AllowIPs)
}
- if s := Load(); !reflect.DeepEqual(s, Settings{}.normal()) {
+ // the defaults, with the Dock choice an older file's (Hide): a file
+ // nobody can read could be one
+ if s := Load(); !reflect.DeepEqual(s, Settings{}.settleDock().normal()) {
t.Fatalf("Load of a garbled file changed: %+v", s)
}
if err := Save(Load()); err == nil {
diff --git a/internal/settings/settings.go b/internal/settings/settings.go
index 1d3fa27e6..e9ca2f684 100644
--- a/internal/settings/settings.go
+++ b/internal/settings/settings.go
@@ -86,6 +86,14 @@ type Settings struct {
// DockNever keeps magpie out of the Dock and Command-Tab even while
// its window is open, the Hide choice. Dock wins over it.
DockNever bool `json:"dockNever,omitempty"`
+ // DockSettled says this file's Dock choice is read with With window as
+ // the default. A file written before that (v0.1.2060) has none, and
+ // Hide was its default, stored as nothing: a user who chose Hide can't
+ // be told from one who never chose, so such a file with no choice is
+ // read as Hide (settleDock), never moved into the Dock by the new
+ // default. A new install, with no file, is settled from the start.
+ // Every save writes it.
+ DockSettled bool `json:"dockSettled,omitempty"`
// Proxy for magpie's own requests to vendors: "" follows the
// environment and then the system, "direct" uses none, anything else
// is the proxy (http://, https:// or socks5://; host:port means http).
@@ -1158,7 +1166,7 @@ func (s *Settings) KeepOwn(cur Settings) {
s.GatewayConversations = cur.GatewayConversations
s.UIFont, s.CodeFont = cur.UIFont, cur.CodeFont
s.Window, s.Proxy, s.Port, s.Dock, s.DockWindow, s.Lightweight = cur.Window, cur.Proxy, cur.Port, cur.Dock, cur.DockWindow, cur.Lightweight
- s.DockNever = cur.DockNever
+ s.DockNever, s.DockSettled = cur.DockNever, cur.DockSettled
s.ProxyCustom = cur.ProxyCustom
s.WindowMaximised, s.KeepAwake, s.KeepAwakeDisplay = cur.WindowMaximised, cur.KeepAwake, cur.KeepAwakeDisplay
s.TrayUsages, s.TrayUsage, s.TrayUsageEvery, s.TrayNoLogos, s.TrayNoBird, s.TrayPace, s.TrayNoCost = cur.TrayUsages, cur.TrayUsage, cur.TrayUsageEvery, cur.TrayNoLogos, cur.TrayNoBird, cur.TrayPace, cur.TrayNoCost
@@ -1322,13 +1330,28 @@ func loadChecked() (Settings, error) {
b, err := through("settings", Path(), func(b []byte) ([]byte, error) { return b, nil })
if err != nil {
if os.IsNotExist(err) {
+ // a new install: With window is its default
+ s.DockSettled = true
return s.normal(), nil
}
- return s.normal(), fmt.Errorf("could not read settings at %s: %w", Path(), err)
+ return s.settleDock().normal(), fmt.Errorf("could not read settings at %s: %w", Path(), err)
}
return parse(b)
}
+// settleDock reads a Dock choice written before With window was the
+// default (DockSettled unset) as that magpie did: no choice is Hide.
+func (s Settings) settleDock() Settings {
+ if s.DockSettled {
+ return s
+ }
+ if !s.Dock && !s.DockWindow && !s.DockNever {
+ s.DockNever = true
+ }
+ s.DockSettled = true
+ return s
+}
+
// parsed is the last settings.json that parsed whole and what it read as,
// before normal (s), and after it for Shared (norm, once asked): a
// gateway request asks for the settings a dozen times over, and parsing
@@ -1358,6 +1381,7 @@ func parse(b []byte) (Settings, error) {
parses.Add(1)
perr := json.Unmarshal(bytes.TrimPrefix(b, []byte("\xef\xbb\xbf")), &s)
if perr == nil {
+ s = s.settleDock()
// only what parsed whole is kept: a last good generation read in
// its place is read again, as is a file that can't be read at all
parsed.Lock()
@@ -1373,7 +1397,7 @@ func parse(b []byte) (Settings, error) {
} else if len(bytes.TrimSpace(bytes.TrimPrefix(b, []byte("\xef\xbb\xbf")))) != 0 {
err = fmt.Errorf("could not read settings at %s: %w", Path(), perr)
}
- return s.normal(), err
+ return s.settleDock().normal(), err
}
// parses counts settings.json's parses (Parses).
@@ -1564,7 +1588,10 @@ func UseRedactModel(name string) error {
// save is called under fileMu. Only the consent setter may replace recording.
func save(s Settings, recording bool) error {
defer filememo.Forget() // read again, where a request holds it
- s = s.normal()
+ // what is written is settled: a Settings read from an older file was
+ // settled as it was read, and one made without reading has its Dock
+ // choice read as that file's would be
+ s = s.settleDock().normal()
if !slices.Contains(Themes, s.Theme) {
return fmt.Errorf("theme must be one of %v, not %q", Themes, s.Theme)
}