Skip to content

feat: v1.5.0 — full-size content view (#57), configurable hotkey (#41), session persistence (#10) - #58

Merged
nesquena-hermes merged 1 commit into
mainfrom
sprint-v1.5.0
Apr 25, 2026
Merged

nesquena-hermes merged 1 commit into
mainfrom
sprint-v1.5.0

Conversation

@nesquena-hermes

Copy link
Copy Markdown
Collaborator

Summary

Three quality-of-life improvements in one sprint: full-size content view, configurable global hotkey, and session persistence across reconnects.


Changes

Full-size content view — closes #57

Web content now extends under the native macOS title bar. The web app's custom .app-titlebar element (shipped with the transcript redesign in web UI PR #587, now merged) fills the title bar region, eliminating the doubled native/web header.

Implementation:

  • BrowserWindowController.init: added .fullSizeContentView to styleMask + titlebarAppearsTransparent = true + titleVisibility = .hidden (window title stays set for accessibility, Dock, Window menu)
  • injectTrafficLightWidthVar(): new helper that measures window.standardWindowButton(.zoomButton)?.frame.maxX + 12 and injects it as --traffic-light-width CSS custom property. Default 80px at documentStart, refined to exact pixels in didFinish.
  • windowDidEnterFullScreen: resets var to 0px (traffic lights gone in fullscreen)
  • windowDidExitFullScreen: restores measured value
  • Find bar anchored to window.contentLayoutRect (not contentView.bounds) to avoid overlapping traffic lights

Configurable global hotkey — closes #41

The hardcoded Cmd+Shift+H is now user-configurable in Preferences.

Implementation:

  • New file: HotkeyRecorderView.swift — NSView subclass that arms on click, captures the next keyDown with Cmd/Ctrl/Option modifier, displays the combo symbolically (⌘⇧H etc.). Uses UCKeyTranslate for keyboard-layout-aware display of printable keys. Bare Delete clears the shortcut; Cmd+Delete can still be bound.
  • PreferencesWindowController: replaced static label with HotkeyRecorderView + hint label. Changes are staged in pending vars and only written to UserDefaults on Save (Cancel discards).
  • AppDelegate.setupGlobalHotkey(): reads keyCode/modifiers from UserDefaults (defaults registered at launch). carbonEventHandler installed once; only carbonHotKeyRef is re-registered on Preferences save.
  • AppDelegate.reloadGlobalHotkey(): unregisters old hotkey ref, calls setupGlobalHotkey() with new values, shows NSAlert if registration fails (e.g. Cmd+Space claimed by Spotlight).

Session persistence on reconnect — closes #10

Tunnel drops, network blips, and manual reconnects no longer destroy the WKWebView. localStorage, cookies, IndexedDB, and scroll position survive.

Implementation:

  • BrowserWindowController.reconnectInPlace(targetURL:): calls webView.stopLoading() then reload() (same URL) or load() (URL changed). Resets didReportNavigationFailure and isIntentionalClose defensively.
  • AppDelegate.startTunnel(): reuseWindow = browserWindow != nil && browserWindow?.connectionMode == connectionMode. On reuse: orderOut(nil) (hide, don't destroy) + call reconnectInPlace() on success. On failure or mode switch: fall back to full window rebuild.
  • urlString and connectionMode on BrowserWindowController changed from private let to private(set) var to support URL/mode updates.

Pre-merge checklist

  • Mac agent build verification (required — Swift cannot run on the Linux server):
cd /tmp/swift-mac-test
git clone https://github.com/hermes-webui/hermes-swift-mac . 2>/dev/null || true
git fetch origin && git checkout sprint-v1.5.0 && git pull --rebase

swift package resolve
swift build -c release 2>&1
swift test 2>&1
bash build.sh 2>&1

/usr/libexec/PlistBuddy -c "Print :SUPublicEDKey" "Hermes Agent.app/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Print :SUFeedURL" "Hermes Agent.app/Contents/Info.plist"

Expected: build complete, all tests pass, bash build.sh produces Hermes Agent.app.

  • Independent review from nesquena account
  • Verify traffic lights align correctly (not obscured by web content)
  • Verify Preferences hotkey recorder: click to arm, press combo, Save, shortcut fires
  • Verify session persists across Cmd+R reconnect and tunnel drop

Closes #57, closes #41, closes #10

…ersistence on reconnect

Closes #57: .fullSizeContentView + transparent titlebar so web app's custom
.app-titlebar fills the native title bar region. Traffic light clearance
injected as --traffic-light-width CSS var (80px default at documentStart,
refined to exact measured pixels after first paint). Resets to 0px in
fullscreen, restores on exit. Find bar now anchors to contentLayoutRect to
avoid overlapping traffic lights.

Closes #41: Global hotkey is now configurable in Preferences. New
HotkeyRecorderView captures any Cmd/Ctrl/Option combo. Changes are staged
until Save (Cancel discards). AppDelegate.reloadGlobalHotkey() applies the
new shortcut after save. Registration failure shown via NSAlert. Bare Delete
clears the shortcut; Cmd+Delete etc. can still be bound.

Closes #10: startTunnel() now reuses the existing BrowserWindowController
on reconnect (orderOut instead of close) preserving localStorage, cookies,
IndexedDB, and scroll position. reconnectInPlace() on BrowserWindowController
calls webView.stopLoading() + reload()/load() as appropriate. Window is only
rebuilt when connectionMode changes or on a failed reconnect.

@nesquena nesquena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Mac agent at tip 30349a8.

Build/test results

  • swift build -c release — Build complete (7.10s, 0 warnings)
  • swift test — 22/22 passed (4 suites: PortValidationTests + SSHArgumentTests + URLValidationTests + LaunchBehaviorTests)
  • bash build.sh — .app built, ad-hoc signed, installed to /Applications

Scope: 446/-48 across 5 files. Matches the PR description: three issues in one commit (#57 full-size content view, #41 configurable hotkey, #10 session persistence).

Verification clean clone — the previous test clone at /tmp/swift-mac-test had object-database corruption (git fsck reported many missing trees and blobs, git restore failed with "unable to read sha1 file"). Re-cloned from origin to recover; same as documented in the skill's gotcha section.

Code review

Issue #57 — full-size content view + traffic light width injection.

Window mask gains .fullSizeContentView; titlebarAppearsTransparent = true; titleVisibility = .hidden (the title text is hidden from the title bar but window.title still feeds the Window menu, Dock, Mission Control, and accessibility). Standard recipe for "web app paints under the title bar".

The two-stage CSS variable injection is the right pattern:

  1. At documentStart — a WKUserScript injects --traffic-light-width: 80px before any web content runs. This default prevents content rendering under the traffic lights even on first paint.
  2. After didFinish — injectTrafficLightWidthVar() measures window.standardWindowButton(.zoomButton).frame.maxX + 12 and overrides with the exact pixel value. .zoomButton is the rightmost (green) traffic light, and its frame is in window-space, so maxX + 12 is a clean right edge for the web title bar's left margin. Falls back to 80 if the button reference is unavailable.

Fullscreen handling is symmetric: windowDidEnterFullScreen resets to '0px' (no traffic lights to clear); windowDidExitFullScreen re-runs injectTrafficLightWidthVar(). The JS interpolates an Int, so no escaping concern.

Find bar position fix: previous code anchored to contentView.bounds.height - barHeight, which now overlaps the traffic lights because the contentView extends under the title bar. Fixed by anchoring to window.contentLayoutRect.maxY (the area below the native title bar). Same change in hideFindBar to keep the webView restore consistent. bar.autoresizingMask = [.width, .minYMargin] is correct — the bar stays anchored near the top regardless of window resize.

Issue #41 — configurable global hotkey.

HotkeyRecorderView (new, 215 lines):

  • Click-to-arm via becomeFirstResponder, drops focus on capture/clear/cancel.
  • Bare-vs-modifier Delete handling (the Opus catch): let usableModsForClear = [.command, .control, .option]; bare Delete (no Cmd/Ctrl/Option) clears, but Cmd+Delete falls through and gets captured as a normal hotkey. Correct semantics.
  • Letter-without-modifier guard: NSSound.beep() and don't capture — prevents pure-letter global hotkeys that would intercept normal typing.
  • TIS API retain semantics (the other Opus catch): TISCopyCurrentKeyboardLayoutInputSource() is Copy-style → takeRetainedValue(). TISGetInputSourceProperty() is Get-style → Unmanaged.fromOpaque(ptr).takeUnretainedValue(). Both correct, and the comments call out the ownership reasoning.
  • UCKeyTranslate for printable keys (respects current keyboard layout); symbol table for non-printing keys (arrows, function keys, Return, Tab, Escape, etc.).
  • Display order ⌃⌥⇧⌘key matches macOS standard modifier ordering.
  • Uses semantic colors (controlAccentColor, controlBackgroundColor, separatorColor, labelColor, secondaryLabelColor, tertiaryLabelColor) — adapts to dark mode automatically.

AppDelegate.setupGlobalHotkey rewrite:

  • Reads keyCode and mods from UserDefaults instead of hardcoding kVK_ANSI_H / cmdKey | shiftKey.
  • Skips registration entirely if globalHotkeyEnabled == false.
  • Event handler installed only once (if carbonEventHandler == nil) — important because reloadGlobalHotkey is called on every Preferences save, and a stack of identical handlers would fire the callback N times per keypress.
  • Defaults registered via UserDefaults.standard.register(defaults: [...]) so existing users keep Cmd+Shift+H after upgrade without overwriting any value they later customize.

reloadGlobalHotkey: unregisters the existing hotkey ref (only the ref, not the handler), calls setupGlobalHotkey to register a new ref with the new keys, and shows an NSAlert "Shortcut unavailable" if the user wanted it enabled but registration failed (e.g. Cmd+Space taken by Spotlight). The globalHotkeyEnabled && carbonHotKeyRef == nil check correctly distinguishes "user disabled it" from "OS rejected it".

Pending-edit pattern in PreferencesWindowController (the Cancel-discards Opus catch):

  • pendingHotkeyKeyCode/Modifiers/Enabled instance vars.
  • onCapture / onClear only set the pending vars — no UserDefaults writes.
  • save() writes the pending values to UserDefaults.
  • Cancel just closes — pending values are discarded with the controller. Correct.

Issue #10 — session persistence on reconnect.

The reuse decision is gated on connection-mode parity:

let reuseWindow = browserWindow != nil &&
    browserWindow?.connectionMode == connectionMode

A direct↔ssh switch correctly falls through to the rebuild path because the SSH status bar wouldn't be wired up otherwise (this was the Opus mode-switch catch). connectionMode and urlString were promoted to private(set) var so AppDelegate can read them and reconnectInPlace can rewrite urlString.

reconnectInPlace mechanics:

  1. didReportNavigationFailure = false — reset dedup so a real failure on the new attempt routes to the error window.
  2. isIntentionalClose = false — defensive, ensures windowDidExitFullScreen doesn't no-op.
  3. webView.stopLoading() — cancels any in-flight provisional load. The cancellation surfaces via didFailProvisionalNavigation with NSURLErrorCancelled, which is already short-circuited in the existing handler — so no zombie failure event reaches onNavigationFailed.
  4. Same URL → webView.reload(); different URL → updates urlString and webView.load(URLRequest).

Window lifecycle on reconnect:

  • Reuse path: orderOut(nil) (hide, don't destroy) → reconnectInPlace → makeKeyAndOrderFront(nil) → setOfflineBadge(false).
  • Failed reconnect: browserWindow = nil to drop the hidden controller (ARC deallocates), then showErrorWindow. The "abandon the hidden window" comment makes the intent explicit.

Cookies, localStorage, IndexedDB, and scroll position all persist because the WKWebView and its associated WKWebsiteDataStore (the default, persistent one) are unchanged across the reload.

Non-blocking follow-ups

  1. reconnectInPlace pre-reload race window — there's a small theoretical window between didReportNavigationFailure = false and webView.stopLoading() where, if the previous load's failure callback fired with a non-NSURLErrorCancelled code, it would be re-armed and consume the dedup slot before the new reload can use it. Practically WebKit consistently emits NSURLErrorCancelled for stopLoading-cancelled navigations, but reordering the reset to after stopLoading would close even the theoretical hole.

  2. injectTrafficLightWidthVar only fires on didFinish — for SPA route changes within the same document, it doesn't re-run (because didFinish is gated on full-frame loads). If the web app's title-bar component depends on the var being re-asserted across SPA transitions, a setProperty re-run isn't needed (the value is on documentElement and persists). Just worth noting.

  3. Working-tree corruption recurrence — the /tmp/swift-mac-test test clone arrived with damaged git objects again. Last sprint: working-tree-only damage, recoverable via git restore .. This sprint: object-DB damage, required full re-clone. Two occurrences in two sprints suggests something is touching .git/objects between sessions. Worth investigating whether a hook, Spotlight, Time Machine, or something else is at play. Documented the failure mode in the skill's gotcha section.

Ready to merge and tag v1.5.0.

@nesquena-hermes
nesquena-hermes merged commit 7690df9 into main Apr 25, 2026
1 check passed
@nesquena-hermes
nesquena-hermes deleted the sprint-v1.5.0 branch April 25, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants