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]>
210 lines
6.4 KiB
Swift
210 lines
6.4 KiB
Swift
// The settings window's content: the six panes and the chrome they share.
|
|
//
|
|
// The grouping follows the modern PowerToys page
|
|
// (`SettingsXAML/Views/MouseWithoutBordersPage.xaml`): Encryption key, Device
|
|
// layout, Behavior, Easy Mouse, Keyboard shortcuts, Advanced settings. It is
|
|
// split across tabs rather than one long scroll because a menu-bar app's window
|
|
// has no room for the latter, and because the menu can then open the pane it is
|
|
// talking about (`StatusActions.openSettings(pane:)`).
|
|
//
|
|
// Settings whose lane has not landed yet (clipboard, the extras of CP3) are
|
|
// shown and saved — the file is the contract, not the UI — with a footnote on
|
|
// the pane that says they have no effect yet.
|
|
|
|
import Foundation
|
|
import MWBCore
|
|
import SwiftUI
|
|
|
|
/// The six panes, so the menu bar can open the right one.
|
|
public enum SettingsPane: String, Sendable, CaseIterable {
|
|
/// The four matrix slots and their layout.
|
|
case machines
|
|
/// The security key and the port.
|
|
case security
|
|
/// The mouse, clipboard and Easy Mouse behaviour flags.
|
|
case behaviour
|
|
/// The five shortcuts.
|
|
case hotkeys
|
|
/// `Name2IP` and the two connection filters.
|
|
case network
|
|
/// Permissions, launch at login, logs, version.
|
|
case advanced
|
|
|
|
/// The tab's label.
|
|
public var title: String {
|
|
switch self {
|
|
case .machines: return "Machines"
|
|
case .security: return "Security"
|
|
case .behaviour: return "Behaviour"
|
|
case .hotkeys: return "Shortcuts"
|
|
case .network: return "Network"
|
|
case .advanced: return "Advanced"
|
|
}
|
|
}
|
|
|
|
/// The tab's SF Symbol.
|
|
var symbol: String {
|
|
switch self {
|
|
case .machines: return "rectangle.on.rectangle"
|
|
case .security: return "key"
|
|
case .behaviour: return "cursorarrow.motionlines"
|
|
case .hotkeys: return "keyboard"
|
|
case .network: return "network"
|
|
case .advanced: return "gearshape"
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The window's root view.
|
|
struct SettingsView: View {
|
|
@ObservedObject var model: SettingsViewModel
|
|
@Binding var pane: SettingsPane
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
TabView(selection: $pane) {
|
|
ForEach(SettingsPane.allCases, id: \.self) { pane in
|
|
content(for: pane)
|
|
.tabItem { Label(pane.title, systemImage: pane.symbol) }
|
|
.tag(pane)
|
|
}
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.top, 12)
|
|
messageBar
|
|
}
|
|
.frame(width: 560, height: 520)
|
|
}
|
|
|
|
@ViewBuilder private func content(for pane: SettingsPane) -> some View {
|
|
switch pane {
|
|
case .machines: MachinesPane(model: model)
|
|
case .security: SecurityPane(model: model)
|
|
case .behaviour: BehaviourPane(model: model)
|
|
case .hotkeys: HotkeysPane(model: model)
|
|
case .network: NetworkPane(model: model)
|
|
case .advanced: AdvancedPane(model: model)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private var messageBar: some View {
|
|
if let message = model.message {
|
|
HStack(spacing: 8) {
|
|
Text(message).font(.callout).lineLimit(2)
|
|
Spacer()
|
|
Button("Dismiss") { model.clearMessage() }.buttonStyle(.link)
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 8)
|
|
.background(.quaternary)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Shared chrome
|
|
|
|
/// A scrolling column of sections, the shape every pane has.
|
|
struct SettingsPaneLayout<Content: View>: View {
|
|
@ViewBuilder var content: Content
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 18) {
|
|
content
|
|
}
|
|
.padding(16)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A titled group of controls, with the PowerToys page's explanatory line under
|
|
/// the title.
|
|
struct SettingsSection<Content: View>: View {
|
|
let title: String
|
|
let note: String?
|
|
@ViewBuilder var content: Content
|
|
|
|
init(_ title: String, note: String? = nil, @ViewBuilder content: () -> Content) {
|
|
self.title = title
|
|
self.note = note
|
|
self.content = content()
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text(title).font(.headline)
|
|
if let note {
|
|
Text(note).font(.callout).foregroundStyle(.secondary).fixedSize(
|
|
horizontal: false, vertical: true)
|
|
}
|
|
content
|
|
}
|
|
}
|
|
}
|
|
|
|
/// One labelled row: a title, an optional explanation, and a control on the
|
|
/// right — the shape of a `SettingsCard` on the PowerToys page.
|
|
struct SettingsRow<Control: View>: View {
|
|
let title: String
|
|
let help: String?
|
|
@ViewBuilder var control: Control
|
|
|
|
init(_ title: String, help: String? = nil, @ViewBuilder control: () -> Control) {
|
|
self.title = title
|
|
self.help = help
|
|
self.control = control()
|
|
}
|
|
|
|
var body: some View {
|
|
HStack(alignment: .firstTextBaseline, spacing: 12) {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(title)
|
|
if let help {
|
|
Text(help).font(.callout).foregroundStyle(.secondary).fixedSize(
|
|
horizontal: false, vertical: true)
|
|
}
|
|
}
|
|
Spacer(minLength: 12)
|
|
control
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A checkbox with the PowerToys wording under it.
|
|
struct SettingsToggle: View {
|
|
let title: String
|
|
let help: String?
|
|
@Binding var isOn: Bool
|
|
|
|
init(_ title: String, help: String? = nil, isOn: Binding<Bool>) {
|
|
self.title = title
|
|
self.help = help
|
|
self._isOn = isOn
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Toggle(title, isOn: $isOn)
|
|
if let help {
|
|
Text(help).font(.callout).foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.padding(.leading, 20)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The footnote a pane carries when some of its settings are stored but not yet
|
|
/// acted on, because the lane that reads them has not landed (TODO §8, §9).
|
|
struct NotYetActive: View {
|
|
let text: String
|
|
|
|
var body: some View {
|
|
Label(text, systemImage: "clock")
|
|
.font(.callout)
|
|
.foregroundStyle(.secondary)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
}
|