gui/window: keep the window frame across starts, take the first click

- Options.FrameFile: the window's position, size and maximized state in
  a small JSON file, read at New (a frame on no connected screen is
  ignored, the window opens centered), written shortly after every move
  or resize and at Destroy. macOS: NSWindow frame (the normal frame
  under a zoomed one), checked against NSScreen visible frames; Windows:
  Get/SetWindowPlacement, checked with MonitorFromRect.
- macOS: the web view is a WKWebView subclass that accepts the first
  mouse click, so a page in an inactive window reacts to it instead of
  the click only activating the window (yanks' start dialog).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-11-15 15:19:45 +01:00
1 parent c16b871db5
commit 31dbc347e8
9 files changed
+325 -13

No files matched your search

+9 -1
View File
@@ -38,7 +38,7 @@ the main module's `vX.Y.Z` tags do not version this one. Never move a tag.
| `gui/assets` | `NewResolver(sources...)` over `NewFSSource` (embed.FS), `NewDirSource` (os.Root), `NewZipFileSource`/`NewZipBytesSource`; first source that has a file wins, a read error does not fall through. `ValidatePath` (checked, never cleaned), `Join`, `DetectMIME`. |
| `gui/document` | `Prepare(ctx, res, entry, html, Options{Link})`: rewrites `assets:` / relative references in HTML and CSS (`img`, `srcset`, `script`, `link`, `style`, CSS `url()`/`@import`). Link mode -> `/assets/...` URLs, validated against the resolver; inline mode -> typed `data:` URLs (entry <= 1.5 MiB). |
| `gui/bridge` | `NewRouter(res)`, `Router.Handle("POST /rpc/x", h)`, `Router.SetDocument`, `Router.ServeNative` (for the window's resource handler), `Router.HTML` (Go-rendered fragments through `document`). `NewSession(router, Options)` speaks protocol v1 with the page (`hello`/`ready`, `req`/`res`, `chunk`/`end` streams, `abort`, generations). `InitScript(PageConfig)` is the page side (`bridge.js`). |
| `gui/window` | `New(Options{Title, Width, Height, Debug, DataPath, OnMessage, Resource})`, `Init`, `Navigate`, `Run`, `Dispatch`, `Eval`, `Terminate`, `Destroy`, `BaseURL`, `Snapshot` (macOS), `SetAppearance`, `SetAppIcon`, `AccentColor`. |
| `gui/window` | `New(Options{Title, Width, Height, Debug, DataPath, OnMessage, Resource, FrameFile})`, `Init`, `Navigate`, `Run`, `Dispatch`, `Eval`, `Terminate`, `Destroy`, `BaseURL`, `Snapshot` (macOS), `SetAppearance`, `SetAppIcon`, `AccentColor`. |
## Wiring
@@ -70,6 +70,14 @@ w.Destroy() // then: native window, on the UI thread
The WebView2 user-data folder (`DataPath`) belongs under the program's
`core/paths` cache or data directory (`%LOCALAPPDATA%`, never roaming).
`FrameFile` (since `gui/v0.2.0`) keeps the window's position, size and
maximized state across starts: a small JSON file the program places in
its `core/paths` state directory. It is read at `New` -- a frame that is
on no connected screen any more is ignored and the window opens
centered -- and written shortly after every move or resize and at
`Destroy`. The coordinates are the platform's own (macOS: points from
the bottom left; Windows: `WINDOWPLACEMENT`'s normal position).
## Invariants
- **No listener, no ports, no localhost.** After a transport change,