gui: the window opens at the size it was last given — a resize is kept once it settles, in settings.json, unless the window is maximised, full screen or minimised
This commit is contained in:
+2
-1
@@ -220,9 +220,10 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
return
|
||||
}
|
||||
// the Settings page sends its own choices; how the agents are
|
||||
// arranged is the Agents page's, and stays as it is
|
||||
// arranged is the Agents page's, and the window's size its own; both stay as they are
|
||||
cur := settings.Load()
|
||||
in.AgentOrder, in.AgentsHidden, in.AgentsShown = cur.AgentOrder, cur.AgentsHidden, cur.AgentsShown
|
||||
in.Window = cur.Window // the window's own, as it was last resized
|
||||
if err := settings.Save(in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
|
||||
+40
-2
@@ -164,12 +164,17 @@ func Run(version string, showMain bool, link string) error {
|
||||
Windows: application.WindowsWindow{HiddenOnTaskbar: true},
|
||||
})
|
||||
|
||||
// the window opens at the size it was last given
|
||||
width, height := 660, 600
|
||||
if s := settings.Load().Window; len(s) == 2 && s[0] >= 560 && s[1] >= 420 {
|
||||
width, height = s[0], s[1]
|
||||
}
|
||||
h.main = h.app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||
Name: "main",
|
||||
Title: "magpie",
|
||||
URL: "/?" + theme,
|
||||
Width: 660,
|
||||
Height: 600,
|
||||
Width: width,
|
||||
Height: height,
|
||||
MinWidth: 560,
|
||||
MinHeight: 420,
|
||||
Hidden: true,
|
||||
@@ -179,6 +184,32 @@ func Run(version string, showMain bool, link string) error {
|
||||
TitleBar: application.MacTitleBarHiddenInset,
|
||||
},
|
||||
})
|
||||
// A resize is kept once it settles; a maximised or full-screen window
|
||||
// is the screen's size, not one the user gave it.
|
||||
var resized *time.Timer
|
||||
h.main.OnWindowEvent(events.Common.WindowDidResize, func(*application.WindowEvent) {
|
||||
if resized != nil {
|
||||
resized.Stop()
|
||||
}
|
||||
resized = time.AfterFunc(500*time.Millisecond, func() {
|
||||
if h.main.IsMaximised() || h.main.IsFullscreen() || h.main.IsMinimised() {
|
||||
return
|
||||
}
|
||||
w, ht := h.main.Size()
|
||||
if w < 560 || ht < 420 {
|
||||
return
|
||||
}
|
||||
// macOS reports a window a pixel short of the size it was
|
||||
// opened at; kept as it is, the window would shrink a pixel at
|
||||
// every start
|
||||
s := settings.Load()
|
||||
if len(s.Window) == 2 && abs(s.Window[0]-w) <= 2 && abs(s.Window[1]-ht) <= 2 {
|
||||
return
|
||||
}
|
||||
s.Window = []int{w, ht}
|
||||
settings.Save(s)
|
||||
})
|
||||
})
|
||||
// Closing the window keeps the tray alive; quitting is a menu action.
|
||||
h.main.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
h.main.Hide()
|
||||
@@ -324,3 +355,10 @@ func singleInstance(h *host) *application.SingleInstanceOptions {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func abs(n int) int {
|
||||
if n < 0 {
|
||||
return -n
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ type Settings struct {
|
||||
AgentOrder []string `json:"agentOrder,omitempty"`
|
||||
AgentsHidden []string `json:"agentsHidden,omitempty"`
|
||||
AgentsShown []string `json:"agentsShown,omitempty"`
|
||||
// The main window's size when it was last resized, width and height,
|
||||
// so it opens at it again after a restart.
|
||||
Window []int `json:"window,omitempty"`
|
||||
}
|
||||
|
||||
// Arrange puts items in the order the user gave the agents, those named
|
||||
|
||||
Reference in New Issue
Block a user