Files
magpie/internal/gui/mainwindow.go
T
yetone d3191a51c8 gui: with Hide accounts on, an account's eye shows that one account in this window (yogurt36)
yogurt36 on Discord, for a screen share: with Hide accounts on, one
account should be readable while the others stay masked. Now an
account's name on the provider editor's row (accountNameButton and the
one-account line) and on its Usage card (quotaWho) has a quiet eye, in
sight on hover or keyboard focus, with an aria-label. A click shows
that account, its address and the name the user gave it together
(kin), everywhere the window draws it, tooltips included: the shown
set is skipped in hits(), which every mask goes through. It lives in
memory only. The tray panel keeps hiding it, and closing the window
hides it again: the page stays loaded while the window is hidden, so
hideMain runs mainClosedJS (hideAccounts.closed) first. With Hide
accounts off there is no eye. Strings in zh, zh-TW, ja and de.

Run (macOS, playwright 1.62.0, rebased on 630fd1d69; at push 0f6615ffc, site only, came under it):
- account-eye.test.cjs: 20/20 in chromium and webkit, en zh zh-TW ja
  de, 900px and 360px (no select, no stripe, no sideways scroll, a
  click scrolls nothing, Tab (Alt+Tab in WebKit) reaches the eye).
- Red on the old code (feature stashed): both tests fail.
- Broken by hand, each red, then restored: the shown check in hits();
  closed() without shown.clear(); kin() returning only the address.
- TestClosingHidesShownAccounts (new): red without shown.clear() and
  without the ExecJS(mainClosedJS) call in hideMain.
- go test -run 'TestCoreScriptBudget|TestBuiltinClientsLoaded|
  TestClosingHidesShownAccounts' ./internal/gui: ok. app.js
  1,306,355 bytes, under 1,321,319; budgets not raised.
- i18n-keys.test.cjs: 4/4.
- gofmt -l clean; go vet (mac), GOOS=linux go vet -tags nogui,
  GOOS=windows go vet ./internal/gui; go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.

After the last rebase one chromium en/zh run of account-eye showed 1
fail of 4 with 179MiB free on the disk; its log wasn't kept, so the
test is unnamed. Every run since, with its log kept, passed: 4/4 and
then 20/20 in both engines.

Not run: the whole GUI suite and the full go test ./internal/gui
(another session's suite held the machine and the disk was full; one
link hit ENOSPC and passed on retry). They run after the push.
Not tried: the real Wails window's close (hideMain) by hand.
2026-10-26 18:18:24 +08:00

84 lines
2.8 KiB
Go

//go:build !nogui
package gui
import (
"time"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/yetone/magpie/internal/settings"
)
// mainMacWindow: the main window's Mac options. A window belongs to the
// Space it was last shown on, and showing it again takes the user there; one
// first shown while another app was full screen (a restart to update, with
// the user in that app) belonged to that app's Space from then on, and every
// Open went back to it. It moves to the Space the user is on whenever it is
// shown instead, and can still be made full screen itself. Once shown it
// stays on its Space (showHere), so a click on the Dock icon goes to it there
// (reopenMain).
func mainMacWindow() application.MacWindow {
return application.MacWindow{
// no InvisibleTitleBarHeight: that strip drags from anywhere in
// it, tabs included; the header marks what drags instead. On
// macOS 26 and later its toolbar is taken off once it has placed
// the traffic lights (plainTitlebar)
TitleBar: application.MacTitleBarHiddenInset,
CollectionBehavior: application.MacWindowCollectionBehaviorMoveToActiveSpace |
application.MacWindowCollectionBehaviorFullScreenPrimary,
}
}
type closeAction int
const (
closeHide closeAction = iota // hide the window now
closeLeaveFullscreen // leave full screen, then hide it
)
// closeStep: what closing the main window does. A full-screen window on the
// Mac hidden as it is leaves its Space behind, black, with nothing in it; it
// leaves full screen first and is hidden once it has.
func closeStep(goos string, fullscreen bool) closeAction {
if goos == "darwin" && fullscreen {
return closeLeaveFullscreen
}
return closeHide
}
// mainClosedJS tells the page its window was closed: an account shown
// while Hide accounts is on (its eye) is hidden again, as each is shown for
// the window's session only (yogurt36 on Discord). The page stays loaded
// while the window is hidden, so it can't tell by itself.
const mainClosedJS = "window.hideAccounts?.closed?.()"
// hideMain hides the main window, and takes magpie out of the Dock if it is
// there only while the window is shown.
func (h *host) hideMain() {
application.InvokeSync(func() {
if h.main != nil {
h.main.ExecJS(mainClosedJS)
h.main.Hide()
}
})
h.dock(settings.Load(), false)
}
// leaveFullscreenThenHide takes the closed full-screen window out of full
// screen; WindowDidExitFullScreen hides it. Should that never come (the
// system refused to leave), it is hidden after a while all the same.
func (h *host) leaveFullscreenThenHide() {
h.closing.Store(true)
application.InvokeSync(func() {
if h.main != nil {
h.main.UnFullscreen()
}
})
time.AfterFunc(3*time.Second, func() {
if h.closing.Swap(false) {
application.InvokeAsync(h.hideMain)
}
})
}