diff --git a/docs/features/app-engine/README.md b/docs/features/app-engine/README.md index b3b5073..e4f1311 100644 --- a/docs/features/app-engine/README.md +++ b/docs/features/app-engine/README.md @@ -679,3 +679,19 @@ Rules the consuming lanes must honour: Verdict: REWORK ## Review + +- 2026-09-16 (lead): inspected per `docs/loop.md` §5 after one rework + round. Gates green run by me; diff limited to the brief's files plus + the three authorised cross-lane edits (`Sequencing.swift` lock, + `PermissionState.init`, two README lines), TODO §6, protocol §10.6. + Read the drain loop, `stampAndForward`, `inputDestination`, + `considerCrossing`, `reportEdgeToController` and `Switcher. + nextMachinePacket`: every application packet is stamped exactly once + (Engine or Switcher, both through the one locked sequencer) and + forwarded unchanged — C1 holds. Sink, tap wake, ticker and watchers + funnel through one `AsyncStream` — C3 holds. QA walked C2's rows and + C4's mappings. Files at 644/611 lines are under the 800 mark with + reasons recorded. Verdict: **merge**. Carry into app-ui: settings are + edited only through `SettingsStore.update`; `Engine.observe` is the + one feed for the UI; `Permissions.request()` only on a click. + Unexercised until CP1: everything from `NSApplication.run()` inwards. diff --git a/docs/features/app-ui/README.md b/docs/features/app-ui/README.md new file mode 100644 index 0000000..6f64e22 --- /dev/null +++ b/docs/features/app-ui/README.md @@ -0,0 +1,131 @@ +# 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 diff --git a/docs/loop.md b/docs/loop.md index b049582..fef5967 100644 --- a/docs/loop.md +++ b/docs/loop.md @@ -157,8 +157,8 @@ Strictly one at a time, in this order (mirrors `TODO.md`): | 3 | control-channel | merged 2026-09-16 (two reworks) | | 4 | input-capture | merged 2026-09-16 (one rework) | | 5 | input-inject | merged 2026-09-16 (one rework) | -| 6 | app-engine | the Engine actor, Settings, wiring, recovery; a headless-capable `mwb` | -| 7 | app-ui | status item, settings window, notifications, LaunchAgent — **CP1** (contracts C5) | +| 6 | app-engine | merged 2026-09-16 (one rework) | +| 7 | app-ui | in progress — ends at **CP1** (contracts C5) | | 8 | clipboard | **CP2** | | 9 | extras | **CP3** | | 10 | polish | driven by the checkpoints' findings | @@ -175,6 +175,13 @@ Strictly one at a time, in this order (mirrors `TODO.md`): ## 8. Lane log +- **2026-09-16, lane 6 (app-engine)** — Dev (Opus), QA (Sonnet) + REWORK (settings file mode inherited from a copied-in file; key + release missing on two switch-home paths; `ByeBye` on the signal + path), Dev rework including two authorised cross-lane fixes the Dev + itself had flagged (an unsynchronised `PacketSequencer` — a real C1 + race — and a missing public init). What the brief got wrong: the + reopen countdown said 10 s where Windows and the channel say 30 s. - **2026-09-16, lane 5 (input-inject)** — Dev (Opus), QA (Sonnet) REWORK (chord state normalised too early; undocumented secure-desktop gate), Dev rework, lead inspection. What the brief got wrong: it