Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Watch widget: quiet after 45 minutes without the watch app

Duarte Santos3a171a06c48b
diff --git a/frontend/ios/App/Watch/WidgetState.swift b/frontend/ios/App/Watch/WidgetState.swift
index db26e3453..385543684 100644
--- a/frontend/ios/App/Watch/WidgetState.swift
+++ b/frontend/ios/App/Watch/WidgetState.swift
@@ -31,12 +31,13 @@ struct WidgetState: Codable, Equatable {
&& a.done == b.done && a.total == b.total && a.setLabel == b.setLabel
}
- /// The state as written, unless it is about a session long gone (the app stopped without
- /// saying so): then nothing to show, and the iPhone's Live Activity has the Smart Stack.
+ /// The state as written, unless it is about a session the watch app has not touched for 45
+ /// minutes (it was closed, or the workout runs on the phone alone): then nothing to show, and
+ /// the iPhone's Live Activity has the Smart Stack to itself instead of two cards saying the same.
static func read() -> WidgetState {
guard let d = UserDefaults(suiteName: groupId)?.data(forKey: key),
let s = try? JSONDecoder().decode(WidgetState.self, from: d) else { return .idle }
- if (s.mode == "set" || s.mode == "rest") && Date().timeIntervalSince(s.updatedAt) > 3 * 3600 { return .idle }
+ if (s.mode == "set" || s.mode == "rest") && Date().timeIntervalSince(s.updatedAt) > 45 * 60 { return .idle }
return s
}
diff --git a/frontend/ios/App/WatchWidgets/OpenGymWidgets.swift b/frontend/ios/App/WatchWidgets/OpenGymWidgets.swift
index 553947423..ad7d3cd41 100644
--- a/frontend/ios/App/WatchWidgets/OpenGymWidgets.swift
+++ b/frontend/ios/App/WatchWidgets/OpenGymWidgets.swift
@@ -38,7 +38,15 @@ struct Provider: TimelineProvider {
var entries = [Entry(date: Date(), state: state)]
// When the rest is over the widget says so by itself; the app writes the next state then.
if state.mode == "rest", let end = state.restEndsAt, end > Date() {
- entries.append(Entry(date: end, state: WidgetState(mode: "set", title: state.title, detail: "", restEndsAt: nil)))
+ var after = state
+ after.mode = "set"
+ after.restEndsAt = nil
+ entries.append(Entry(date: end, state: after))
+ }
+ // Not touched by the watch app for 45 minutes: quiet (WidgetState.read says why).
+ if state.mode == "set" || state.mode == "rest" {
+ let quiet = max(Date(), state.updatedAt.addingTimeInterval(45 * 60))
+ entries.append(Entry(date: quiet, state: .idle))
}
completion(Timeline(entries: entries, policy: .never))
}