# 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`, not resizable below its content) hosting an `NSHostingView`. All UI is `@MainActor`; `UIBridge` (in the `mwb` target) receives snapshots on whatever thread `observe` delivers and hops to main. - **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 key equivalents only as labels — real hotkeys are the tap's); separator; "Easy Mouse" (check mark, toggles); "Reconnect" (⌘⌃⌥R label); "Lock all machines"; separator; "Permissions: OK" or "Permissions missing…" (opens the Advanced pane); "Settings…" ⌘,; "Quit Mouse Without Borders" ⌘Q. The item's icon: a template image of two overlapping rounded rectangles, drawn in code (no asset catalog), with a small coloured badge when anything is not `Connected`/NA. - **Settings panes** (a `TabView`): *Machines* — the 4 slots as text fields in a 1×4 or 2×2 grid (`MatrixOneRow`), ◀ ▶ (▲ ▼ in two rows) buttons to reorder, "Wrap around" (`WrapMouse`), "This machine: NAME" with a "Use this name in slot n" helper; *Security* — the key as `SecurityKey.displayText`, Show/Hide, Generate, Copy, TCP port; a Save applies both and the engine reconnects; *Behaviour* — `ShareClipboard`, `TransferFile`, `HideMouseAtScreenEdge`, `DrawMouseCursor`, `BlockScreenSaverOnOtherMachines`, `MoveMouseRelatively`, `BlockMouseAtScreenCorners`, `ShowClipboardAndNetworkStatusMessages`, Easy Mouse picker (`Disable/Enable/Ctrl/Shift`), `DisableEasyMouseWhenForegroundWindowIsFullscreen` and its excluded-apps list; *Hotkeys* — recorders for switch-machine (F-key base), toggle Easy Mouse, lock, reconnect, switch-to-all, each with a Clear button; *Network* — `Name2IP` multi-line editor with the "name ip" per-line format explained, `SameSubnetOnly`, `ValidateRemoteMachineIP`; *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`), "Open log folder", version. Settings not yet backed by a lane (clipboard/extras) are shown and saved — they simply have no effect until their lane lands; say so in a footnote on the pane. - **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)`; key/port/matrix edits are applied on Save, everything else on change. - **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`, `switchToAll`, `reconnect`, `lockAll`, `toggleEasyMouse`, `apply`, `SettingsStore.update`/`current`, `Settings` accessors. - `input-capture`: `KeyMap.vk(forKeycode:)`, `Hotkey`, `Permissions`. - `wire-core`: `SecurityKey.displayText/normalize/isValid/random`. - `session-matrix`: `Matrix`, `SocketStatus`. ### Promised (to clipboard, extras) ```swift @MainActor public final class StatusItemController { init(actions: StatusActions); func update(_ snapshot: EngineSnapshot) } public struct StatusActions: Sendable { switchTo: (Int) -> Void; switchHome; toggleEasyMouse; reconnect; lockAll; openSettings(pane:); quit } @MainActor public final class SettingsWindowController { init(model: SettingsViewModel); func show(pane: SettingsPane?) } @MainActor public final class SettingsViewModel: ObservableObject { init(store: SettingsStore, apply: @escaping (Settings) async -> Void); … } public enum SettingsPane { case machines, security, behaviour, hotkeys, network, advanced } public enum StatusColor { static func nsColor(for: SocketStatus) -> NSColor } public final class Notifier { func enabledChanged(_:); func post(title:body:) } public enum LaunchAtLogin { static var isEnabled: Bool; static func set(_:) throws; static var isAvailable: Bool } ``` ## Status / TODO - [ ] `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`). - [ ] `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). - [ ] `Sources/MWBMac/Notifications.swift`, `Sources/MWBMac/LaunchAgent.swift`. - [ ] `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). - [ ] `docs/protocol.md`: nothing expected; append §10.7 only if a wire fact was learned. - [ ] `tools/bundle.sh` / `Resources/Info.plist`: add what the bundle needs for notifications and login items (authorised). ## Work log ## QA log ## Review