@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,130 @@
|
|
|
1
|
+
// swiftlint:disable function_body_length
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import CapgoWidgetKitPlugin
|
|
4
|
+
|
|
5
|
+
final class CapgoWidgetKitPluginTests: XCTestCase {
|
|
6
|
+
func testResolveSvgInterpolatesStateTimerAndMetaScope() {
|
|
7
|
+
let definition = makeTemplateDefinition()
|
|
8
|
+
let record = TemplateRuntime.makeRecord(
|
|
9
|
+
activityId: "activity-1",
|
|
10
|
+
definitionObject: definition,
|
|
11
|
+
stateObject: ["title": "Chest Day"],
|
|
12
|
+
openUrl: "widgetkitdemo://session/session-1",
|
|
13
|
+
nowMs: 1_000
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
let layoutObject = ((definition["layouts"] as? [String: Any])?["lockScreen"] as? [String: Any]) ?? [:]
|
|
17
|
+
let svg = TemplateRuntime.resolveSvg(layoutObject: layoutObject, record: record, nowMs: 1_000)
|
|
18
|
+
|
|
19
|
+
XCTAssertTrue(svg.contains("Chest Day"))
|
|
20
|
+
XCTAssertTrue(svg.contains("1:30"))
|
|
21
|
+
XCTAssertTrue(svg.contains("template-1"))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func testApplyActionUsesSourceIdPayloadAndTimerMutation() throws {
|
|
25
|
+
let definition = makeTemplateDefinition()
|
|
26
|
+
let record = TemplateRuntime.makeRecord(
|
|
27
|
+
activityId: "activity-1",
|
|
28
|
+
definitionObject: definition,
|
|
29
|
+
stateObject: ["title": "Chest Day", "count": 0],
|
|
30
|
+
openUrl: nil,
|
|
31
|
+
nowMs: 1_000
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
let (nextRecord, event) = try TemplateRuntime.applyAction(
|
|
35
|
+
actionId: "complete-set",
|
|
36
|
+
sourceId: "primary-complete-button",
|
|
37
|
+
payloadObject: [
|
|
38
|
+
"label": "Bench Press",
|
|
39
|
+
"durationMs": 30_000
|
|
40
|
+
],
|
|
41
|
+
record: record,
|
|
42
|
+
nowMs: 5_000
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
XCTAssertEqual((nextRecord.state["count"] as? NSNumber)?.intValue, 1)
|
|
46
|
+
XCTAssertEqual(nextRecord.state["lastSource"] as? String, "primary-complete-button")
|
|
47
|
+
XCTAssertEqual(nextRecord.state["lastLabel"] as? String, "Bench Press")
|
|
48
|
+
XCTAssertEqual(nextRecord.state["summary"] as? String, "primary-complete-button :: Bench Press")
|
|
49
|
+
|
|
50
|
+
let timer = nextRecord.timers["cooldown"]
|
|
51
|
+
XCTAssertEqual(timer?.durationMs, 30_000)
|
|
52
|
+
XCTAssertEqual(timer?.startedAtMs, 5_000)
|
|
53
|
+
XCTAssertEqual(timer?.status, "running")
|
|
54
|
+
|
|
55
|
+
XCTAssertEqual(event.sourceId, "primary-complete-button")
|
|
56
|
+
|
|
57
|
+
let serializedEvent = try TemplateRuntime.serializeEvent(event)
|
|
58
|
+
XCTAssertEqual(serializedEvent["sourceId"] as? String, "primary-complete-button")
|
|
59
|
+
|
|
60
|
+
let payload = serializedEvent["payload"] as? [String: Any]
|
|
61
|
+
XCTAssertEqual(payload?["label"] as? String, "Bench Press")
|
|
62
|
+
|
|
63
|
+
let timers = serializedEvent["timers"] as? [String: Any]
|
|
64
|
+
let cooldown = timers?["cooldown"] as? [String: Any]
|
|
65
|
+
XCTAssertEqual((cooldown?["durationMs"] as? NSNumber)?.intValue, 30_000)
|
|
66
|
+
XCTAssertEqual((cooldown?["startedAt"] as? NSNumber)?.intValue, 5_000)
|
|
67
|
+
XCTAssertEqual(cooldown?["status"] as? String, "running")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private func makeTemplateDefinition() -> [String: Any] {
|
|
71
|
+
[
|
|
72
|
+
"id": "template-1",
|
|
73
|
+
"timers": [
|
|
74
|
+
[
|
|
75
|
+
"id": "cooldown",
|
|
76
|
+
"durationMs": 90_000,
|
|
77
|
+
"autoStart": true
|
|
78
|
+
]
|
|
79
|
+
],
|
|
80
|
+
"actions": [
|
|
81
|
+
[
|
|
82
|
+
"id": "complete-set",
|
|
83
|
+
"eventName": "widget.set.completed",
|
|
84
|
+
"patches": [
|
|
85
|
+
[
|
|
86
|
+
"op": "increment",
|
|
87
|
+
"path": "count",
|
|
88
|
+
"amount": 1
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
"op": "set",
|
|
92
|
+
"path": "lastSource",
|
|
93
|
+
"valueTemplate": "{{action.sourceId}}"
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
"op": "set",
|
|
97
|
+
"path": "lastLabel",
|
|
98
|
+
"valueTemplate": "{{action.payload.label}}"
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
"op": "set",
|
|
102
|
+
"path": "summary",
|
|
103
|
+
"valueTemplate": "{{action.sourceId}} :: {{action.payload.label}}"
|
|
104
|
+
]
|
|
105
|
+
],
|
|
106
|
+
"timerMutations": [
|
|
107
|
+
[
|
|
108
|
+
"op": "setDuration",
|
|
109
|
+
"timerId": "cooldown",
|
|
110
|
+
"durationPath": "action.payload.durationMs"
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
"op": "restart",
|
|
114
|
+
"timerId": "cooldown",
|
|
115
|
+
"durationPath": "action.payload.durationMs"
|
|
116
|
+
]
|
|
117
|
+
]
|
|
118
|
+
]
|
|
119
|
+
],
|
|
120
|
+
"layouts": [
|
|
121
|
+
"lockScreen": [
|
|
122
|
+
"width": 100,
|
|
123
|
+
"height": 40,
|
|
124
|
+
"svg": "<svg>{{state.title}}|{{timers.cooldown.remainingText}}|{{meta.template.id}}</svg>"
|
|
125
|
+
]
|
|
126
|
+
]
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// swiftlint:enable function_body_length
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-widget-kit",
|
|
3
|
+
"version": "8.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Capacitor plugin for generic iOS WidgetKit and Live Activities using SVG templates, declarative actions, and shared App Group persistence.",
|
|
6
|
+
"main": "dist/plugin.cjs.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/esm/index.d.ts",
|
|
9
|
+
"unpkg": "dist/plugin.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"android/src/main/",
|
|
12
|
+
"android/build.gradle",
|
|
13
|
+
"dist/",
|
|
14
|
+
"ios/Sources",
|
|
15
|
+
"ios/Tests",
|
|
16
|
+
"Package.swift",
|
|
17
|
+
"CapgoCapacitorWidgetKit.podspec"
|
|
18
|
+
],
|
|
19
|
+
"author": "Martin Donadieu <martin@capgo.app>",
|
|
20
|
+
"license": "MPL-2.0",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+ssh://git@github.com/Cap-go/capacitor-widget-kit.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Cap-go/capacitor-widget-kit/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://capgo.app/docs/plugins/widget-kit/",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"capacitor",
|
|
31
|
+
"plugin",
|
|
32
|
+
"widgetkit",
|
|
33
|
+
"live-activities",
|
|
34
|
+
"activitykit",
|
|
35
|
+
"ios"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"verify": "bun run verify:ios && bun run verify:android && bun run verify:package",
|
|
39
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorWidgetKit -destination generic/platform=iOS",
|
|
40
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
41
|
+
"verify:package": "bun run build",
|
|
42
|
+
"test:maestro": "./scripts/run-maestro-native.sh ios",
|
|
43
|
+
"test:maestro:ios": "./scripts/run-maestro-native.sh ios",
|
|
44
|
+
"test:maestro:android": "./scripts/run-maestro-native.sh android",
|
|
45
|
+
"lint": "rimraf ./build/example-ios && bun run eslint && bun run prettier -- --check && bun run swiftlint -- lint",
|
|
46
|
+
"fmt": "bun run eslint -- --fix && bun run prettier -- --write && bun run swiftlint -- --fix --format",
|
|
47
|
+
"eslint": "eslint . --ext .ts",
|
|
48
|
+
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,json,java,mjs}\" --plugin=prettier-plugin-java",
|
|
49
|
+
"swiftlint": "node-swiftlint",
|
|
50
|
+
"docgen": "docgen --api CapgoWidgetKitPlugin --output-readme README.md --output-json dist/docs.json",
|
|
51
|
+
"build": "bun run clean && bun run docgen && tsc && rollup -c rollup.config.mjs",
|
|
52
|
+
"clean": "rimraf ./dist",
|
|
53
|
+
"watch": "tsc --watch",
|
|
54
|
+
"prepublishOnly": "bun run build",
|
|
55
|
+
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@capacitor/android": "^8.0.0",
|
|
59
|
+
"@capacitor/cli": "^8.0.0",
|
|
60
|
+
"@capacitor/core": "^8.0.0",
|
|
61
|
+
"@capacitor/docgen": "^0.3.1",
|
|
62
|
+
"@capacitor/ios": "^8.0.0",
|
|
63
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
64
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
65
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
66
|
+
"@types/node": "^24.10.1",
|
|
67
|
+
"eslint": "^8.57.1",
|
|
68
|
+
"eslint-plugin-import": "^2.31.0",
|
|
69
|
+
"prettier": "^3.6.2",
|
|
70
|
+
"prettier-plugin-java": "^2.7.7",
|
|
71
|
+
"prettier-pretty-check": "^0.2.0",
|
|
72
|
+
"rimraf": "^6.1.0",
|
|
73
|
+
"rollup": "^4.53.2",
|
|
74
|
+
"swiftlint": "^2.0.0",
|
|
75
|
+
"typescript": "^5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": ">=8.0.0"
|
|
79
|
+
},
|
|
80
|
+
"prettier": "@ionic/prettier-config",
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
82
|
+
"eslintConfig": {
|
|
83
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
84
|
+
},
|
|
85
|
+
"capacitor": {
|
|
86
|
+
"ios": {
|
|
87
|
+
"src": "ios"
|
|
88
|
+
},
|
|
89
|
+
"android": {
|
|
90
|
+
"src": "android"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|