mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-29 13:03:11 +00:00
Add an Apple Watch app that can control the glasses
This commit is contained in:
1 parent
c896ce9ac8
commit
2696f3b76c
46 files changed
+3877
-88
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
import SwiftUI
|
||||
import WatchKit
|
||||
|
||||
enum CrownSensitivity: String, CaseIterable {
|
||||
case low = "Low"
|
||||
case normal = "Normal"
|
||||
case high = "High"
|
||||
|
||||
var next: CrownSensitivity {
|
||||
let all = Self.allCases
|
||||
return all[(all.firstIndex(of: self)! + 1) % all.count]
|
||||
}
|
||||
|
||||
var digitalCrown: DigitalCrownRotationalSensitivity {
|
||||
switch self {
|
||||
case .low: return .low
|
||||
case .normal: return .medium
|
||||
case .high: return .high
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Watch-local preferences (nothing here is synced to the phone). */
|
||||
@MainActor
|
||||
@Observable
|
||||
final class WatchPrefs {
|
||||
/** Buzz on every gesture sent, and tick on crown detents. */
|
||||
var haptics: Bool {
|
||||
didSet { store.set(haptics, forKey: Keys.haptics) }
|
||||
}
|
||||
|
||||
var crownSensitivity: CrownSensitivity {
|
||||
didSet { store.set(crownSensitivity.rawValue, forKey: Keys.crown) }
|
||||
}
|
||||
|
||||
@ObservationIgnored private let store = UserDefaults.standard
|
||||
|
||||
private enum Keys {
|
||||
static let haptics = "haptics"
|
||||
static let crown = "crownSensitivity"
|
||||
}
|
||||
|
||||
init() {
|
||||
haptics = store.object(forKey: Keys.haptics) as? Bool ?? true
|
||||
crownSensitivity = store.string(forKey: Keys.crown).flatMap(CrownSensitivity.init(rawValue:)) ?? .normal
|
||||
}
|
||||
}
|
||||
|
||||
/** The wrist's confirmation of what was sent. */
|
||||
@MainActor
|
||||
struct Haptics {
|
||||
let prefs: WatchPrefs
|
||||
|
||||
/** A sent click, swipe or command. */
|
||||
func click() { play(.click) }
|
||||
/** A sent double-click: back. */
|
||||
func doubleClick() { play(.directionDown) }
|
||||
/** The start of a hold. */
|
||||
func heavy() { play(.start) }
|
||||
/** A reply finished arriving. */
|
||||
func done() { play(.success) }
|
||||
|
||||
/** The phone refused or did not answer; always plays. */
|
||||
func error() { WKInterfaceDevice.current().play(.failure) }
|
||||
|
||||
private func play(_ type: WKHapticType) {
|
||||
if prefs.haptics { WKInterfaceDevice.current().play(type) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user