- Resources/Info.plist: NSSupportsSuddenTermination = false, so nothing can skip applicationWillTerminate (invariant 3, contracts C2). That is the only bundle change notifications and login items turned out to need; the work log says what else was checked. - docs/features/app-ui/README.md: Assumptions brought in line with what shipped, Handshakes replaced with the real API (five deviations, all reasoned), one open request to app-engine for a DrawMouseCursor accessor, Status/TODO ticked, work log. - TODO.md §7: three lines ticked; CP1 left for the lead. - UIBridge: dropped an unused openSettings entry point. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
374 lines
20 KiB
Markdown
374 lines
20 KiB
Markdown
# app-ui
|
||
|
||
## Goal
|
||
|
||
The user-facing app: a menu-bar status item that shows every machine in
|
||
the matrix with the Windows status colours and offers the everyday
|
||
actions, and a native settings window that exposes every PowerToys
|
||
setting (README §Settings) plus the Mac-only permissions and
|
||
launch-at-login controls. It replaces the placeholder status item
|
||
app-engine shipped and is the last lane before **CP1**, the first build
|
||
the user tests. Everything the UI does goes through two doors:
|
||
`Engine.observe` for state in, `SettingsStore.update` + `Engine.apply`
|
||
for state out (app-engine Review).
|
||
|
||
## Assumptions
|
||
|
||
- **AppKit for the status item, SwiftUI for the settings window.**
|
||
`NSStatusItem` + `NSMenu` rebuilt on every `EngineSnapshot`; the
|
||
settings window is one `NSWindow` (`.titled, .closable, .miniaturizable`,
|
||
fixed at 560 × 520) hosting an `NSHostingView<SettingsView>`. All UI is
|
||
`@MainActor`; `UIBridge` (in the `mwb` target) receives snapshots on
|
||
whatever thread `observe` delivers and hops to main.
|
||
- **The UI never sees `EngineSnapshot`.** `MWBMac` may import neither
|
||
`MWBNet` nor the executable target (README D2), and `EngineSnapshot`
|
||
lives in `mwb` while `PeerStatus` lives in `MWBNet`. So the status item
|
||
takes `StatusModel`/`MachineRow` — plain `MWBCore`-only values — and
|
||
`UIBridge` is the mapping. This is the one shape change from the
|
||
Handshakes sketch this README used to carry; everything else there
|
||
shipped as written.
|
||
- **Status colours** are the documented table
|
||
(`doc/devdocs/modules/mousewithoutborders.md`): NA `#717171`,
|
||
Resolving yellow, Connecting orange, Handshaking blue, Error red,
|
||
ForceClosed purple, InvalidKey brown `#A52A2A`, Timeout pink
|
||
`#FFC0CB`, SendError maroon `#800000`, Connected green `#008000`. A
|
||
slot with no connection at all shows NA; the local machine shows a
|
||
filled dot in the accent colour.
|
||
- **Menu** (top to bottom): one row per matrix slot "● name — status"
|
||
(the controlled machine gets a check mark; clicking a row switches to
|
||
it, the local row switches home; ⌃⌥F1..F4 shown as **labels** only —
|
||
the real hotkeys are the tap's, which sees them before any menu
|
||
could); then any peer that connected without being in the matrix,
|
||
shown but not clickable; separator; "Control All Computers"
|
||
(`MenuAllPC`, `frmScreen.Designer.cs:174`), "Easy Mouse" (check mark,
|
||
toggles), "Reconnect" and "Lock All Machines", the last two labelled
|
||
with their configured shortcut; separator; the problem lines —
|
||
host-name, permissions ("Permissions: OK" or "Permissions missing: …",
|
||
which opens the Advanced pane), "Cannot inject events", "Input capture
|
||
is not running", and the last recovery (app-engine request 2);
|
||
separator; "Settings…" ⌘,; the version; "Quit Mouse Without Borders"
|
||
⌘Q. The item's icon: two overlapping rounded rectangles drawn in code
|
||
(no asset catalog), a template image so AppKit tints it, with a
|
||
coloured badge — and no longer a template — when anything is wrong.
|
||
- **Settings panes** (a `TabView`, one file each):
|
||
*Machines* — the 4 slots as text fields in a 1×4 or 2×2 grid
|
||
(`MatrixOneRow`), ◀ ▶ (▲ ▼ in two rows) buttons to reorder, "Devices in
|
||
a single row", "Move the mouse back to the first machine when it passes
|
||
the last one" (`WrapMouse`), and this Mac's name with Copy and a "Put
|
||
in slot" menu; *Security* — the key as `SecurityKey.displayText`,
|
||
Show/Hide, New key, Copy, TCP port, and one "Save and reconnect" that
|
||
applies both; *Behaviour* — `HideMouseAtScreenEdge`,
|
||
`MoveMouseRelatively`, `BlockMouseAtScreenCorners`, the Easy Mouse
|
||
picker (`Disable/Enable/Ctrl/Shift`),
|
||
`DisableEasyMouseWhenForegroundWindowIsFullscreen` and its
|
||
excluded-apps list, `ShareClipboard`, `TransferFile`,
|
||
`BlockScreenSaverOnOtherMachines`,
|
||
`ShowClipboardAndNetworkStatusMessages`; *Hotkeys* — recorders for
|
||
toggle Easy Mouse, lock, reconnect and switch-to-all, each with a
|
||
Clear button, plus the switch-machine base key as the PowerToys
|
||
three-way choice; *Network* — `Name2IP` multi-line editor with the
|
||
"name ip" per-line format explained, `ValidateRemoteMachineIP`,
|
||
`SameSubnetOnly`; *Advanced* — Accessibility and Input Monitoring rows
|
||
with state, "Request…" (`Permissions.request()`) and "Open System
|
||
Settings" (`x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility`
|
||
/ `?Privacy_ListenEvent`), "Launch at login" (`SMAppService.mainApp`),
|
||
Show-in-Finder for the settings and log files, and the version, host
|
||
name, machine id and device id. Settings not yet backed by a lane
|
||
(clipboard/extras) are shown and saved — they simply have no effect
|
||
until their lane lands; a footnote on the pane says so.
|
||
- **Hotkey recorder**: an `NSViewRepresentable` that becomes first
|
||
responder on click, records the next key-down with its modifiers
|
||
(`KeyMap.vk(forKeycode:)` for the VK; ⌘→Win, ⌥→Alt, ⌃→Ctrl, ⇧→Shift)
|
||
into a `Hotkey`, shows it as "⌃⌥⌘L", Escape cancels. It never installs
|
||
a global monitor.
|
||
- **Every edit** is `store.update { $0.x = … }` then
|
||
`await engine.apply(store.current)`. The security key, the TCP port,
|
||
the matrix, `Name2IP` and the excluded-apps list are **drafts** with a
|
||
Save button; every other control commits as it changes. The store is
|
||
the only writer of `settings.json` and the Engine is told to re-read —
|
||
there is no second path (app-engine request 1).
|
||
- **Notifications** (`ShowClipboardAndNetworkStatusMessages`,
|
||
`Common.cs` `ShowToolTip` call sites): `UNUserNotificationCenter`
|
||
for "Connected to X" / "Lost X" / "Invalid key for X"; authorization
|
||
requested when the user turns the toggle on; skipped entirely when
|
||
`Bundle.main.bundleIdentifier` is nil (unbundled `swift run`).
|
||
- **Launch at login**: `SMAppService.mainApp.register()` /
|
||
`unregister()`, status from `.status`; disabled with a note when not
|
||
running from a bundle.
|
||
- **Single settings window**: reopening brings it to front; closing
|
||
hides, never terminates (LSUIElement app).
|
||
- **CP1 is the lead's**: after merge the lead runs `tools/bundle.sh`
|
||
and hands over the checklist from TODO §7 and contracts C5.
|
||
|
||
## Handshakes
|
||
|
||
### Consumed
|
||
|
||
- `app-engine`: `Engine.observe`, `EngineSnapshot`, `switchTo(slot:)`,
|
||
`switchToAll`, `reconnect`, `lockAll`, `toggleEasyMouse`, `apply`,
|
||
`recoverLocal(reason:)`, `SettingsStore.update`/`current`/`fileURL`,
|
||
the `Settings` accessors, `Log.fileURL()`, `MWBVersion.string`.
|
||
- `input-capture`: `KeyMap.vk(forKeycode:)`, `Hotkey`, `HotkeyConfig`,
|
||
`Permissions.preflight`/`request`, `PermissionState`.
|
||
- `wire-core`: `SecurityKey.displayText/normalize/isValid/random/minimumLength`.
|
||
- `session-matrix`: `Matrix`, `SocketStatus`.
|
||
- `control-channel`: `PeerStatus` (in `UIBridge` only).
|
||
|
||
Nothing consumed was changed. No file outside this lane's list was
|
||
edited except the status-item parts of `Sources/mwb/AppLifecycle.swift`,
|
||
`Resources/Info.plist` and `TODO.md` §7, all authorised by the brief.
|
||
|
||
### Promised (to clipboard, extras)
|
||
|
||
As shipped 2026-09-16.
|
||
|
||
```swift
|
||
// MWBMac/StatusItem.swift
|
||
public enum StatusColor {
|
||
public static func nsColor(for status: SocketStatus) -> NSColor
|
||
public static var local: NSColor { get }
|
||
public static func name(for status: SocketStatus) -> String
|
||
}
|
||
public struct MachineRow: Sendable, Equatable {
|
||
public var name: String; public var status: SocketStatus
|
||
public var isLocal, isControlled: Bool; public var slot: Int?
|
||
public init(name: String, status: SocketStatus, isLocal: Bool = false,
|
||
isControlled: Bool = false, slot: Int? = nil)
|
||
}
|
||
public struct StatusModel: Sendable, Equatable {
|
||
public var rows: [MachineRow]; public var controlled: String?
|
||
public var broadcasting: Bool; public var easyMouse: EasyMouseMode
|
||
public var missingPermissions: [String]; public var canInject, tapRunning: Bool
|
||
public var hostnameProblem, lastRecovery: String?
|
||
public var lockHotkey, reconnectHotkey: Hotkey
|
||
public var switchMachineVK: Int32; public var version: String
|
||
public init()
|
||
}
|
||
@MainActor public struct StatusActions {
|
||
public var switchTo: (Int) -> Void // matrix slot
|
||
public var switchHome, switchToAll, toggleEasyMouse, reconnect, lockAll, quit: () -> Void
|
||
public var openSettings: (SettingsPane?) -> Void
|
||
}
|
||
@MainActor public final class StatusItemController {
|
||
public init(actions: StatusActions)
|
||
public func update(_ model: StatusModel) // no-op when nothing changed
|
||
public func remove()
|
||
}
|
||
|
||
// MWBMac/SettingsWindow/
|
||
public enum SettingsPane: String, Sendable, CaseIterable {
|
||
case machines, security, behaviour, hotkeys, network, advanced
|
||
public var title: String { get }
|
||
}
|
||
@MainActor public final class SettingsViewModel: ObservableObject {
|
||
public init(store: SettingsStore, localName: String,
|
||
apply: @escaping @Sendable (Settings) async -> Void)
|
||
@Published public private(set) var settings: Settings
|
||
@Published public var securityKeyDraft, portDraft, name2IPDraft, excludedAppsDraft: String
|
||
@Published public var slotDrafts: [String]
|
||
@Published public var showSecurityKey: Bool
|
||
@Published public private(set) var message: String?
|
||
@Published public var permissions: PermissionState
|
||
public let localName: String
|
||
public var settingsFileURL: URL { get }
|
||
public func binding<T: Equatable>(_ keyPath: WritableKeyPath<Settings, T>) -> Binding<T>
|
||
public func commit(_ body: (inout Settings) -> Void)
|
||
public func storeChanged(); public func refreshDrafts(); public func clearMessage()
|
||
public var securityKeyIsValid, matrixHasEdits: Bool { get }
|
||
public func generateKey(); public func copyKey(); public func copyLocalName()
|
||
public func saveConnection(); public func saveMatrix()
|
||
public func swapSlots(_ first: Int, _ second: Int); public func useLocalName(inSlot: Int)
|
||
public func saveName2IP(); public func saveExcludedApps()
|
||
}
|
||
@MainActor public final class SettingsWindowController: NSObject, NSWindowDelegate {
|
||
public init(model: SettingsViewModel)
|
||
public func show(pane: SettingsPane? = nil)
|
||
public var isVisible: Bool { get }
|
||
}
|
||
public enum HotkeyText {
|
||
public static func describe(_ hotkey: Hotkey) -> String // "⌃⌥⌘L"
|
||
public static func switchMachineLabel(_ baseVK: Int32, _ slot: Int) -> String?
|
||
public static func keyName(_ vk: Int32) -> String?
|
||
}
|
||
|
||
// MWBMac/Notifications.swift
|
||
@MainActor public final class Notifier {
|
||
public init(); public var isAvailable: Bool { get }
|
||
public func enabledChanged(_ isOn: Bool)
|
||
public func post(title: String, body: String)
|
||
public func connected(to machine: String); public func lost(_ machine: String)
|
||
public func invalidKey(for machine: String)
|
||
}
|
||
|
||
// MWBMac/LaunchAgent.swift
|
||
public enum LaunchAtLogin {
|
||
public static var isAvailable, isEnabled, needsApproval: Bool { get }
|
||
public static func set(_ enabled: Bool) throws
|
||
}
|
||
```
|
||
|
||
Five deviations from the shape this section sketched at planning time:
|
||
|
||
- **`StatusItemController.update` takes a `StatusModel`, not an
|
||
`EngineSnapshot`** — the layering reason above. `UIBridge` owns the
|
||
mapping, including which of two connections to a peer decides the dot's
|
||
colour.
|
||
- **`StatusActions` gained `switchToAll` and lost nothing.** ALL-machines
|
||
mode is in the Windows tray menu (`MenuAllPC`) and the Engine already
|
||
publishes `broadcasting`, so leaving it out would have made the hotkey
|
||
the only way in.
|
||
- **`SettingsViewModel.init` takes `localName`.** The Machines and
|
||
Advanced panes both show it and the store does not carry it; the
|
||
process resolves it (README D7) and hands it over, exactly as it does
|
||
to the Engine.
|
||
- **`Notifier` is `@MainActor`**, which the sketch did not say: it holds
|
||
the "have we asked for authorization" flag, and everything that calls
|
||
it is main-isolated anyway.
|
||
- **`LaunchAtLogin.isEnabled` is read-only plus `set(_:) throws`**, with
|
||
`needsApproval` added, because `SMAppService` has a third state — the
|
||
registration exists but the user has to approve it in System Settings —
|
||
and a two-state toggle would have looked broken in it.
|
||
|
||
### Requested of app-engine (open)
|
||
|
||
1. **`Settings` has no `drawMouseCursor` accessor.** README §Settings
|
||
lists `DrawMouseCursor` (default true) and the brief asks for every
|
||
property in that table to be reachable in the settings window;
|
||
`Sources/MWBCore/Settings.swift` carries the property in
|
||
`defaultProperties` (so it round-trips) but publishes no typed
|
||
accessor, and that file is app-engine's. A one-line
|
||
`public var drawMouseCursor: Bool` pair would close it. The control is
|
||
**not shown** in the Behaviour pane until then, with a footnote saying
|
||
the value is kept untouched for the Windows machines that read it —
|
||
which is the honest position anyway, since the drawn cursor is out of
|
||
scope for v1 (README D6) and a toggle that does nothing on either side
|
||
is worse than no toggle.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] `Sources/MWBMac/StatusItem.swift`: item, icon, menu, colours
|
||
(`doc/devdocs/modules/mousewithoutborders.md`; menu actions mirror
|
||
`Form/frmMatrix.cs` and the tray menu in `Class/Program.cs` /
|
||
`Core/Common.cs` `ShowMenu`).
|
||
- [x] `Sources/MWBMac/SettingsWindow/SettingsWindow.swift`, `SettingsView.swift`,
|
||
`SettingsViewModel.swift`, `MachinesPane.swift`, `SecurityPane.swift`,
|
||
`BehaviourPane.swift`, `HotkeysPane.swift` (+ recorder),
|
||
`NetworkPane.swift`, `AdvancedPane.swift` — every property in
|
||
README §Settings reachable (`Form/Settings/*.cs` for labels and
|
||
grouping), **except `DrawMouseCursor`**: no accessor exists to bind
|
||
to, so it is an open Handshake request above and a footnote in the
|
||
pane.
|
||
- [x] `Sources/MWBMac/Notifications.swift`, `Sources/MWBMac/LaunchAgent.swift`.
|
||
- [x] `Sources/mwb/UIBridge.swift`: snapshot → UI, actions → engine;
|
||
replace the placeholder status item in `Sources/mwb/AppLifecycle.swift`
|
||
(authorised edit, that file's status-item parts only).
|
||
- [x] `docs/protocol.md`: nothing expected; **nothing appended** — this
|
||
lane learned no wire fact. It reads settings and statuses that
|
||
earlier lanes already transcribed.
|
||
- [x] `tools/bundle.sh` / `Resources/Info.plist`: add what the bundle
|
||
needs for notifications and login items (authorised). **Only
|
||
`Info.plist` changed, and only by one key** — see the work log for
|
||
what was checked and why nothing else was needed.
|
||
|
||
## Work log
|
||
|
||
- **2026-09-16 (dev)** — lane built on `main` from `bce5c3c`; four
|
||
commits. Gates green on the last; `MWB_ADHOC=1 tools/bundle.sh`
|
||
produces `dist/mwb.app`.
|
||
|
||
*What was built.* Thirteen new files and two edited ones.
|
||
`MWBMac/StatusItem.swift` is the menu bar: the colour table, the row
|
||
and model values, the drawn icon and the menu. `MWBMac/SettingsWindow/`
|
||
is the window: one `NSWindow` + `NSHostingView`
|
||
(`SettingsWindow.swift`), the tab chrome and the shared row/section/
|
||
toggle views (`SettingsView.swift`), the one object the panes bind to
|
||
(`SettingsViewModel.swift`), and a file per pane. `Notifications.swift`
|
||
and `LaunchAgent.swift` are the two macOS services the Windows side has
|
||
no equivalent for. `mwb/UIBridge.swift` joins them to the Engine, and
|
||
`mwb/AppLifecycle.swift` lost its placeholder status item.
|
||
|
||
*Key decisions.*
|
||
1. **The UI is told, not asked.** `StatusItemController.update` takes a
|
||
value and compares it to the last one, so `render` can be called on
|
||
every snapshot — which it is, several times a second while
|
||
connecting — and rebuilds the menu only when something a user can
|
||
see has changed.
|
||
2. **`StatusModel` instead of `EngineSnapshot`.** Forced by the target
|
||
layering (README D2), but it is the better shape anyway: the status
|
||
item has no opinion about how two connections to one peer collapse
|
||
into one dot, and `UIBridge.bestStatuses` can be read and argued
|
||
about on its own.
|
||
3. **Drafts only where a keystroke is expensive.** A `Toggle` writes
|
||
the settings file and re-derives the configs, which is cheap. The
|
||
security key and the port tear down every socket, and a matrix edit
|
||
replicates four packets to every peer — so those, plus the two
|
||
multi-line editors, are drafts with a Save button, which is also
|
||
what the Windows form does with its single "&Apply"
|
||
(`frmMatrix.Designer.cs:440-441`).
|
||
4. **The switch-machine hotkey is a three-way picker, not a recorder.**
|
||
`HotKeySwitchMachine` is the *first of four consecutive* virtual
|
||
keys (`InputHook.cs:611-620`), so an arbitrary recorded key would
|
||
silently claim three more. PowerToys offers exactly three choices
|
||
here — F1..F4, 1..4, Disabled
|
||
(`MouseWithoutBordersPage.xaml:386-392`,
|
||
`SettingsPage4.Designer.cs:223-257`) — and so do we. The other four
|
||
shortcuts are free-form recorders.
|
||
5. **Escape cancels the recorder rather than being recordable.** The
|
||
hard escape is ⌃⌥⌘Escape (contracts C2) and is not editable; a
|
||
recorder you cannot back out of is a trap when the chord you are
|
||
typing is one the tap swallows.
|
||
6. **The one `Permissions.request()` call site moved** from the
|
||
placeholder menu to the Advanced pane's "Request…" button. Still
|
||
exactly one, still only on a click (CLAUDE.md, Workflow).
|
||
7. **A settings file that will not parse now shows a modal alert and
|
||
quits** instead of leaving a status item saying "settings error".
|
||
An accessory app has no window and no Dock icon; the previous
|
||
behaviour was a dead end for anyone not reading the log.
|
||
|
||
*Deviations from the brief and the Assumptions as written.*
|
||
- **`update(_ snapshot: EngineSnapshot)`** became
|
||
`update(_ model: StatusModel)`, with `UIBridge` doing the mapping.
|
||
Recorded in Handshakes with the four other API changes.
|
||
- **`DrawMouseCursor` is not in the pane.** No accessor exists to bind
|
||
to and `Settings.swift` is app-engine's file, so this is an open
|
||
Handshake request rather than a cross-lane edit.
|
||
- **The menu gained "Control All Computers"** and the per-row labels
|
||
for the two shortcuts, neither of which the README sketch listed.
|
||
- **Clicking the local machine's row** uses the ordinary
|
||
`Engine.switchTo(slot:)` when it has a matrix slot, and
|
||
`recoverLocal(reason: .escapeHotkey)` only when it has none. A menu
|
||
click asking for control back *is* a manual escape, so the wording
|
||
that ends up in the "Control returned:" line is right, but it is a
|
||
reason invented for a hotkey and worth knowing about.
|
||
- **`Info.plist` gained one key and `bundle.sh` gained none.** What
|
||
notifications and login items actually need was checked item by item:
|
||
a bundle identifier (already there), a display name for the banner
|
||
and the Login Items list (already there), and a code signature (which
|
||
`bundle.sh` already applies, with D5's warning about ad-hoc
|
||
identities). `UNUserNotificationCenter` needs no usage-description
|
||
key and `SMAppService.mainApp` needs no plist entry at all. The key
|
||
that *was* added is `NSSupportsSuddenTermination` = `false`: it is
|
||
already the default for applications, and saying it out loud is
|
||
cheap insurance for the one path that must never be skipped —
|
||
`applicationWillTerminate`, which releases held keys, gives the
|
||
pointer back and says `ByeBye` (invariant 3, contracts C2).
|
||
|
||
*Verification.* `xcrun swift-format format -i --recursive Sources
|
||
Package.swift`, then `tools/gates.sh` green (lint --strict, MWBCore
|
||
layering, build with warnings-as-errors) — run under `tools/guard.sh`.
|
||
`.build/debug/mwb --version` and `--check-permissions` behave as
|
||
before (the latter exits 3 on this machine, which has neither grant)
|
||
and still create no settings file, log file or tap.
|
||
`MWB_ADHOC=1 tools/bundle.sh` produces `dist/mwb.app` and
|
||
`codesign --verify` passes. No file is over 400 lines and no function
|
||
over 50. **Neither the app nor the settings window was launched**: the
|
||
app creates an event tap, opens sockets, posts TCC prompts and could
|
||
post notifications (CLAUDE.md invariant 5 and the lane brief). That
|
||
means every pixel here — the menu, the six panes, the recorder, the
|
||
notifications, the login item — is unexercised, and CP1 is where it
|
||
first runs.
|
||
|
||
## QA log
|
||
|
||
## Review
|