Repository navigation
feat: v1.5.0 — full-size content view (#57), configurable hotkey (#41), session persistence (#10) - #58
Conversation
…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
left a comment
There was a problem hiding this comment.
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—.appbuilt, 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:
- At documentStart — a
WKUserScriptinjects--traffic-light-width: 80pxbefore any web content runs. This default prevents content rendering under the traffic lights even on first paint. - After didFinish —
injectTrafficLightWidthVar()measureswindow.standardWindowButton(.zoomButton).frame.maxX + 12and overrides with the exact pixel value..zoomButtonis the rightmost (green) traffic light, and itsframeis in window-space, somaxX + 12is a clean right edge for the web title bar's left margin. Falls back to80if 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. UCKeyTranslatefor printable keys (respects current keyboard layout); symbol table for non-printing keys (arrows, function keys, Return, Tab, Escape, etc.).- Display order
⌃⌥⇧⌘keymatches macOS standard modifier ordering. - Uses semantic colors (
controlAccentColor,controlBackgroundColor,separatorColor,labelColor,secondaryLabelColor,tertiaryLabelColor) — adapts to dark mode automatically.
AppDelegate.setupGlobalHotkey rewrite:
- Reads
keyCodeandmodsfrom UserDefaults instead of hardcodingkVK_ANSI_H/cmdKey | shiftKey. - Skips registration entirely if
globalHotkeyEnabled == false. - Event handler installed only once (
if carbonEventHandler == nil) — important becausereloadGlobalHotkeyis 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 keepCmd+Shift+Hafter 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/Enabledinstance vars.onCapture/onClearonly 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 == connectionModeA 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:
didReportNavigationFailure = false— reset dedup so a real failure on the new attempt routes to the error window.isIntentionalClose = false— defensive, ensureswindowDidExitFullScreendoesn't no-op.webView.stopLoading()— cancels any in-flight provisional load. The cancellation surfaces viadidFailProvisionalNavigationwithNSURLErrorCancelled, which is already short-circuited in the existing handler — so no zombie failure event reachesonNavigationFailed.- Same URL →
webView.reload(); different URL → updatesurlStringandwebView.load(URLRequest).
Window lifecycle on reconnect:
- Reuse path:
orderOut(nil)(hide, don't destroy) →reconnectInPlace→makeKeyAndOrderFront(nil)→setOfflineBadge(false). - Failed reconnect:
browserWindow = nilto drop the hidden controller (ARC deallocates), thenshowErrorWindow. 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
-
reconnectInPlacepre-reload race window — there's a small theoretical window betweendidReportNavigationFailure = falseandwebView.stopLoading()where, if the previous load's failure callback fired with a non-NSURLErrorCancelledcode, it would be re-armed and consume the dedup slot before the new reload can use it. Practically WebKit consistently emitsNSURLErrorCancelledfor stopLoading-cancelled navigations, but reordering the reset to after stopLoading would close even the theoretical hole. -
injectTrafficLightWidthVaronly fires ondidFinish— 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, asetPropertyre-run isn't needed (the value is on documentElement and persists). Just worth noting. -
Working-tree corruption recurrence — the
/tmp/swift-mac-testtest clone arrived with damaged git objects again. Last sprint: working-tree-only damage, recoverable viagit restore .. This sprint: object-DB damage, required full re-clone. Two occurrences in two sprints suggests something is touching.git/objectsbetween 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.
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-titlebarelement (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.fullSizeContentViewto styleMask +titlebarAppearsTransparent = true+titleVisibility = .hidden(window title stays set for accessibility, Dock, Window menu)injectTrafficLightWidthVar(): new helper that measureswindow.standardWindowButton(.zoomButton)?.frame.maxX + 12and injects it as--traffic-light-widthCSS custom property. Default80pxat documentStart, refined to exact pixels indidFinish.windowDidEnterFullScreen: resets var to0px(traffic lights gone in fullscreen)windowDidExitFullScreen: restores measured valuewindow.contentLayoutRect(notcontentView.bounds) to avoid overlapping traffic lightsConfigurable global hotkey — closes #41
The hardcoded Cmd+Shift+H is now user-configurable in Preferences.
Implementation:
HotkeyRecorderView.swift— NSView subclass that arms on click, captures the next keyDown with Cmd/Ctrl/Option modifier, displays the combo symbolically (⌘⇧H etc.). UsesUCKeyTranslatefor keyboard-layout-aware display of printable keys. Bare Delete clears the shortcut; Cmd+Delete can still be bound.PreferencesWindowController: replaced static label withHotkeyRecorderView+ 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).carbonEventHandlerinstalled once; onlycarbonHotKeyRefis re-registered on Preferences save.AppDelegate.reloadGlobalHotkey(): unregisters old hotkey ref, callssetupGlobalHotkey()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:): callswebView.stopLoading()thenreload()(same URL) orload()(URL changed). ResetsdidReportNavigationFailureandisIntentionalClosedefensively.AppDelegate.startTunnel():reuseWindow = browserWindow != nil && browserWindow?.connectionMode == connectionMode. On reuse:orderOut(nil)(hide, don't destroy) + callreconnectInPlace()on success. On failure or mode switch: fall back to full window rebuild.urlStringandconnectionModeonBrowserWindowControllerchanged fromprivate lettoprivate(set) varto support URL/mode updates.Pre-merge checklist
Expected: build complete, all tests pass,
bash build.shproduces Hermes Agent.app.Closes #57, closes #41, closes #10