Engine.swift is the actor contracts C3 names: it owns the Switcher, the sequencer, the replay filter, the channel, the tap, the routing state, the capture ring, the injector, the cursor and the screens, and it is the only thing that stamps an Id (contracts C1). Every callback — the channel's sink, the tap's wake-up, the timers, the workspace and settings observers — funnels through one AsyncStream so four queues are serialised once instead of racing as free Tasks. `dispatch` is the port of Receiver.ProcessPackage (Receiver.cs:86-390), long on purpose. EngineActions.swift performs [SwitchAction] (MachineStuff.cs:1008-1050, Helper.cs:73-127), the hotkeys (InputHook.cs:516-655) and the mapping from Settings onto every lane's config struct (contracts C4). Recovery.swift is contracts C2 end to end: escape hotkey, controlled peer lost, tap lost, capture overflow, revoked permission, quit — each ending in route-local, releaseAll and a pointer that is coupled again — plus the reopen countdown (frmScreen.cs:427-450). AppLifecycle.swift is the process: flock single instance, the LSUIElement NSApplication with a placeholder status item, the DispatchSourceSignal + atexit emergency release, and hostname validation (README D7). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
55 lines
1.7 KiB
Swift
55 lines
1.7 KiB
Swift
// mwb — the executable. Wires MWBCore, MWBNet and MWBMac together.
|
|
//
|
|
// With no arguments it runs the app: an `LSUIElement` `NSApplication` with the
|
|
// placeholder status item of `AppLifecycle.swift`. The two diagnostic flags stay
|
|
// because the build and the bundle script use them, and because they must work
|
|
// without creating a settings file, a log file or an event tap.
|
|
|
|
import AppKit
|
|
import Foundation
|
|
import MWBCore
|
|
import MWBMac
|
|
import MWBNet
|
|
|
|
let usage = """
|
|
usage: mwb [--version | --check-permissions]
|
|
(no arguments) run the app in the menu bar
|
|
--version print the build version and exit 0
|
|
--check-permissions print Input Monitoring / Accessibility state; exit 0 if both granted, 3 otherwise
|
|
"""
|
|
|
|
func checkPermissions() -> Int32 {
|
|
let state = Permissions.preflight()
|
|
print("input-monitoring (listen): \(state.listen ? "granted" : "missing")")
|
|
print("accessibility (post): \(state.post ? "granted" : "missing")")
|
|
if !state.isComplete {
|
|
print("grant the missing permission(s) in System Settings > Privacy & Security")
|
|
}
|
|
return state.isComplete ? 0 : 3
|
|
}
|
|
|
|
@MainActor
|
|
func runApp() -> Never {
|
|
let application = NSApplication.shared
|
|
let delegate = AppDelegate()
|
|
application.delegate = delegate
|
|
// No Dock icon and no menu bar of our own; the status item is the whole UI.
|
|
application.setActivationPolicy(.accessory)
|
|
application.run()
|
|
exit(0)
|
|
}
|
|
|
|
let arguments = Array(CommandLine.arguments.dropFirst())
|
|
switch arguments {
|
|
case []:
|
|
runApp()
|
|
case ["--version"]:
|
|
print("mwb \(MWBVersion.string)")
|
|
exit(0)
|
|
case ["--check-permissions"]:
|
|
exit(checkPermissions())
|
|
default:
|
|
FileHandle.standardError.write(Data((usage + "\n").utf8))
|
|
exit(2)
|
|
}
|