Repository navigation
fix(main): add Linux title-bar fallback controls - #509
Conversation
Fixes #461 Phase 2 of #457: detect at runtime when Electron's native titleBarOverlay cannot be relied on and fall back to renderer-drawn caption controls instead of shipping a hidden bar with no controls. - main/window-options.ts: add resolveTitleBarMode() gating on platform, Electron major >= 33, and a setTitleBarOverlay API probe; createMainWindow() omits titleBarOverlay options in 'html-fallback' mode; add applyWindowControlAction() for the validated verb set. - main/index.ts: resolve the mode once per window creation and report it to the renderer via get-status as titleBarMode. - main/ipc.ts + preload.ts: one narrow window-action IPC channel (minimize | toggle-maximize | close); close routes through BrowserWindow.close() so close-to-tray semantics match the native button. - frontend TitleBar: mount minimal min/max/close controls only when main reports 'html-fallback'; styled with logical CSS properties (RTL-safe). - i18n: common.minimize/maximize/windowControls keys across en/es/pt/fa. - docs/title-bar-phase1.md: Debian GNOME verification evidence (2026-08-24), GNOME close-only default layout, safe-area behavior, fallback engagement; xvfb screenshot CI documented as follow-up. - tests: mode-resolution matrix, fallback window options, window-action verb validation, and updated preload contract surface. Verification: test:titlebar-window-options, test:electron-api-contract, test:kds-window-hardening, test:translations, lint (0 errors), backend build, frontend tsc --noEmit all pass.
Greptile SummaryThe PR adds runtime title-bar overlay gating, renderer-provided fallback caption controls, and an epoch-and-nonce readiness handshake for the main Electron window. The status-failure and reload paths still permit a visible fallback window without caption controls.
Confidence Score: 4/5The PR does not yet appear safe to merge because fallback windows can still remain visible without minimize, maximize, or close controls after status or reload failures. The new timeout prevents an indefinitely invisible window, and epoch validation prevents stale readiness, but the fail-safe displays an unverified fallback document while reload failures leave an already-visible window in place; both paths can expose hidden-titlebar windows whose renderer controls never mount. Files Needing Attention: frontend/src/components/layout/WindowControls.tsx, main/index.ts, main/window-readiness.ts, main/window-options.ts
|
| Filename | Overview |
|---|---|
| frontend/src/components/layout/WindowControls.tsx | Adds renderer caption controls and readiness reporting, but status-resolution failure still leaves the fail-safe able to expose a fallback window without controls. |
| main/window-readiness.ts | Adds epoch-and-nonce readiness validation and a timeout that deliberately shows unconfirmed renderer documents. |
| main/index.ts | Resets readiness on navigation, but leaves an already-visible fallback window exposed if the replacement document fails to restore its controls. |
| main/window-options.ts | Adds capability-based overlay selection and intentionally retains hidden title-bar styling when renderer fallback controls are required. |
| main/ipc.ts | Adds narrow validated window-action and document-bound readiness IPC handlers. |
| main/preload.ts | Exposes the narrow control surface and automatically binds readiness reports to a per-document nonce. |
Sequence Diagram
sequenceDiagram
participant Main
participant Renderer
Main->>Main: Create hidden fallback window
Main->>Main: Begin readiness epoch
Renderer->>Main: getStatus()
alt Status and controls resolve
Renderer->>Renderer: Mount fallback controls
Renderer->>Main: windowReady(epoch + preload nonce)
Main->>Main: Show window
else Status/load fails
Main->>Main: 10-second fail-safe
Main->>Main: Show window without verified controls
end
Reviews (3): Last reviewed commit: "no-mistakes(document): Clarify title-bar..." | Re-trigger Greptile
Address two review findings on the fallback title-bar readiness path: 1. WindowControls now signals windowReady() immediately on mount and again from a 3s fail-safe timer, independent of getStatus() resolution, so a rejected/hanging/unknown-mode status can never leave the hidden frame window invisible indefinitely. Mode defaults to 'html-fallback' and only upgrades to 'native-overlay' when main explicitly confirms it: failure falls toward visible controls, never a control-less hidden bar. 2. Main resets the renderer readiness flag on every did-start-loading navigation (initial load, manual reload, crash recovery), so readiness is per-document and a reload that fails to re-mount the root chrome cannot inherit a stale ready flag while its caption controls are gone. Docs updated to describe both fail-safe behaviors.
Replace the point-fix readiness patches with one coherent per-document lifecycle in main/window-readiness.ts: - Every document load (window creation and each did-start-loading) begins a new readiness epoch, invalidating prior documents' reports and re-arming a bounded fail-safe. - get-status now exposes titleBarEpoch; the renderer binds its windowReady report to it and reports only once its control surface exists (native caption buttons for overlay mode; after fallback buttons commit to DOM). - The window-ready IPC rejects stale or malformed epochs instead of showing the window, so a reload can never inherit a previous document's readiness. - If the current epoch never confirms (getStatus rejection/hang, renderer failure before mount), main's 10s fail-safe shows the window anyway and logs loudly: visible beats invisible forever. Tests: new tests/window-readiness.test.ts covers reject path (malformed reports + fail-safe firing exactly once), reload path (stale-epoch invalidation, inert superseded timers), and fail-safe cancellation on confirmation. Contract test updated for the epoch-bound payload. Docs updated to describe the epoch lifecycle.
… and version validation
Intent
Implement Linux title-bar fallback controls for the FloCafe desktop POS (epic #457, slice 2; PR must carry "Fixes #461"). Goal: on systems where Electron's native titleBarOverlay is unavailable or broken at runtime, the main window must never ship as a hidden bar with no controls.
Accepted requirements in current form:
This run revalidates after fixing two review findings: (a) fail-safe windowReady() signaling in WindowControls.tsx so mode-resolution failure cannot leave the hidden BrowserWindow invisible indefinitely; (b) per-document readiness reset via did-start-loading in main/index.ts so reloads cannot leave a stale ready flag with unmounted controls.
Boundaries: do NOT touch nativeTheme/setTitleBarOverlay color logic or macOS traffic-light positioning (owned by sibling slice flocafe-457-slice1-theme-bar). No changes to KDS/print window options. Electron pinned at 43.4.0. No AI attribution in commits.
Environment notes for pipeline validation: pipeline worktree starts without node_modules - run npm ci before testing; use assertion/log-based evidence only, no screenshot capture. Relevant checks: npm run test:titlebar-window-options, test:electron-api-contract, test:kds-window-hardening, test:translations, npm run lint, npm run build, frontend tsc --noEmit / i18n:check.
What Changed
titleBarOverlayon supported platform, Electron version, and runtime API availability; unsupported or unavailable overlays use the hidden-window HTML fallback path.windowActionIPC, with close routed throughBrowserWindow.close()and logical RTL-safe title-bar styling.Risk Assessment
🚨 High: The status-resolution failure path can still expose a fallback window without any controls, contradicting the core acceptance invariant; macOS also has a reachable duplicate-controls case.
Testing
Focused title-bar, IPC, readiness, KDS, printer, restore, and translation tests passed. Backend and renderer production builds also passed, including TypeScript compilation and static page generation. No screenshot was captured because this phase explicitly requires assertion/log-based evidence only. Generated build and dependency artifacts were removed from the worktree.
Evidence: Title-bar behavior evidence
Evidence: KDS verification log
KDS sender-hardening and window-construction verification passed.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
main/ipc.ts:255- Readiness accepts any report whose epoch matches the mutable global epoch. During reload, an old document’s delayed getStatus() can receive the new epoch and then be accepted by this handler, clearing the new document’s fail-safe. Bind reports to a document/frame-specific token or identity, not only the current epoch number.main/index.ts:360- The fail-safe shows the window but leaves readiness false. After a status failure, tray Show, second-instance focus, and macOS activate all call showMainWindow(), which rejects the window and cannot restore it after it is hidden. Track the fail-safe-surfaced state separately or allow recovery through that path.frontend/src/components/layout/WindowControls.tsx:73- When the overlay API is absent on macOS, this mode still uses hiddenInset, which retains native traffic-light controls, while WindowControls also mounts the HTML min/max/close strip. The fallback can therefore display duplicate caption controls; clarify whether macOS should retain native traffic lights or use HTML controls exclusively.main/window-options.ts:40- The defensive parser uses parseInt, so electronVersion='33oops' is treated as major 33 and selects native-overlay. That malformed version should fail closed under the stated runtime-gating invariant; validate the version format before accepting the major.🔧 Fix: Hardened title-bar readiness identity, recovery, and version validation
2 issues (1 error, 1 warning) still open:
main/ipc.ts:257- Readiness identity is still frame-scoped, not document-scoped.isCurrentRendererFramecompares onlysenderFrame.frameTokenwithevent.sender.mainFrame; during a same-origin reload, an old document can invokegetStatus()after the global epoch increments, receive the new epoch, pass line 257 while its frame is still current, and then mark the new document ready at line 264. Bind status/readiness to a document-scoped navigation nonce instead. Electron’s frame token identifies a frame/RenderFrameHost rather than a document: Electron WebFrameMain, Chromium frame-token lifetime.main/index.ts:402- The readiness gate is bypassed becauserestore()runs beforeshowMainWindow(). A fallback window minimized during a reload has readiness reset; launching a second instance or using the tray restores it visibly, then the readiness check returns false. This can expose the hidden-title-bar document before fallback controls remount. Move restore inside the readiness-approved show path (the same ordering appears in the tray handlers).🔧 Fix: Bind readiness to document nonces and gate window restoration
2 issues (1 error, 1 warning) still open:
frontend/src/components/layout/WindowControls.tsx:47- Criterion 3 requires readiness and visible controls to fail toward visible controls. IfgetStatus()rejects or hangs on a Linux fallback window,resolvedstays null, the component returns null, and the main fail-safe eventually shows a window with no controls. This still reaches the prohibited hidden-bar/no-controls failure path during mode-resolution failure; make the fallback controls/readiness path independent of this failure or explicitly approve the containment.main/window-options.ts:64- On macOS fallback (missing overlay API or an older Electron),hiddenInsetretains native traffic-light buttons whileWindowControlsrenders the HTML fallback for everyhtml-fallbackmode. Users can therefore see duplicate caption controls. Decide whether macOS should retain native traffic lights or suppress the HTML fallback in this mode.✅ **Test** - passed
✅ No issues found.
npm run test:titlebar-window-optionsnpm run test:electron-api-contractnpm run test:window-readinessEVIDENCE_DIR=~/.no-mistakes/evidence/01M0STCNAAD8W0VMJ2E6GMDE78 npm run test:kds-window-hardeningnpm run test:translationsnpm run test:printer-ipcnode tests/run-electron-node-test.cjs tests/restore-managed-path.test.tsnpm run buildcd frontend && npm ci --no-audit --no-fundcd frontend && npm run buildgit diff --check✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.