How krishkrosh/trackweight works
Project Type and Purpose
• This is a native macOS desktop application (built in Swift 6+/Xcode 16) that uses Force Touch trackpad sensors for weight measurement.
• It follows an MVVM-style pattern with a SwiftUI frontend, Combine for reactive data flow, and a low-level touch library (OpenMultitouchSupport) for sensor access.
File Structure
Top-level modules:
• Sources/OpenMultitouchSupport (OMS library)
• OMSManager.swift – Touch event capture and publisher
• OMSTouchData.swift – Touch data model (pressure, position, etc.)
• TrackWeight (app code)
• TrackWeightApp.swift – App entry point
• *.swift views (ContentView, ScaleView, WeighingView, DebugView, etc.)
• *ViewModel.swift (ContentViewModel, ScaleViewModel, WeighingViewModel)
• WeighingState.swift – Domain state model
• Assets & entitlements
Main Components
a. User Interface Layer (SwiftUI Views)
• ContentView, HomeView, ScaleView, TrackWeightView, DebugView
b. Presentation / ViewModel Layer (Combine publishers/subscribers)
• ContentViewModel, ScaleViewModel, WeighingViewModel
c. Core Logic / Domain Model
• WeighingState, calibration logic, pressure-to-weight conversion
d. Sensor Integration Library
• OpenMultitouchSupport (OMSManager + OMSTouchData)
e. Operating System & Hardware
• macOS event system, Force Touch trackpad hardware
f. Build & Deployment
• Xcode project, Package.swift, Homebrew cask workflow
Relationships & Data Flow
1. User taps/places finger on trackpad → SwiftUI View reacts to ViewModel state
2. ViewModel subscribes to OMSManager pressure data publisher
3. OMSManager captures raw touch events via private macOS APIs → emits OMSTouchData streams
4. ViewModel receives pressure readings → applies calibration logic in WeighingState → computes weight
5. ViewModel publishes weight updates → SwiftUI View displays updated measurement
6. DebugView optionally subscribes to raw OMSTouchData for logging
7. Build pipeline: GitHub Actions updates Homebrew formula for distribution
Architectural Patterns & Principles
• MVVM (Model-View-ViewModel) separation
• Reactive data flow via Combine (Publishers & Subscribers)
• Single responsibility per ViewModel (each view has its own)
• Modular dependency on an external library (OpenMultitouchSupport)
• Sandbox disabled for low-level hardware access