Files
lucioandClaude Opus 5 6b2b3fc65a app-ui: menu bar, settings window, notifications, login item
The real user interface, replacing app-engine's placeholder status item.

- MWBMac/StatusItem.swift: NSStatusItem with a code-drawn icon, the
  documented status colours (doc/devdocs/modules/mousewithoutborders.md)
  and the menu the Windows tray menu offers (frmScreen.Designer.cs:91-180).
- MWBMac/SettingsWindow/*: one NSWindow hosting a SwiftUI TabView with six
  panes; every property in README §Settings is reachable. Labels and help
  text taken from MouseWithoutBordersPage.xaml + Resources.resw, cited per
  file.
- MWBMac/Notifications.swift, LaunchAgent.swift: UNUserNotificationCenter
  and SMAppService.mainApp, both guarded on a bundle identifier.
- mwb/UIBridge.swift: EngineSnapshot -> StatusModel, clicks -> Engine, and
  the connected/lost/invalid-key notification diff.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 04:14:11 -07:00

51 lines
2.1 KiB
Swift

// Launch at login.
//
// Windows registers `Run` key entries and, in service mode, a Windows service
// (`Class/Program.cs`, `Core/Service.cs`); neither has a macOS equivalent worth
// porting (README D6). `SMAppService.mainApp` is the whole macOS answer: it
// registers the *bundle* with the login-items machinery, and the user can turn it
// off again in System Settings > General > Login Items.
//
// It needs a real bundle with a bundle identifier and a code signature. Run
// unbundled — `swift run`, or the binary straight out of `.build` — there is
// nothing to register, so `isAvailable` is false and the UI says why rather than
// throwing at the user.
import Foundation
import ServiceManagement
/// The login-item registration for this app.
public enum LaunchAtLogin {
/// False when the process is not running from an app bundle, in which case
/// nothing here does anything.
public static var isAvailable: Bool {
Bundle.main.bundleIdentifier != nil && Bundle.main.bundleURL.pathExtension == "app"
}
/// Whether macOS will start this app at login.
public static var isEnabled: Bool {
guard isAvailable else { return false }
return SMAppService.mainApp.status == .enabled
}
/// Why the toggle is off when it is not simply "the user said no":
/// `requiresApproval` means the registration exists but the user has to
/// switch it on in System Settings, which is macOS's rule, not ours.
public static var needsApproval: Bool {
guard isAvailable else { return false }
return SMAppService.mainApp.status == .requiresApproval
}
/// Registers or unregisters. Throws what `SMAppService` throws, which the
/// caller shows verbatim: the failures are all "this copy is not where macOS
/// will trust it from" and only the user can move it.
public static func set(_ enabled: Bool) throws {
guard isAvailable else { return }
if enabled {
try SMAppService.mainApp.register()
} else {
try SMAppService.mainApp.unregister()
}
}
}