Skip to content

fix(main): add Linux title-bar fallback controls - #509

Merged
khaira777 merged 11 commits into
mainfrom
fm/flocafe-457-slice2-linux-fallback
Aug 24, 2026
Merged

khaira777 merged 11 commits into
mainfrom
fm/flocafe-457-slice2-linux-fallback

Conversation

@khaira777

@khaira777 khaira777 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Runtime overlay-availability gating in main: resolveTitleBarMode gating on platform + Electron major >= 33 plus a runtime capability probe (setTitleBarOverlay API presence); when unavailable, build the window without titleBarOverlay options (fallback mode) instead of hidden-with-no-controls. Keep runtime gating defensive; do not assume X11/Wayland behavior.
  2. HTML fallback controls: when falling back, render minimal min/max/close controls in the renderer TitleBar wired through ONE narrow windowAction IPC (minimize | toggle-maximize | close) across main/ipc.ts handler + main/preload.ts + frontend electron.d.ts. Context isolation unchanged; no broad IPC surface. Close must route through BrowserWindow.close() so close-to-tray behavior in main/index.ts is identical to the native close button.
  3. Renderer integration: fallback controls only mount when main reports fallback mode via the capability surface (getStatus payload titleBarMode field); styled with logical CSS properties (RTL-safe) consistent with existing flo-title-bar classes. Readiness must be fail-safe: windowReady() signaling and visible-controls defaulting must not depend on mode resolution succeeding (fail toward VISIBLE controls), and renderer readiness must reset per document load so reloads cannot inherit a stale ready flag.
  4. Documentation: docs/title-bar-phase1.md updated with captain's Debian GNOME verification evidence (2026-08-24, real hardware), GNOME's close-only default button layout and E43+ DE button-layout respect, safe-area behavior, how the fallback decides to engage, and the readiness fail-safe behaviors.
  5. Contract/type tests updated and green: tests/titlebar-window-options.test.ts (mode resolution matrix, fallback window options, window-action verb validation) and tests/electron-api-contract.test.ts (preload surface includes windowAction and windowReady).

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

  • Fixes Phase 2: Linux fallback controls + Electron version gating #461 by gating native titleBarOverlay on supported platform, Electron version, and runtime API availability; unsupported or unavailable overlays use the hidden-window HTML fallback path.
  • Adds localized minimize, maximize, and close controls wired through narrow windowAction IPC, with close routed through BrowserWindow.close() and logical RTL-safe title-bar styling.
  • Adds per-document renderer readiness epochs and fail-safe visibility handling, updates title-bar documentation, and expands contract, window-option, and readiness tests.

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
Title-bar options, fallback gating, narrow IPC actions, preload contract, and readiness fail-safe/reload assertions passed.
Evidence: KDS verification log

KDS sender-hardening and window-construction verification passed.

=== GHSA-jmmq-fjg5-g6px KDS Window & IPC Hardening Verification ===

[Phase 1] Verifying sender identity across 12 non-PIN-gated IPC channels...
  ✓ db-health-check: successfully blocks untrusted senders and admits trusted origins
  ✓ db-apply-safe-fixes: successfully blocks untrusted senders and admits trusted origins
  ✓ master-pin-status: successfully blocks untrusted senders and admits trusted origins
  ✓ get-settings: successfully blocks untrusted senders and admits trusted origins
  ✓ set-setting: successfully blocks untrusted senders and admits trusted origins
  ✓ whatsapp-get-status: successfully blocks untrusted senders and admits trusted origins
  ✓ get-kds-info: successfully blocks untrusted senders and admits trusted origins
  ✓ open-kds-window: successfully blocks untrusted senders and admits trusted origins
  ✓ get-app-info: successfully blocks untrusted senders and admits trusted origins
  ✓ get-printers: successfully blocks untrusted senders and admits trusted origins
  ✓ save-printer: successfully blocks untrusted senders and admits trusted origins
  ✓ get-daily-summary: successfully blocks untrusted senders and admits trusted origins

[Phase 2] Verifying PIN-gated handlers require authorization...
  ✓ backup-database: successfully protected by master PIN

[Phase 3] Verifying KDS window construction and bridge removal...
  ✓ BrowserWindow webPreferences: preload=undefined, contextIsolation=true, nodeIntegration=false

[Phase 4] Verifying KDS window navigation confinement...
  ✓ will-navigate strictly confines navigation to http://192.168.1.50:3002
  ✓ windowOpenHandler denies all popup/new-window requests

✅ All KDS window hardening and IPC security checks passed successfully.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 error, 1 warning)
  • 🚨 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. isCurrentRendererFrame compares only senderFrame.frameToken with event.sender.mainFrame; during a same-origin reload, an old document can invoke getStatus() 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 because restore() runs before showMainWindow(). 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. If getStatus() rejects or hangs on a Linux fallback window, resolved stays 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), hiddenInset retains native traffic-light buttons while WindowControls renders the HTML fallback for every html-fallback mode. 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-options
  • npm run test:electron-api-contract
  • npm run test:window-readiness
  • EVIDENCE_DIR=~/.no-mistakes/evidence/01M0STCNAAD8W0VMJ2E6GMDE78 npm run test:kds-window-hardening
  • npm run test:translations
  • npm run test:printer-ipc
  • node tests/run-electron-node-test.cjs tests/restore-managed-path.test.ts
  • npm run build
  • cd frontend && npm ci --no-audit --no-fund
  • cd frontend && npm run build
  • git diff --check
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The 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.

  • Adds narrow minimize, maximize/restore, and close IPC actions.
  • Resets renderer readiness for each document and introduces a bounded visibility fail-safe.
  • Updates title-bar styling, translations, documentation, and contract tests.

Confidence Score: 4/5

The 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

Important Files Changed

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
Loading

Reviews (3): Last reviewed commit: "no-mistakes(document): Clarify title-bar..." | Re-trigger Greptile

Comment thread main/window-readiness.ts Resolved
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.
Comment thread main/index.ts Resolved
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.
@khaira777 khaira777 changed the title fix(layout): add Linux title-bar fallback controls fix(main): add Linux title-bar fallback controls Aug 24, 2026
@khaira777
khaira777 merged commit 0afd0d2 into main Aug 24, 2026
13 checks passed
@khaira777
khaira777 deleted the fm/flocafe-457-slice2-linux-fallback branch August 24, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 2: Linux fallback controls + Electron version gating

1 participant