Started without its window (at login, `magpie tray`; for the panel; for a magpie:// link), magpie still made the main window hidden, and its page kept a WebContent process (~66 MB) until the user opened it, which after a boot can be never. On the Mac it is now made by openMain the first time it is shown, the path lightweight mode already takes for a window it let go (madeAgain). A start that shows the window is as before, and Linux and Windows are unchanged (Windows' readiness waits on the main window's page; see #6340 for the panel there). Measured on mote, real window app, real account sandbox HOME, at 30s: - `magpie tray`: v0.1.3916 (w33) WebContent 66 MB; this change none. magpie itself 154-174 MB vs 185-194 MB. - `magpie panel`: one WebContent (the panel's, 70 MB) where w32 had two. - a magpie:// link: the main window made later shows on screen in the same place and size (1540x959 at 190,31, CGWindowList), WebContent 77 MB vs 80 MB. - Start-up CPU in 30s varies 2-10 s for both builds (start-time jobs), no difference between them. Run: go test -run 'Panel|Light|Tray|Main|Window|Dock|Reopen' ./internal/gui (mica, ok, with TestMainOnFirstOpen), go vet ./internal/gui darwin and GOOS=windows. Every h.main use outside the start is nil-guarded already (lightweight mode lets it go). Not run: a real Dock click or tray-menu Open after a hidden start (no ssh-driven click; both go to openMain/reopenMain, which make it when nil, as the link start above did).
41 lines
1.6 KiB
Go
41 lines
1.6 KiB
Go
package gui
|
|
|
|
import "time"
|
|
|
|
// Lightweight mode (settings.Lightweight, #580): a window closed — the
|
|
// panel or the main window — has its webview let go once it has stayed
|
|
// closed a while, and is made again the next time it is opened. Its web
|
|
// content process (a hundred MB or so on a Mac) ends with it; the next open
|
|
// draws the page from the start, a moment's wait.
|
|
|
|
// lightEvery is how often the closed windows are looked at, and lightTicks
|
|
// how many looks in a row have to find one closed before it goes: a window
|
|
// is let go 30 to 60 s after it was closed, so a panel opened again soon
|
|
// after is the same one, at once.
|
|
const (
|
|
lightEvery = 30 * time.Second
|
|
lightTicks = 2
|
|
)
|
|
|
|
// lightStep is one look at a window: ticks is how many looks in a row have
|
|
// found it closed before this one. It says that count now and whether the
|
|
// window's webview is to go. With the mode off, or the window shown, the
|
|
// count starts over.
|
|
func lightStep(on, shown bool, ticks int) (int, bool) {
|
|
if !on || shown {
|
|
return 0, false
|
|
}
|
|
ticks++
|
|
return ticks, ticks >= lightTicks
|
|
}
|
|
|
|
// panelOnFirstOpen says whether the tray panel is made the first time it is
|
|
// opened rather than as magpie starts: on the Mac, where a hidden panel's
|
|
// page kept a WebContent process of its own (~67 MB) for nothing.
|
|
func panelOnFirstOpen(goos string) bool { return goos == "darwin" }
|
|
|
|
// mainOnFirstOpen says whether the main window is made the first time it is
|
|
// shown rather than as magpie starts: on the Mac, when it starts without the
|
|
// window (showMain false: at login, for the panel or a link).
|
|
func mainOnFirstOpen(goos string, showMain bool) bool { return goos == "darwin" && !showMain }
|