@lattices/cli 0.4.2 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/app/Info.plist +2 -2
- package/app/Lattices.app/Contents/Info.plist +2 -2
- package/app/Lattices.app/Contents/MacOS/Lattices +0 -0
- package/app/Package.swift +6 -0
- package/app/Sources/AppShell/App.swift +20 -0
- package/app/Sources/{AppDelegate.swift → AppShell/AppDelegate.swift} +94 -34
- package/app/Sources/{AppShellView.swift → AppShell/AppShellView.swift} +12 -1
- package/app/Sources/AppShell/AppUpdater.swift +92 -0
- package/app/Sources/AppShell/CliActionLauncher.swift +50 -0
- package/app/Sources/{HomeDashboardView.swift → AppShell/HomeDashboardView.swift} +18 -10
- package/app/Sources/AppShell/LatticesRuntime.swift +61 -0
- package/app/Sources/{MainView.swift → AppShell/MainView.swift} +351 -191
- package/app/Sources/{OnboardingView.swift → AppShell/OnboardingView.swift} +30 -16
- package/app/Sources/{Preferences.swift → AppShell/Preferences.swift} +78 -0
- package/app/Sources/{SettingsView.swift → AppShell/SettingsView.swift} +869 -152
- package/app/Sources/{HotkeyStore.swift → Core/Actions/HotkeyStore.swift} +9 -5
- package/app/Sources/{IntentEngine.swift → Core/Actions/IntentEngine.swift} +51 -27
- package/app/Sources/Core/Actions/IntentSchema.swift +94 -0
- package/app/Sources/{Intents → Core/Actions/Intents}/LatticeIntent.swift +0 -25
- package/app/Sources/{PaletteCommand.swift → Core/Actions/PaletteCommand.swift} +26 -6
- package/app/Sources/{VoiceIntentResolver.swift → Core/Actions/VoiceIntentResolver.swift} +46 -4
- package/app/Sources/Core/Companion/CompanionActivityLog.swift +70 -0
- package/app/Sources/Core/Companion/CompanionKeyboardController.swift +141 -0
- package/app/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +438 -0
- package/app/Sources/Core/Companion/LatticesCompanionCockpit.swift +555 -0
- package/app/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +594 -0
- package/app/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +204 -0
- package/app/Sources/Core/Companion/LatticesDeckHost.swift +1463 -0
- package/app/Sources/{LatticesApi.swift → Core/Daemon/LatticesApi.swift} +125 -4
- package/app/Sources/{AppTypeClassifier.swift → Core/Desktop/AppTypeClassifier.swift} +36 -0
- package/app/Sources/{DesktopModel.swift → Core/Desktop/DesktopModel.swift} +6 -8
- package/app/Sources/Core/Desktop/MouseFinder.swift +527 -0
- package/app/Sources/Core/Desktop/SessionWindowLocator.swift +139 -0
- package/app/Sources/Core/Desktop/WindowDragSnapController.swift +628 -0
- package/app/Sources/Core/Desktop/WindowPreviewCard.swift +100 -0
- package/app/Sources/Core/Desktop/WindowPreviewStore.swift +113 -0
- package/app/Sources/Core/Desktop/WindowSelectionStore.swift +76 -0
- package/app/Sources/{WindowTiler.swift → Core/Desktop/WindowTiler.swift} +351 -172
- package/app/Sources/Core/Input/MouseGestureConfig.swift +364 -0
- package/app/Sources/Core/Input/MouseGestureController.swift +1203 -0
- package/app/Sources/Core/Input/MouseInputDeviceStore.swift +98 -0
- package/app/Sources/Core/Input/MouseInputEventViewer.swift +272 -0
- package/app/Sources/Core/Input/MouseShortcutStore.swift +107 -0
- package/app/Sources/{CommandModeState.swift → Core/Overlays/CommandMode/CommandModeState.swift} +127 -24
- package/app/Sources/{CommandModeView.swift → Core/Overlays/CommandMode/CommandModeView.swift} +492 -79
- package/app/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +67 -0
- package/app/Sources/{CheatSheetHUD.swift → Core/Overlays/HUD/CheatSheetHUD.swift} +1 -0
- package/app/Sources/{HUDRightBar.swift → Core/Overlays/HUD/HUDRightBar.swift} +23 -201
- package/app/Sources/{LauncherHUD.swift → Core/Overlays/HUD/LauncherHUD.swift} +12 -26
- package/app/Sources/{OmniSearchView.swift → Core/Overlays/OmniSearch/OmniSearchView.swift} +136 -2
- package/app/Sources/{OmniSearchWindow.swift → Core/Overlays/OmniSearch/OmniSearchWindow.swift} +21 -32
- package/app/Sources/Core/Overlays/OverlayPanelShell.swift +241 -0
- package/app/Sources/{ScreenMapState.swift → Core/Overlays/ScreenMap/ScreenMapState.swift} +116 -32
- package/app/Sources/{ScreenMapView.swift → Core/Overlays/ScreenMap/ScreenMapView.swift} +510 -524
- package/app/Sources/{ScreenMapWindowController.swift → Core/Overlays/ScreenMap/ScreenMapWindowController.swift} +12 -4
- package/app/Sources/{VoiceCommandWindow.swift → Core/Overlays/Voice/VoiceCommandWindow.swift} +46 -53
- package/app/Sources/Core/Pi/PiAuthNextStepCard.swift +148 -0
- package/app/Sources/Core/Pi/PiAuthPromptCard.swift +90 -0
- package/app/Sources/{PiChatDock.swift → Core/Pi/PiChatDock.swift} +137 -74
- package/app/Sources/{PiChatSession.swift → Core/Pi/PiChatSession.swift} +608 -108
- package/app/Sources/Core/Pi/PiInstallCallout.swift +86 -0
- package/app/Sources/Core/Pi/PiProviderSetupCallout.swift +99 -0
- package/app/Sources/{PiWorkspaceView.swift → Core/Pi/PiWorkspaceView.swift} +174 -77
- package/app/Sources/{PermissionChecker.swift → Core/System/PermissionChecker.swift} +76 -2
- package/app/Sources/Core/System/SystemTelemetryMonitor.swift +273 -0
- package/app/Sources/{HandsOffSession.swift → Core/Voice/HandsOffSession.swift} +15 -4
- package/app/Sources/{WorkspaceManager.swift → Core/Workspace/WorkspaceManager.swift} +288 -0
- package/bin/assistant-intelligence.ts +874 -0
- package/bin/handsoff-infer.ts +16 -209
- package/bin/handsoff-worker.ts +45 -258
- package/bin/lattices-app.ts +62 -0
- package/bin/lattices-dev +4 -0
- package/bin/lattices.ts +125 -14
- package/docs/agents.md +14 -0
- package/docs/api.md +55 -0
- package/docs/app.md +3 -0
- package/docs/companion-deck.md +180 -0
- package/docs/component-extraction-roadmap.md +392 -0
- package/docs/config.md +25 -0
- package/docs/tiling-reference.md +55 -0
- package/docs/voice-error-model.md +73 -0
- package/package.json +4 -1
- package/app/Sources/App.swift +0 -10
- package/app/Sources/CommandPaletteWindow.swift +0 -134
- package/app/Sources/MouseFinder.swift +0 -222
- /package/app/Sources/{KeyRecorderView.swift → AppShell/KeyRecorderView.swift} +0 -0
- /package/app/Sources/{MainWindow.swift → AppShell/MainWindow.swift} +0 -0
- /package/app/Sources/{SettingsWindow.swift → AppShell/SettingsWindow.swift} +0 -0
- /package/app/Sources/{HotkeyManager.swift → Core/Actions/HotkeyManager.swift} +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/CreateLayerIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/DistributeIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/FocusIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/HelpIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/KillIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/LaunchIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/ListSessionsIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/ListWindowsIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/ScanIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/SearchIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/SwitchLayerIntent.swift +0 -0
- /package/app/Sources/{Intents → Core/Actions/Intents}/TileIntent.swift +0 -0
- /package/app/Sources/{DaemonProtocol.swift → Core/Daemon/DaemonProtocol.swift} +0 -0
- /package/app/Sources/{DaemonServer.swift → Core/Daemon/DaemonServer.swift} +0 -0
- /package/app/Sources/{AccessibilityTextExtractor.swift → Core/Desktop/AccessibilityTextExtractor.swift} +0 -0
- /package/app/Sources/{DesktopModelTypes.swift → Core/Desktop/DesktopModelTypes.swift} +0 -0
- /package/app/Sources/{InventoryManager.swift → Core/Desktop/InventoryManager.swift} +0 -0
- /package/app/Sources/{InventoryPath.swift → Core/Desktop/InventoryPath.swift} +0 -0
- /package/app/Sources/{OcrModel.swift → Core/Desktop/OcrModel.swift} +0 -0
- /package/app/Sources/{OcrStore.swift → Core/Desktop/OcrStore.swift} +0 -0
- /package/app/Sources/{PlacementSpec.swift → Core/Desktop/PlacementSpec.swift} +0 -0
- /package/app/Sources/{TilePickerView.swift → Core/Desktop/TilePickerView.swift} +0 -0
- /package/app/Sources/{AppWindowShell.swift → Core/Overlays/AppWindowShell.swift} +0 -0
- /package/app/Sources/{CommandModeWindow.swift → Core/Overlays/CommandMode/CommandModeWindow.swift} +0 -0
- /package/app/Sources/{CommandPaletteView.swift → Core/Overlays/CommandPalette/CommandPaletteView.swift} +0 -0
- /package/app/Sources/{HUDBottomBar.swift → Core/Overlays/HUD/HUDBottomBar.swift} +0 -0
- /package/app/Sources/{HUDController.swift → Core/Overlays/HUD/HUDController.swift} +0 -0
- /package/app/Sources/{HUDLeftBar.swift → Core/Overlays/HUD/HUDLeftBar.swift} +0 -0
- /package/app/Sources/{HUDMinimap.swift → Core/Overlays/HUD/HUDMinimap.swift} +0 -0
- /package/app/Sources/{HUDState.swift → Core/Overlays/HUD/HUDState.swift} +0 -0
- /package/app/Sources/{HUDTopBar.swift → Core/Overlays/HUD/HUDTopBar.swift} +0 -0
- /package/app/Sources/{LayerBezel.swift → Core/Overlays/HUD/LayerBezel.swift} +0 -0
- /package/app/Sources/{OmniSearchState.swift → Core/Overlays/OmniSearch/OmniSearchState.swift} +0 -0
- /package/app/Sources/{DiagnosticLog.swift → Core/System/DiagnosticLog.swift} +0 -0
- /package/app/Sources/{EventBus.swift → Core/System/EventBus.swift} +0 -0
- /package/app/Sources/{ProcessModel.swift → Core/System/ProcessModel.swift} +0 -0
- /package/app/Sources/{ProcessQuery.swift → Core/System/ProcessQuery.swift} +0 -0
- /package/app/Sources/{AdvisorLearningStore.swift → Core/Voice/AdvisorLearningStore.swift} +0 -0
- /package/app/Sources/{AgentSession.swift → Core/Voice/AgentSession.swift} +0 -0
- /package/app/Sources/{AudioProvider.swift → Core/Voice/AudioProvider.swift} +0 -0
- /package/app/Sources/{VoiceChatView.swift → Core/Voice/VoiceChatView.swift} +0 -0
- /package/app/Sources/{VoxClient.swift → Core/Voice/VoxClient.swift} +0 -0
- /package/app/Sources/{Project.swift → Core/Workspace/Project.swift} +0 -0
- /package/app/Sources/{ProjectScanner.swift → Core/Workspace/ProjectScanner.swift} +0 -0
- /package/app/Sources/{SessionLayerStore.swift → Core/Workspace/SessionLayerStore.swift} +0 -0
- /package/app/Sources/{SessionManager.swift → Core/Workspace/SessionManager.swift} +0 -0
- /package/app/Sources/{Terminal.swift → Core/Workspace/Terminal/Terminal.swift} +0 -0
- /package/app/Sources/{TerminalQuery.swift → Core/Workspace/Terminal/TerminalQuery.swift} +0 -0
- /package/app/Sources/{TerminalSynthesizer.swift → Core/Workspace/Terminal/TerminalSynthesizer.swift} +0 -0
- /package/app/Sources/{TmuxModel.swift → Core/Workspace/Tmux/TmuxModel.swift} +0 -0
- /package/app/Sources/{TmuxQuery.swift → Core/Workspace/Tmux/TmuxQuery.swift} +0 -0
- /package/app/Sources/{ActionRow.swift → UI/ActionRow.swift} +0 -0
- /package/app/Sources/{OrphanRow.swift → UI/OrphanRow.swift} +0 -0
- /package/app/Sources/{ProjectRow.swift → UI/ProjectRow.swift} +0 -0
- /package/app/Sources/{TabGroupRow.swift → UI/TabGroupRow.swift} +0 -0
- /package/app/Sources/{Theme.swift → UI/Theme.swift} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import IOKit.hid
|
|
3
|
+
|
|
4
|
+
struct MouseInputDeviceInfo: Identifiable, Equatable {
|
|
5
|
+
var id: String
|
|
6
|
+
var vendorId: Int?
|
|
7
|
+
var productId: Int?
|
|
8
|
+
var locationId: Int?
|
|
9
|
+
var product: String?
|
|
10
|
+
var manufacturer: String?
|
|
11
|
+
var transport: String?
|
|
12
|
+
|
|
13
|
+
var summary: String {
|
|
14
|
+
var parts: [String] = []
|
|
15
|
+
if let product, !product.isEmpty {
|
|
16
|
+
parts.append(product)
|
|
17
|
+
}
|
|
18
|
+
if let manufacturer, !manufacturer.isEmpty, parts.isEmpty {
|
|
19
|
+
parts.append(manufacturer)
|
|
20
|
+
}
|
|
21
|
+
if let vendorId { parts.append("vid:\(vendorId)") }
|
|
22
|
+
if let productId { parts.append("pid:\(productId)") }
|
|
23
|
+
if let locationId { parts.append("loc:\(locationId)") }
|
|
24
|
+
if let transport, !transport.isEmpty { parts.append(transport) }
|
|
25
|
+
return parts.isEmpty ? "Unknown pointer device" : parts.joined(separator: " | ")
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
final class MouseInputDeviceStore: ObservableObject {
|
|
30
|
+
static let shared = MouseInputDeviceStore()
|
|
31
|
+
|
|
32
|
+
@Published private(set) var devices: [MouseInputDeviceInfo] = []
|
|
33
|
+
|
|
34
|
+
private init() {
|
|
35
|
+
refresh()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func refresh() {
|
|
39
|
+
let manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
|
|
40
|
+
let matches: [[String: Any]] = [
|
|
41
|
+
[
|
|
42
|
+
kIOHIDDeviceUsagePageKey as String: kHIDPage_GenericDesktop,
|
|
43
|
+
kIOHIDDeviceUsageKey as String: kHIDUsage_GD_Mouse,
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
kIOHIDDeviceUsagePageKey as String: kHIDPage_GenericDesktop,
|
|
47
|
+
kIOHIDDeviceUsageKey as String: kHIDUsage_GD_Pointer,
|
|
48
|
+
],
|
|
49
|
+
]
|
|
50
|
+
IOHIDManagerSetDeviceMatchingMultiple(manager, matches as CFArray)
|
|
51
|
+
IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone))
|
|
52
|
+
|
|
53
|
+
let resolved: [MouseInputDeviceInfo]
|
|
54
|
+
if let rawDevices = IOHIDManagerCopyDevices(manager) as? Set<IOHIDDevice> {
|
|
55
|
+
resolved = rawDevices.compactMap(Self.deviceInfo(for:))
|
|
56
|
+
.sorted { $0.summary.localizedCaseInsensitiveCompare($1.summary) == .orderedAscending }
|
|
57
|
+
} else {
|
|
58
|
+
resolved = []
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DispatchQueue.main.async {
|
|
62
|
+
self.devices = resolved
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private static func deviceInfo(for device: IOHIDDevice) -> MouseInputDeviceInfo? {
|
|
67
|
+
let vendorId = integerProperty(kIOHIDVendorIDKey as CFString, from: device)
|
|
68
|
+
let productId = integerProperty(kIOHIDProductIDKey as CFString, from: device)
|
|
69
|
+
let locationId = integerProperty(kIOHIDLocationIDKey as CFString, from: device)
|
|
70
|
+
let product = stringProperty(kIOHIDProductKey as CFString, from: device)
|
|
71
|
+
let manufacturer = stringProperty(kIOHIDManufacturerKey as CFString, from: device)
|
|
72
|
+
let transport = stringProperty(kIOHIDTransportKey as CFString, from: device)
|
|
73
|
+
|
|
74
|
+
let vendorToken = vendorId.map(String.init) ?? "vid"
|
|
75
|
+
let productToken = productId.map(String.init) ?? "pid"
|
|
76
|
+
let locationToken = locationId.map(String.init) ?? "loc"
|
|
77
|
+
let id = [product ?? "mouse", vendorToken, productToken, locationToken].joined(separator: ":")
|
|
78
|
+
|
|
79
|
+
return MouseInputDeviceInfo(
|
|
80
|
+
id: id,
|
|
81
|
+
vendorId: vendorId,
|
|
82
|
+
productId: productId,
|
|
83
|
+
locationId: locationId,
|
|
84
|
+
product: product,
|
|
85
|
+
manufacturer: manufacturer,
|
|
86
|
+
transport: transport
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private static func integerProperty(_ key: CFString, from device: IOHIDDevice) -> Int? {
|
|
91
|
+
guard let value = IOHIDDeviceGetProperty(device, key) else { return nil }
|
|
92
|
+
return (value as? NSNumber)?.intValue
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private static func stringProperty(_ key: CFString, from device: IOHIDDevice) -> String? {
|
|
96
|
+
IOHIDDeviceGetProperty(device, key) as? String
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
import SwiftUI
|
|
3
|
+
|
|
4
|
+
final class MouseInputEventViewer: ObservableObject {
|
|
5
|
+
static let shared = MouseInputEventViewer()
|
|
6
|
+
|
|
7
|
+
struct Entry: Identifiable {
|
|
8
|
+
let id = UUID()
|
|
9
|
+
let timestamp: Date
|
|
10
|
+
let phase: String
|
|
11
|
+
let appName: String
|
|
12
|
+
let bundleId: String
|
|
13
|
+
let buttonNumber: Int
|
|
14
|
+
let triggerCandidate: String
|
|
15
|
+
let deltaText: String
|
|
16
|
+
let modifiersText: String
|
|
17
|
+
let deviceText: String
|
|
18
|
+
let matchText: String
|
|
19
|
+
let note: String
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Published private(set) var entries: [Entry] = []
|
|
23
|
+
@Published private(set) var isCaptureActive = false
|
|
24
|
+
|
|
25
|
+
private let maxEntries = 120
|
|
26
|
+
private var window: NSWindow?
|
|
27
|
+
private var closeObserver: Any?
|
|
28
|
+
|
|
29
|
+
private init() {}
|
|
30
|
+
|
|
31
|
+
func show() {
|
|
32
|
+
if let window {
|
|
33
|
+
isCaptureActive = true
|
|
34
|
+
window.makeKeyAndOrderFront(nil)
|
|
35
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let view = MouseInputEventViewerView()
|
|
40
|
+
let window = AppWindowShell.makeWindow(
|
|
41
|
+
config: .init(
|
|
42
|
+
title: "Mouse Shortcut Event Viewer",
|
|
43
|
+
initialSize: NSSize(width: 980, height: 620),
|
|
44
|
+
minSize: NSSize(width: 840, height: 460),
|
|
45
|
+
maxSize: NSSize(width: 1500, height: 1000)
|
|
46
|
+
),
|
|
47
|
+
rootView: view
|
|
48
|
+
)
|
|
49
|
+
AppWindowShell.positionCentered(window)
|
|
50
|
+
AppWindowShell.present(window)
|
|
51
|
+
|
|
52
|
+
closeObserver = NotificationCenter.default.addObserver(
|
|
53
|
+
forName: NSWindow.willCloseNotification,
|
|
54
|
+
object: window,
|
|
55
|
+
queue: .main
|
|
56
|
+
) { [weak self] _ in
|
|
57
|
+
self?.teardownWindow()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
self.window = window
|
|
61
|
+
isCaptureActive = true
|
|
62
|
+
DiagnosticLog.shared.info("Mouse shortcuts event viewer opened")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func dismiss() {
|
|
66
|
+
window?.close()
|
|
67
|
+
teardownWindow()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func clear() {
|
|
71
|
+
entries.removeAll()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func record(_ observedEvent: MouseShortcutObservedEvent) {
|
|
75
|
+
let entry = Entry(
|
|
76
|
+
timestamp: observedEvent.timestamp,
|
|
77
|
+
phase: observedEvent.phase,
|
|
78
|
+
appName: observedEvent.frontmostAppName ?? "Unknown App",
|
|
79
|
+
bundleId: observedEvent.frontmostBundleId ?? "unknown.bundle",
|
|
80
|
+
buttonNumber: observedEvent.buttonNumber,
|
|
81
|
+
triggerCandidate: observedEvent.candidateTrigger ?? "--",
|
|
82
|
+
deltaText: "\(Int(observedEvent.delta.x)), \(Int(observedEvent.delta.y))",
|
|
83
|
+
modifiersText: Self.modifierLabels(for: observedEvent.modifiers).joined(separator: "+").ifEmpty("--"),
|
|
84
|
+
deviceText: observedEvent.device?.summary ?? "Unresolved device",
|
|
85
|
+
matchText: observedEvent.matchedRuleSummary ?? (observedEvent.willFire ? "Would fire" : "No match"),
|
|
86
|
+
note: observedEvent.note ?? ""
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
DispatchQueue.main.async {
|
|
90
|
+
self.entries.append(entry)
|
|
91
|
+
if self.entries.count > self.maxEntries {
|
|
92
|
+
self.entries.removeFirst(self.entries.count - self.maxEntries)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private func teardownWindow() {
|
|
98
|
+
if let closeObserver {
|
|
99
|
+
NotificationCenter.default.removeObserver(closeObserver)
|
|
100
|
+
self.closeObserver = nil
|
|
101
|
+
}
|
|
102
|
+
window = nil
|
|
103
|
+
isCaptureActive = false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private static func modifierLabels(for flags: NSEvent.ModifierFlags) -> [String] {
|
|
107
|
+
var labels: [String] = []
|
|
108
|
+
if flags.contains(.control) { labels.append("Ctrl") }
|
|
109
|
+
if flags.contains(.option) { labels.append("Option") }
|
|
110
|
+
if flags.contains(.shift) { labels.append("Shift") }
|
|
111
|
+
if flags.contains(.command) { labels.append("Cmd") }
|
|
112
|
+
return labels
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private struct MouseInputEventViewerView: View {
|
|
117
|
+
@ObservedObject private var viewer = MouseInputEventViewer.shared
|
|
118
|
+
@ObservedObject private var devices = MouseInputDeviceStore.shared
|
|
119
|
+
|
|
120
|
+
private static let timestampFormatter: DateFormatter = {
|
|
121
|
+
let formatter = DateFormatter()
|
|
122
|
+
formatter.dateFormat = "HH:mm:ss.SSS"
|
|
123
|
+
return formatter
|
|
124
|
+
}()
|
|
125
|
+
|
|
126
|
+
var body: some View {
|
|
127
|
+
VStack(spacing: 0) {
|
|
128
|
+
header
|
|
129
|
+
Divider()
|
|
130
|
+
.overlay(Color.white.opacity(0.08))
|
|
131
|
+
ScrollView {
|
|
132
|
+
LazyVStack(alignment: .leading, spacing: 8) {
|
|
133
|
+
if devices.devices.isEmpty {
|
|
134
|
+
deviceStrip(text: "Devices: none detected")
|
|
135
|
+
} else {
|
|
136
|
+
deviceStrip(text: "Devices: " + devices.devices.map(\.summary).joined(separator: " | "))
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
ForEach(viewer.entries) { entry in
|
|
140
|
+
entryRow(entry)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
.padding(14)
|
|
144
|
+
}
|
|
145
|
+
.background(Color.black.opacity(0.16))
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private var header: some View {
|
|
150
|
+
HStack(spacing: 12) {
|
|
151
|
+
VStack(alignment: .leading, spacing: 4) {
|
|
152
|
+
Text("Mouse Shortcut Event Viewer")
|
|
153
|
+
.font(.system(size: 14, weight: .semibold, design: .monospaced))
|
|
154
|
+
.foregroundColor(.white.opacity(0.95))
|
|
155
|
+
Text("Watching extra mouse buttons and drag candidates for configurable shortcuts.")
|
|
156
|
+
.font(.system(size: 11))
|
|
157
|
+
.foregroundColor(.white.opacity(0.6))
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Spacer()
|
|
161
|
+
|
|
162
|
+
Button("Copy") {
|
|
163
|
+
let text = viewer.entries.map { entry in
|
|
164
|
+
[
|
|
165
|
+
Self.timestampFormatter.string(from: entry.timestamp),
|
|
166
|
+
entry.phase,
|
|
167
|
+
entry.appName,
|
|
168
|
+
entry.bundleId,
|
|
169
|
+
"button=\(entry.buttonNumber)",
|
|
170
|
+
"candidate=\(entry.triggerCandidate)",
|
|
171
|
+
"delta=\(entry.deltaText)",
|
|
172
|
+
"mods=\(entry.modifiersText)",
|
|
173
|
+
"device=\(entry.deviceText)",
|
|
174
|
+
"match=\(entry.matchText)",
|
|
175
|
+
entry.note,
|
|
176
|
+
].filter { !$0.isEmpty }.joined(separator: " | ")
|
|
177
|
+
}.joined(separator: "\n")
|
|
178
|
+
NSPasteboard.general.clearContents()
|
|
179
|
+
NSPasteboard.general.setString(text, forType: .string)
|
|
180
|
+
}
|
|
181
|
+
.buttonStyle(.plain)
|
|
182
|
+
.foregroundColor(.white.opacity(0.72))
|
|
183
|
+
|
|
184
|
+
Button("Clear") {
|
|
185
|
+
viewer.clear()
|
|
186
|
+
}
|
|
187
|
+
.buttonStyle(.plain)
|
|
188
|
+
.foregroundColor(.white.opacity(0.72))
|
|
189
|
+
}
|
|
190
|
+
.padding(.horizontal, 16)
|
|
191
|
+
.padding(.vertical, 12)
|
|
192
|
+
.background(Color.white.opacity(0.04))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private func deviceStrip(text: String) -> some View {
|
|
196
|
+
Text(text)
|
|
197
|
+
.font(.system(size: 10, weight: .medium, design: .monospaced))
|
|
198
|
+
.foregroundColor(.white.opacity(0.6))
|
|
199
|
+
.padding(.horizontal, 10)
|
|
200
|
+
.padding(.vertical, 8)
|
|
201
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
202
|
+
.background(
|
|
203
|
+
RoundedRectangle(cornerRadius: 10)
|
|
204
|
+
.fill(Color.white.opacity(0.04))
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private func entryRow(_ entry: MouseInputEventViewer.Entry) -> some View {
|
|
209
|
+
VStack(alignment: .leading, spacing: 6) {
|
|
210
|
+
HStack(alignment: .firstTextBaseline, spacing: 10) {
|
|
211
|
+
Text(Self.timestampFormatter.string(from: entry.timestamp))
|
|
212
|
+
.font(.system(size: 11, weight: .medium, design: .monospaced))
|
|
213
|
+
.foregroundColor(.white.opacity(0.82))
|
|
214
|
+
|
|
215
|
+
Text(entry.phase.uppercased())
|
|
216
|
+
.font(.system(size: 10, weight: .bold, design: .monospaced))
|
|
217
|
+
.foregroundColor(Color(red: 0.62, green: 0.84, blue: 1.0))
|
|
218
|
+
|
|
219
|
+
Text(entry.triggerCandidate)
|
|
220
|
+
.font(.system(size: 11, weight: .semibold, design: .monospaced))
|
|
221
|
+
.foregroundColor(.white.opacity(0.94))
|
|
222
|
+
|
|
223
|
+
Spacer()
|
|
224
|
+
|
|
225
|
+
Text(entry.matchText)
|
|
226
|
+
.font(.system(size: 10, weight: .medium, design: .monospaced))
|
|
227
|
+
.foregroundColor(.white.opacity(0.68))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
HStack(spacing: 14) {
|
|
231
|
+
metadataPill("App", "\(entry.appName) (\(entry.bundleId))")
|
|
232
|
+
metadataPill("Button", "\(entry.buttonNumber)")
|
|
233
|
+
metadataPill("Delta", entry.deltaText)
|
|
234
|
+
metadataPill("Mods", entry.modifiersText)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
HStack(spacing: 14) {
|
|
238
|
+
metadataPill("Device", entry.deviceText)
|
|
239
|
+
if !entry.note.isEmpty {
|
|
240
|
+
metadataPill("Note", entry.note)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
.padding(12)
|
|
245
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
|
246
|
+
.background(
|
|
247
|
+
RoundedRectangle(cornerRadius: 12)
|
|
248
|
+
.fill(Color.white.opacity(0.04))
|
|
249
|
+
.overlay(
|
|
250
|
+
RoundedRectangle(cornerRadius: 12)
|
|
251
|
+
.stroke(Color.white.opacity(0.06), lineWidth: 0.5)
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private func metadataPill(_ label: String, _ value: String) -> some View {
|
|
257
|
+
HStack(spacing: 6) {
|
|
258
|
+
Text(label.uppercased())
|
|
259
|
+
.font(.system(size: 9, weight: .bold, design: .monospaced))
|
|
260
|
+
.foregroundColor(.white.opacity(0.42))
|
|
261
|
+
Text(value)
|
|
262
|
+
.font(.system(size: 10, weight: .medium, design: .monospaced))
|
|
263
|
+
.foregroundColor(.white.opacity(0.82))
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private extension String {
|
|
269
|
+
func ifEmpty(_ replacement: String) -> String {
|
|
270
|
+
isEmpty ? replacement : self
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
import Combine
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
final class MouseShortcutStore: ObservableObject {
|
|
6
|
+
static let shared = MouseShortcutStore()
|
|
7
|
+
|
|
8
|
+
@Published private(set) var config: MouseShortcutConfig
|
|
9
|
+
|
|
10
|
+
let configURL: URL
|
|
11
|
+
private var lastLoadedModifiedDate: Date?
|
|
12
|
+
|
|
13
|
+
private init() {
|
|
14
|
+
let dir = FileManager.default.homeDirectoryForCurrentUser
|
|
15
|
+
.appendingPathComponent(".lattices")
|
|
16
|
+
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
17
|
+
self.configURL = dir.appendingPathComponent("mouse-shortcuts.json")
|
|
18
|
+
self.config = .defaults
|
|
19
|
+
ensureConfigFile()
|
|
20
|
+
reload()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var tuning: MouseShortcutTuning {
|
|
24
|
+
config.tuning
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var enabledRules: [MouseShortcutRule] {
|
|
28
|
+
config.rules.filter(\.enabled)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var watchedButtonNumbers: Set<Int64> {
|
|
32
|
+
Set(enabledRules.map { Int64($0.trigger.button.rawButtonNumber) })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var summaryLines: [String] {
|
|
36
|
+
enabledRules.map { "\($0.trigger.triggerName) -> \($0.action.type.rawValue)" }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func ensureConfigFile() {
|
|
40
|
+
guard !FileManager.default.fileExists(atPath: configURL.path) else { return }
|
|
41
|
+
write(config: .defaults)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func reload() {
|
|
45
|
+
guard let data = FileManager.default.contents(atPath: configURL.path) else {
|
|
46
|
+
config = .defaults
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
do {
|
|
51
|
+
config = try JSONDecoder().decode(MouseShortcutConfig.self, from: data)
|
|
52
|
+
lastLoadedModifiedDate = modifiedDate()
|
|
53
|
+
} catch {
|
|
54
|
+
DiagnosticLog.shared.error("MouseShortcutStore: failed to decode mouse-shortcuts.json - \(error.localizedDescription)")
|
|
55
|
+
config = .defaults
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func reloadIfNeeded() {
|
|
60
|
+
let currentModifiedDate = modifiedDate()
|
|
61
|
+
guard currentModifiedDate != lastLoadedModifiedDate else { return }
|
|
62
|
+
reload()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func restoreDefaults() {
|
|
66
|
+
write(config: .defaults)
|
|
67
|
+
reload()
|
|
68
|
+
DiagnosticLog.shared.info("Mouse shortcuts restored to defaults")
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func openConfiguration() {
|
|
72
|
+
ensureConfigFile()
|
|
73
|
+
NSWorkspace.shared.open(configURL)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func match(for event: MouseShortcutTriggerEvent) -> MouseShortcutMatchResult? {
|
|
77
|
+
for rule in enabledRules {
|
|
78
|
+
guard rule.trigger.kind == event.kind,
|
|
79
|
+
rule.trigger.button == event.button,
|
|
80
|
+
rule.trigger.direction == event.direction,
|
|
81
|
+
rule.device.matches(event.device) else {
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return MouseShortcutMatchResult(
|
|
86
|
+
rule: rule,
|
|
87
|
+
action: rule.action,
|
|
88
|
+
triggerName: rule.trigger.triggerName
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return nil
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private func write(config: MouseShortcutConfig) {
|
|
96
|
+
let encoder = JSONEncoder()
|
|
97
|
+
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
|
|
98
|
+
guard let data = try? encoder.encode(config) else { return }
|
|
99
|
+
try? data.write(to: configURL, options: .atomic)
|
|
100
|
+
lastLoadedModifiedDate = modifiedDate()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private func modifiedDate() -> Date? {
|
|
104
|
+
let attrs = try? FileManager.default.attributesOfItem(atPath: configURL.path)
|
|
105
|
+
return attrs?[.modificationDate] as? Date
|
|
106
|
+
}
|
|
107
|
+
}
|