@capgo/capacitor-widget-kit 8.1.0
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/CapgoCapacitorWidgetKit.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +1119 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoNativeWidgetBridge.java +311 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoTemplateActionReceiver.java +36 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoTemplateSvgBitmapRenderer.java +25 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoTemplateWidgetBridge.java +31 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKit.java +218 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKitConstants.java +18 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKitPlugin.java +370 -0
- package/android/src/main/java/app/capgo/widgetkit/TemplateActivityStore.java +167 -0
- package/android/src/main/java/app/capgo/widgetkit/TemplateJsonUtils.java +369 -0
- package/android/src/main/java/app/capgo/widgetkit/TemplateRuntime.java +676 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +2223 -0
- package/dist/esm/definitions.d.ts +1117 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/helpers/workout.d.ts +32 -0
- package/dist/esm/helpers/workout.js +129 -0
- package/dist/esm/helpers/workout.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/runtime.d.ts +25 -0
- package/dist/esm/runtime.js +653 -0
- package/dist/esm/runtime.js.map +1 -0
- package/dist/esm/web.d.ts +23 -0
- package/dist/esm/web.js +292 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +1096 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +1099 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoNativeWidgetBridge.swift +372 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateWidgetBridge.swift +199 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWidgetKit.swift +218 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWidgetKitPlugin.swift +322 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWidgetKitSharedStore.swift +47 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWorkoutLiveActivityComponents.swift +246 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWorkoutLiveActivityWidget.swift +257 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CompleteSetIntent.swift +24 -0
- package/ios/Sources/CapgoWidgetKitPlugin/TemplateActionIntent.swift +56 -0
- package/ios/Sources/CapgoWidgetKitPlugin/TemplateActivityStore.swift +239 -0
- package/ios/Sources/CapgoWidgetKitPlugin/TemplateLiveActivityManager.swift +251 -0
- package/ios/Sources/CapgoWidgetKitPlugin/TemplateRuntime.swift +1067 -0
- package/ios/Sources/CapgoWidgetKitPlugin/WorkoutActivityStore.swift +111 -0
- package/ios/Sources/CapgoWidgetKitPlugin/WorkoutLiveActivityManager.swift +263 -0
- package/ios/Sources/CapgoWidgetKitPlugin/WorkoutSession.swift +271 -0
- package/ios/Tests/CapgoWidgetKitPluginTests/CapgoWidgetKitPluginTests.swift +130 -0
- package/package.json +93 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
@objc(CapgoWidgetKitPlugin)
|
|
5
|
+
public class CapgoWidgetKitPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
6
|
+
public let identifier = "CapgoWidgetKitPlugin"
|
|
7
|
+
public let jsName = "CapgoWidgetKit"
|
|
8
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
|
+
CAPPluginMethod(name: "areActivitiesSupported", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "startTemplateActivity", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "updateTemplateActivity", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "endTemplateActivity", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "performTemplateAction", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "getTemplateActivity", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "listTemplateActivities", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "listTemplateEvents", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "acknowledgeTemplateEvents", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "startWidgetSession", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "updateWidgetSession", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "stopWidgetSession", returnType: CAPPluginReturnPromise),
|
|
21
|
+
CAPPluginMethod(name: "getWidgetSession", returnType: CAPPluginReturnPromise),
|
|
22
|
+
CAPPluginMethod(name: "listWidgetSessions", returnType: CAPPluginReturnPromise),
|
|
23
|
+
CAPPluginMethod(name: "sendWidgetMessage", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "listWidgetMessages", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "acknowledgeWidgetMessages", returnType: CAPPluginReturnPromise),
|
|
26
|
+
CAPPluginMethod(name: "completeWidgetMessage", returnType: CAPPluginReturnPromise),
|
|
27
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
private let implementation = CapgoWidgetKit()
|
|
31
|
+
|
|
32
|
+
@objc func areActivitiesSupported(_ call: CAPPluginCall) {
|
|
33
|
+
call.resolve(implementation.areActivitiesSupported())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc func startTemplateActivity(_ call: CAPPluginCall) {
|
|
37
|
+
guard let definition = call.getObject("definition") else {
|
|
38
|
+
call.reject(CapgoWidgetKitBridgeError.missingObject("definition").localizedDescription)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
guard let state = call.getObject("state") else {
|
|
43
|
+
call.reject(CapgoWidgetKitBridgeError.missingObject("state").localizedDescription)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Task {
|
|
48
|
+
do {
|
|
49
|
+
let payload = try await implementation.startTemplateActivity(
|
|
50
|
+
activityId: call.getString("activityId"),
|
|
51
|
+
definitionObject: definition,
|
|
52
|
+
stateObject: state,
|
|
53
|
+
openUrl: call.getString("openUrl")
|
|
54
|
+
)
|
|
55
|
+
call.resolve(payload)
|
|
56
|
+
} catch {
|
|
57
|
+
call.reject(error.localizedDescription)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc func updateTemplateActivity(_ call: CAPPluginCall) {
|
|
63
|
+
guard let activityId = call.getString("activityId") else {
|
|
64
|
+
call.reject("The `activityId` is required.")
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Task {
|
|
69
|
+
do {
|
|
70
|
+
let payload = try await implementation.updateTemplateActivity(
|
|
71
|
+
activityId: activityId,
|
|
72
|
+
definitionObject: call.getObject("definition"),
|
|
73
|
+
stateObject: call.getObject("state"),
|
|
74
|
+
openUrl: call.getString("openUrl")
|
|
75
|
+
)
|
|
76
|
+
call.resolve(payload)
|
|
77
|
+
} catch {
|
|
78
|
+
call.reject(error.localizedDescription)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@objc func endTemplateActivity(_ call: CAPPluginCall) {
|
|
84
|
+
guard let activityId = call.getString("activityId") else {
|
|
85
|
+
call.reject("The `activityId` is required.")
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Task {
|
|
90
|
+
do {
|
|
91
|
+
try await implementation.endTemplateActivity(
|
|
92
|
+
activityId: activityId,
|
|
93
|
+
stateObject: call.getObject("state")
|
|
94
|
+
)
|
|
95
|
+
call.resolve()
|
|
96
|
+
} catch {
|
|
97
|
+
call.reject(error.localizedDescription)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@objc func performTemplateAction(_ call: CAPPluginCall) {
|
|
103
|
+
guard let activityId = call.getString("activityId") else {
|
|
104
|
+
call.reject("The `activityId` is required.")
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
guard let actionId = call.getString("actionId") else {
|
|
109
|
+
call.reject("The `actionId` is required.")
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Task {
|
|
114
|
+
do {
|
|
115
|
+
let payload = try await implementation.performTemplateAction(
|
|
116
|
+
activityId: activityId,
|
|
117
|
+
actionId: actionId,
|
|
118
|
+
sourceId: call.getString("sourceId"),
|
|
119
|
+
payloadObject: call.getObject("payload")
|
|
120
|
+
)
|
|
121
|
+
call.resolve(payload)
|
|
122
|
+
} catch {
|
|
123
|
+
call.reject(error.localizedDescription)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@objc func getTemplateActivity(_ call: CAPPluginCall) {
|
|
129
|
+
guard let activityId = call.getString("activityId") else {
|
|
130
|
+
call.reject("The `activityId` is required.")
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
do {
|
|
135
|
+
call.resolve(try implementation.getTemplateActivity(activityId: activityId))
|
|
136
|
+
} catch {
|
|
137
|
+
call.reject(error.localizedDescription)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@objc func listTemplateActivities(_ call: CAPPluginCall) {
|
|
142
|
+
do {
|
|
143
|
+
call.resolve(try implementation.listTemplateActivities())
|
|
144
|
+
} catch {
|
|
145
|
+
call.reject(error.localizedDescription)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@objc func listTemplateEvents(_ call: CAPPluginCall) {
|
|
150
|
+
do {
|
|
151
|
+
call.resolve(
|
|
152
|
+
try implementation.listTemplateEvents(
|
|
153
|
+
activityId: call.getString("activityId"),
|
|
154
|
+
unacknowledgedOnly: call.getBool("unacknowledgedOnly") ?? false
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
} catch {
|
|
158
|
+
call.reject(error.localizedDescription)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@objc func acknowledgeTemplateEvents(_ call: CAPPluginCall) {
|
|
163
|
+
let eventIds = call.getArray("eventIds", String.self)
|
|
164
|
+
|
|
165
|
+
do {
|
|
166
|
+
try implementation.acknowledgeTemplateEvents(
|
|
167
|
+
activityId: call.getString("activityId"),
|
|
168
|
+
eventIds: eventIds
|
|
169
|
+
)
|
|
170
|
+
call.resolve()
|
|
171
|
+
} catch {
|
|
172
|
+
call.reject(error.localizedDescription)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@objc func startWidgetSession(_ call: CAPPluginCall) {
|
|
177
|
+
do {
|
|
178
|
+
call.resolve(
|
|
179
|
+
try implementation.startWidgetSession(
|
|
180
|
+
widgetId: call.getString("widgetId"),
|
|
181
|
+
kind: call.getString("kind"),
|
|
182
|
+
stateObject: call.getObject("state"),
|
|
183
|
+
metadataObject: call.getObject("metadata")
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
} catch {
|
|
187
|
+
call.reject(error.localizedDescription)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@objc func updateWidgetSession(_ call: CAPPluginCall) {
|
|
192
|
+
guard let widgetId = call.getString("widgetId") else {
|
|
193
|
+
call.reject("The `widgetId` is required.")
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
do {
|
|
198
|
+
call.resolve(
|
|
199
|
+
try implementation.updateWidgetSession(
|
|
200
|
+
widgetId: widgetId,
|
|
201
|
+
stateObject: call.getObject("state"),
|
|
202
|
+
metadataObject: call.getObject("metadata"),
|
|
203
|
+
merge: call.getBool("merge") ?? false
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
} catch {
|
|
207
|
+
call.reject(error.localizedDescription)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@objc func stopWidgetSession(_ call: CAPPluginCall) {
|
|
212
|
+
guard let widgetId = call.getString("widgetId") else {
|
|
213
|
+
call.reject("The `widgetId` is required.")
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
do {
|
|
218
|
+
try implementation.stopWidgetSession(widgetId: widgetId, stateObject: call.getObject("state"))
|
|
219
|
+
call.resolve()
|
|
220
|
+
} catch {
|
|
221
|
+
call.reject(error.localizedDescription)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@objc func getWidgetSession(_ call: CAPPluginCall) {
|
|
226
|
+
guard let widgetId = call.getString("widgetId") else {
|
|
227
|
+
call.reject("The `widgetId` is required.")
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
do {
|
|
232
|
+
call.resolve(try implementation.getWidgetSession(widgetId: widgetId))
|
|
233
|
+
} catch {
|
|
234
|
+
call.reject(error.localizedDescription)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@objc func listWidgetSessions(_ call: CAPPluginCall) {
|
|
239
|
+
do {
|
|
240
|
+
call.resolve(try implementation.listWidgetSessions())
|
|
241
|
+
} catch {
|
|
242
|
+
call.reject(error.localizedDescription)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@objc func sendWidgetMessage(_ call: CAPPluginCall) {
|
|
247
|
+
guard let widgetId = call.getString("widgetId") else {
|
|
248
|
+
call.reject("The `widgetId` is required.")
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
guard let name = call.getString("name") else {
|
|
253
|
+
call.reject("The `name` is required.")
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
do {
|
|
258
|
+
call.resolve(
|
|
259
|
+
try implementation.sendWidgetMessage(
|
|
260
|
+
widgetId: widgetId,
|
|
261
|
+
direction: call.getString("direction"),
|
|
262
|
+
name: name,
|
|
263
|
+
payloadObject: call.getObject("payload"),
|
|
264
|
+
expectsResponse: call.getBool("expectsResponse") ?? false
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
} catch {
|
|
268
|
+
call.reject(error.localizedDescription)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@objc func listWidgetMessages(_ call: CAPPluginCall) {
|
|
273
|
+
do {
|
|
274
|
+
call.resolve(
|
|
275
|
+
try implementation.listWidgetMessages(
|
|
276
|
+
widgetId: call.getString("widgetId"),
|
|
277
|
+
direction: call.getString("direction"),
|
|
278
|
+
unacknowledgedOnly: call.getBool("unacknowledgedOnly") ?? false,
|
|
279
|
+
pendingOnly: call.getBool("pendingOnly") ?? false
|
|
280
|
+
)
|
|
281
|
+
)
|
|
282
|
+
} catch {
|
|
283
|
+
call.reject(error.localizedDescription)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@objc func acknowledgeWidgetMessages(_ call: CAPPluginCall) {
|
|
288
|
+
do {
|
|
289
|
+
try implementation.acknowledgeWidgetMessages(
|
|
290
|
+
messageIds: call.getArray("messageIds", String.self),
|
|
291
|
+
widgetId: call.getString("widgetId"),
|
|
292
|
+
direction: call.getString("direction")
|
|
293
|
+
)
|
|
294
|
+
call.resolve()
|
|
295
|
+
} catch {
|
|
296
|
+
call.reject(error.localizedDescription)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@objc func completeWidgetMessage(_ call: CAPPluginCall) {
|
|
301
|
+
guard let messageId = call.getString("messageId") else {
|
|
302
|
+
call.reject("The `messageId` is required.")
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
do {
|
|
307
|
+
call.resolve(
|
|
308
|
+
try implementation.completeWidgetMessage(
|
|
309
|
+
messageId: messageId,
|
|
310
|
+
responseObject: call.getObject("response"),
|
|
311
|
+
error: call.getString("error")
|
|
312
|
+
)
|
|
313
|
+
)
|
|
314
|
+
} catch {
|
|
315
|
+
call.reject(error.localizedDescription)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
320
|
+
call.resolve(implementation.getPluginVersion())
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public enum CapgoWidgetKitSharedStoreError: LocalizedError {
|
|
4
|
+
case missingAppGroup
|
|
5
|
+
case invalidSuite(String)
|
|
6
|
+
|
|
7
|
+
public var errorDescription: String? {
|
|
8
|
+
switch self {
|
|
9
|
+
case .missingAppGroup:
|
|
10
|
+
return "Missing App Group configuration. Set CapgoWidgetKitAppGroup in the app and widget extension Info.plist files."
|
|
11
|
+
case .invalidSuite(let suiteName):
|
|
12
|
+
return "Unable to open the shared App Group suite: \(suiteName)"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public enum CapgoWidgetKitSharedStore {
|
|
18
|
+
public static let appGroupInfoKey = "CapgoWidgetKitAppGroup"
|
|
19
|
+
|
|
20
|
+
public static func resolveAppGroupId(bundle: Bundle = .main) -> String? {
|
|
21
|
+
if let configured = bundle.object(forInfoDictionaryKey: appGroupInfoKey) as? String, !configured.isEmpty {
|
|
22
|
+
return configured
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
guard let bundleId = bundle.bundleIdentifier, !bundleId.isEmpty else {
|
|
26
|
+
return nil
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let lowercased = bundleId.lowercased()
|
|
30
|
+
if lowercased.contains("widget") || lowercased.contains("extension"),
|
|
31
|
+
bundleId.split(separator: ".").count > 1 {
|
|
32
|
+
return "group.\(bundleId.split(separator: ".").dropLast().joined(separator: ".")).widgetkit"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return "group.\(bundleId).widgetkit"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static func defaults(bundle: Bundle = .main) throws -> UserDefaults {
|
|
39
|
+
guard let suiteName = resolveAppGroupId(bundle: bundle) else {
|
|
40
|
+
throw CapgoWidgetKitSharedStoreError.missingAppGroup
|
|
41
|
+
}
|
|
42
|
+
guard let defaults = UserDefaults(suiteName: suiteName) else {
|
|
43
|
+
throw CapgoWidgetKitSharedStoreError.invalidSuite(suiteName)
|
|
44
|
+
}
|
|
45
|
+
return defaults
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#if canImport(ActivityKit) && canImport(WidgetKit)
|
|
2
|
+
import ActivityKit
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import WidgetKit
|
|
5
|
+
#if canImport(AppIntents)
|
|
6
|
+
import AppIntents
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
@available(iOS 16.2, *)
|
|
10
|
+
struct WorkoutRecommendationPill: View {
|
|
11
|
+
let text: String
|
|
12
|
+
|
|
13
|
+
var body: some View {
|
|
14
|
+
HStack(spacing: 6) {
|
|
15
|
+
Image(systemName: "sparkles")
|
|
16
|
+
.font(.caption.bold())
|
|
17
|
+
Text(text)
|
|
18
|
+
.font(.caption.weight(.semibold))
|
|
19
|
+
.lineLimit(1)
|
|
20
|
+
}
|
|
21
|
+
.foregroundStyle(.white)
|
|
22
|
+
.padding(.horizontal, 10)
|
|
23
|
+
.padding(.vertical, 6)
|
|
24
|
+
.background(Capsule().fill(Color.capgoBlue))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@available(iOS 16.2, *)
|
|
29
|
+
struct WorkoutTimerLabel: View {
|
|
30
|
+
let timer: WorkoutActiveTimer
|
|
31
|
+
let now: Date
|
|
32
|
+
|
|
33
|
+
var body: some View {
|
|
34
|
+
HStack(spacing: 6) {
|
|
35
|
+
Image(systemName: "timer")
|
|
36
|
+
.font(.subheadline.bold())
|
|
37
|
+
Text(timer.remainingText(now: now))
|
|
38
|
+
.font(.system(.title3, design: .rounded).weight(.bold))
|
|
39
|
+
.monospacedDigit()
|
|
40
|
+
}
|
|
41
|
+
.foregroundStyle(Color.capgoMint)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@available(iOS 16.2, *)
|
|
46
|
+
struct RestProgressBackground: View {
|
|
47
|
+
let timer: WorkoutActiveTimer
|
|
48
|
+
let now: Date
|
|
49
|
+
|
|
50
|
+
var body: some View {
|
|
51
|
+
GeometryReader { proxy in
|
|
52
|
+
let progress = timer.progress(now: now)
|
|
53
|
+
let remainingWidth = proxy.size.width * (1 - progress)
|
|
54
|
+
|
|
55
|
+
HStack(spacing: 0) {
|
|
56
|
+
Rectangle()
|
|
57
|
+
.fill(Color.capgoMint.opacity(0.75))
|
|
58
|
+
.frame(width: remainingWidth)
|
|
59
|
+
Spacer(minLength: 0)
|
|
60
|
+
}
|
|
61
|
+
.clipShape(RoundedRectangle(cornerRadius: 22, style: .continuous))
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@available(iOS 16.2, *)
|
|
67
|
+
struct WorkoutCompletionButton: View {
|
|
68
|
+
let sessionId: String
|
|
69
|
+
|
|
70
|
+
var body: some View {
|
|
71
|
+
Group {
|
|
72
|
+
#if canImport(AppIntents)
|
|
73
|
+
if #available(iOS 17.0, *) {
|
|
74
|
+
Button(intent: CompleteSetIntent(sessionId: sessionId)) {
|
|
75
|
+
buttonBody
|
|
76
|
+
}
|
|
77
|
+
.buttonStyle(.plain)
|
|
78
|
+
} else {
|
|
79
|
+
buttonBody
|
|
80
|
+
}
|
|
81
|
+
#else
|
|
82
|
+
buttonBody
|
|
83
|
+
#endif
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private var buttonBody: some View {
|
|
88
|
+
ZStack {
|
|
89
|
+
RoundedRectangle(cornerRadius: 18, style: .continuous)
|
|
90
|
+
.fill(Color.capgoMint)
|
|
91
|
+
Image(systemName: "checkmark")
|
|
92
|
+
.font(.system(size: 24, weight: .bold))
|
|
93
|
+
.foregroundStyle(.white)
|
|
94
|
+
}
|
|
95
|
+
.frame(width: 76, height: 62)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@available(iOS 16.2, *)
|
|
100
|
+
struct MissingSessionView: View {
|
|
101
|
+
var body: some View {
|
|
102
|
+
VStack(alignment: .leading, spacing: 8) {
|
|
103
|
+
Text("Capgo Widget Kit")
|
|
104
|
+
.font(.headline)
|
|
105
|
+
.foregroundStyle(.white)
|
|
106
|
+
Text("No shared workout session was found. Check the App Group and Info.plist setup.")
|
|
107
|
+
.font(.footnote)
|
|
108
|
+
.foregroundStyle(.white.opacity(0.7))
|
|
109
|
+
}
|
|
110
|
+
.padding(18)
|
|
111
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
112
|
+
.background(
|
|
113
|
+
RoundedRectangle(cornerRadius: 22, style: .continuous)
|
|
114
|
+
.fill(Color.black)
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@available(iOS 16.2, *)
|
|
120
|
+
struct WorkoutDynamicIslandLeadingView: View {
|
|
121
|
+
let attributes: WorkoutActivityAttributes
|
|
122
|
+
|
|
123
|
+
var body: some View {
|
|
124
|
+
Image(systemName: "figure.strengthtraining.traditional")
|
|
125
|
+
.foregroundStyle(Color.capgoMint)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@available(iOS 16.2, *)
|
|
130
|
+
struct WorkoutDynamicIslandTrailingView: View {
|
|
131
|
+
let attributes: WorkoutActivityAttributes
|
|
132
|
+
let contentState: WorkoutActivityAttributes.ContentState
|
|
133
|
+
|
|
134
|
+
private var session: WorkoutSession? {
|
|
135
|
+
try? WorkoutActivityStore.make().loadEnvelope(sessionId: attributes.sessionId)?.session
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var body: some View {
|
|
139
|
+
TimelineView(.periodic(from: .now, by: 1)) { timeline in
|
|
140
|
+
if let timer = session?.activeTimer(now: timeline.date) {
|
|
141
|
+
Text(timer.remainingText(now: timeline.date))
|
|
142
|
+
.monospacedDigit()
|
|
143
|
+
.foregroundStyle(Color.capgoMint)
|
|
144
|
+
} else if contentState.isComplete {
|
|
145
|
+
Image(systemName: "checkmark.circle.fill")
|
|
146
|
+
.foregroundStyle(Color.capgoMint)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@available(iOS 16.2, *)
|
|
153
|
+
struct WorkoutDynamicIslandCenterView: View {
|
|
154
|
+
let attributes: WorkoutActivityAttributes
|
|
155
|
+
|
|
156
|
+
var body: some View {
|
|
157
|
+
Text(attributes.title)
|
|
158
|
+
.font(.headline)
|
|
159
|
+
.lineLimit(1)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@available(iOS 16.2, *)
|
|
164
|
+
struct WorkoutDynamicIslandBottomView: View {
|
|
165
|
+
let attributes: WorkoutActivityAttributes
|
|
166
|
+
let contentState: WorkoutActivityAttributes.ContentState
|
|
167
|
+
|
|
168
|
+
private var session: WorkoutSession? {
|
|
169
|
+
try? WorkoutActivityStore.make().loadEnvelope(sessionId: attributes.sessionId)?.session
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var body: some View {
|
|
173
|
+
HStack(spacing: 12) {
|
|
174
|
+
Text(session?.currentSet?.title ?? "Session complete")
|
|
175
|
+
.font(.subheadline.weight(.semibold))
|
|
176
|
+
.lineLimit(1)
|
|
177
|
+
Spacer(minLength: 8)
|
|
178
|
+
if !(session?.isComplete ?? contentState.isComplete) {
|
|
179
|
+
WorkoutCompletionButton(sessionId: attributes.sessionId)
|
|
180
|
+
.frame(width: 54, height: 42)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@available(iOS 16.2, *)
|
|
187
|
+
struct WorkoutCompactLeadingView: View {
|
|
188
|
+
let contentState: WorkoutActivityAttributes.ContentState
|
|
189
|
+
|
|
190
|
+
var body: some View {
|
|
191
|
+
if let activeExerciseIndex = contentState.activeExerciseIndex, let activeSetIndex = contentState.activeSetIndex {
|
|
192
|
+
Text("\(activeExerciseIndex + 1).\(activeSetIndex + 1)")
|
|
193
|
+
.font(.caption2.monospacedDigit())
|
|
194
|
+
} else {
|
|
195
|
+
Image(systemName: "checkmark")
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@available(iOS 16.2, *)
|
|
201
|
+
struct WorkoutCompactTrailingView: View {
|
|
202
|
+
let contentState: WorkoutActivityAttributes.ContentState
|
|
203
|
+
|
|
204
|
+
var body: some View {
|
|
205
|
+
if contentState.isComplete {
|
|
206
|
+
Image(systemName: "checkmark.circle.fill")
|
|
207
|
+
.foregroundStyle(Color.capgoMint)
|
|
208
|
+
} else if let timerStartedAtMs = contentState.timerStartedAtMs, let timerDurationMs = contentState.timerDurationMs {
|
|
209
|
+
TimelineView(.periodic(from: .now, by: 1)) { timeline in
|
|
210
|
+
let timer = WorkoutActiveTimer(
|
|
211
|
+
source: WorkoutSetReference(
|
|
212
|
+
exerciseIndex: 0,
|
|
213
|
+
setIndex: 0,
|
|
214
|
+
set: WorkoutSet(title: ""),
|
|
215
|
+
exercise: WorkoutExercise(id: "placeholder", title: "", sets: [])
|
|
216
|
+
),
|
|
217
|
+
startedAtMs: timerStartedAtMs,
|
|
218
|
+
durationMs: timerDurationMs
|
|
219
|
+
)
|
|
220
|
+
Text(timer.remainingText(now: timeline.date))
|
|
221
|
+
.font(.caption2.monospacedDigit())
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@available(iOS 16.2, *)
|
|
228
|
+
struct WorkoutMinimalView: View {
|
|
229
|
+
let contentState: WorkoutActivityAttributes.ContentState
|
|
230
|
+
|
|
231
|
+
var body: some View {
|
|
232
|
+
if contentState.isComplete {
|
|
233
|
+
Image(systemName: "checkmark.circle.fill")
|
|
234
|
+
.foregroundStyle(Color.capgoMint)
|
|
235
|
+
} else {
|
|
236
|
+
Image(systemName: "figure.strengthtraining.traditional")
|
|
237
|
+
.foregroundStyle(Color.capgoMint)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
extension Color {
|
|
243
|
+
static let capgoMint = Color(red: 0.0, green: 0.85, blue: 0.62)
|
|
244
|
+
static let capgoBlue = Color(red: 0.33, green: 0.56, blue: 1.0)
|
|
245
|
+
}
|
|
246
|
+
#endif
|