Apple Watch: Sound-effects and vibrate settings, build scripts

This commit is contained in:
James Babcock committed 2026-11-04 03:04:43 -08:00
1 parent 2696f3b76c
commit 6df52021c8
13 files changed
+117 -29

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ struct FaceclawWatchApp: App {
init() {
link = PhoneLink()
prefs = WatchPrefs()
prefs = WatchPrefs(link: link)
// Here rather than in a view: a background launch never builds one.
link.start()
}
+2 -2
View File
@@ -171,8 +171,8 @@ final class PadController {
let steps = Int(crownRemainder.rounded(.towardZero))
guard steps != 0 else { return }
crownRemainder -= Double(steps)
let clockwiseNext = link.state?.crownClockwiseNext == true
let gesture: RingGesture = (steps > 0) == clockwiseNext ? .scrollDown : .scrollUp
// Clockwise moves to the previous item.
let gesture: RingGesture = steps > 0 ? .scrollUp : .scrollDown
guard gestureAllowed(gesture) else { return }
// Capped low: a fast twirl otherwise outruns the display. The crown's
// own detent haptics are the feedback, so there's no buzz here.
+5 -3
View File
@@ -115,8 +115,9 @@ struct PhoneState: Equatable {
var windows: [WindowEntry] = []
var apps: [AppEntry] = []
var remoteEnabled = true
/** False by default: clockwise moves to the previous item. */
var crownClockwiseNext = false
/** Settings > Watch on the glasses; WatchPrefs and Haptics say what they do. */
var vibrateOnInput = true
var soundEffects = false
var canUnlock = true
var mirrorAssistant = true
var assistantAvailable = false
@@ -155,7 +156,8 @@ struct PhoneState: Equatable {
}
state.apps = (o["apps"] as? [[String: Any]] ?? []).map(appEntry)
state.remoteEnabled = o["remoteEnabled"] as? Bool ?? true
state.crownClockwiseNext = o["crownClockwiseNext"] as? Bool ?? false
state.vibrateOnInput = o["vibrateOnInput"] as? Bool ?? true
state.soundEffects = o["soundEffects"] as? Bool ?? false
state.canUnlock = o["canUnlock"] as? Bool ?? true
state.mirrorAssistant = o["mirrorAssistant"] as? Bool ?? true
state.assistantAvailable = o["assistantAvailable"] as? Bool ?? false
+6 -3
View File
@@ -340,20 +340,23 @@ struct StatusScreen: View {
// MARK: - Settings
/** Watch-local preferences: feel of the pad and crown. */
/** Watch-local preferences: feel of the crown. */
struct SettingsScreen: View {
@Environment(WatchPrefs.self) private var prefs
var body: some View {
@Bindable var prefs = prefs
ScrollView {
VStack(spacing: 4) {
Toggle("Vibrate on input", isOn: $prefs.haptics)
Button {
prefs.crownSensitivity = prefs.crownSensitivity.next
} label: {
RowLabel(title: "Crown sensitivity", detail: prefs.crownSensitivity.rawValue)
}
Text("Vibration and sound effects are in Settings > Watch on the glasses.")
.font(.caption2)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
.padding(.top, 6)
Text("To keep the remote open between glances, set Settings > General > Return to Clock > Faceclaw on the watch.")
.font(.caption2)
.foregroundStyle(.secondary)
+43 -14
View File
@@ -22,33 +22,44 @@ enum CrownSensitivity: String, CaseIterable {
}
}
/** Watch-local preferences (nothing here is synced to the phone). */
/**
Crown sensitivity is the watch's own. Vibration and sound follow Settings > Watch on
the glasses, through the mirrored state, which the application context keeps for
when the phone is out of reach.
*/
@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) }
}
/** Confirm each gesture sent, and tick on crown detents. */
var haptics: Bool { link.state?.vibrateOnInput ?? true }
/** Give each gesture its own cue, sound included; see Haptics. */
var soundEffects: Bool { link.state?.soundEffects ?? false }
var crownSensitivity: CrownSensitivity {
didSet { store.set(crownSensitivity.rawValue, forKey: Keys.crown) }
}
@ObservationIgnored private let link: PhoneLink
@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
init(link: PhoneLink) {
self.link = link
crownSensitivity = store.string(forKey: Keys.crown).flatMap(CrownSensitivity.init(rawValue:)) ?? .normal
}
}
/** The wrist's confirmation of what was sent. */
/**
The wrist's confirmation of what was sent. watchOS has no call that plays only a
vibration or only a sound: every WKHapticType is both, and only the watch's own Silent
Mode mutes the sound. So sound effects on means the full set of cues, which vibrate
whatever the vibrate setting says, and off means `.click` for everything. Whether
`.click` is truly silent is unconfirmed; see notes/apple-watch-followups.md.
*/
@MainActor
struct Haptics {
let prefs: WatchPrefs
@@ -62,10 +73,28 @@ struct Haptics {
/** 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) }
/** The phone refused or did not answer; always plays, and never feels like a sent gesture. */
func error() {
let device = WKInterfaceDevice.current()
if prefs.soundEffects {
device.play(.failure)
return
}
device.play(.click)
Task {
try? await Task.sleep(nanoseconds: Self.errorTapGapNanos)
device.play(.click)
}
}
private func play(_ cue: WKHapticType) {
if prefs.soundEffects {
WKInterfaceDevice.current().play(cue)
} else if prefs.haptics {
WKInterfaceDevice.current().play(.click)
}
}
/** Apple's documentation asks for at least 100 ms between haptics. */
private static let errorTapGapNanos: UInt64 = 150_000_000
}