@capgo/capacitor-widget-kit 8.1.1 → 8.1.3
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/README.md +120 -22
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKit.java +23 -3
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKitConstants.java +1 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoWidgetKitPlugin.java +15 -0
- package/android/src/main/java/app/capgo/widgetkit/TemplateRuntime.java +10 -2
- package/dist/docs.json +116 -2
- package/dist/esm/definitions.d.ts +60 -5
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/helpers/workout.js +28 -0
- package/dist/esm/helpers/workout.js.map +1 -1
- package/dist/esm/runtime.js +3 -3
- package/dist/esm/runtime.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +8 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +38 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +38 -4
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateHomeWidget.swift +117 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateWidgetBridge.swift +37 -2
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateWidgetViews.swift +288 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWidgetKit.swift +27 -2
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWidgetKitPlugin.swift +17 -1
- package/ios/Sources/CapgoWidgetKitPlugin/TemplateLiveActivityManager.swift +19 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
<h2><a href="https://capgo.app/consulting/?ref=plugin_widget_kit"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
-
Create WidgetKit, ActivityKit, and Android widget experiences from Capacitor without forcing one rendering model.
|
|
9
|
+
Create Home Screen WidgetKit, ActivityKit, and Android widget experiences from Capacitor without forcing one rendering model.
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
|
|
13
|
+
<img src="./docs/demo.webp" alt="Demo of capacitor-widget-kit in action" width="300" />
|
|
10
14
|
|
|
11
15
|
The plugin has two implementation paths:
|
|
12
16
|
|
|
13
|
-
- SVG template
|
|
17
|
+
- SVG template widgets: store Home Screen, Lock Screen, Dynamic Island, and Android layouts with optional named frames, hotspots, declarative state patches, pause/resume timers, and interaction events. Use this when your widget can be driven by resolved SVG output.
|
|
14
18
|
- Full-native widget sessions: store shared JSON state for native widget code and queue app-to-widget or widget-to-app messages. Use this when you want to render the widget fully in Swift/Kotlin/Java but still need Capacitor to start, stop, sync, or process async work.
|
|
15
19
|
|
|
16
20
|
The included workout flow is only an example helper built on top of the generic SVG abstraction.
|
|
@@ -25,7 +29,8 @@ bunx cap sync android
|
|
|
25
29
|
|
|
26
30
|
## iOS Requirements
|
|
27
31
|
|
|
28
|
-
-
|
|
32
|
+
- Add a Widget Extension target for Home Screen / SpringBoard widgets.
|
|
33
|
+
- iOS 17+ is recommended for interactive Home Screen widget and Live Activity buttons.
|
|
29
34
|
- Add `NSSupportsLiveActivities` to the app `Info.plist` when using ActivityKit.
|
|
30
35
|
- Add the same App Group to the app target and the widget extension target.
|
|
31
36
|
- Set `CapgoWidgetKitAppGroup` in both `Info.plist` files to the shared App Group identifier.
|
|
@@ -43,7 +48,9 @@ The plugin ships the native pieces a widget extension or Android widget can use:
|
|
|
43
48
|
|
|
44
49
|
- `CapgoTemplateActivityAttributes` for the iOS Live Activity bridge
|
|
45
50
|
- `CapgoTemplateActionIntent` for interactive iOS template buttons
|
|
51
|
+
- `CapgoTemplateWidgetTimelineProvider` and `CapgoTemplateHomeWidgetView` for real iOS Home Screen / SpringBoard widgets backed by WidgetKit timelines
|
|
46
52
|
- `CapgoTemplateWidgetBridge` to load a stored SVG activity and resolve one surface into `svg + width/height + frameId + hotspots + metadata`
|
|
53
|
+
- `CapgoTemplateSurfaceView`, `CapgoTemplateWidgetSurface`, and `CapgoTemplateLatestWidgetSurface` to place a rendered SVG view under native hotspot buttons in SwiftUI
|
|
47
54
|
- `CapgoNativeWidgetBridge` to load full-native widget sessions and exchange async messages without using SVG templates
|
|
48
55
|
- `CapgoTemplateActionReceiver` and `CapgoTemplateWidgetBridge` for Android template widgets
|
|
49
56
|
|
|
@@ -58,23 +65,53 @@ import CapgoWidgetKitPlugin
|
|
|
58
65
|
@main
|
|
59
66
|
struct ExampleWidgetBundle: WidgetBundle {
|
|
60
67
|
var body: some Widget {
|
|
68
|
+
ExampleTemplateHomeWidget()
|
|
69
|
+
|
|
61
70
|
if #available(iOS 16.2, *) {
|
|
62
71
|
ExampleTemplateLiveActivityWidget()
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
}
|
|
75
|
+
|
|
76
|
+
struct ExampleTemplateHomeWidget: Widget {
|
|
77
|
+
private let kind = "ExampleTemplateHomeWidget"
|
|
78
|
+
|
|
79
|
+
var body: some WidgetConfiguration {
|
|
80
|
+
StaticConfiguration(kind: kind, provider: CapgoTemplateWidgetTimelineProvider()) { entry in
|
|
81
|
+
CapgoTemplateHomeWidgetView(entry: entry) { layout in
|
|
82
|
+
MySvgRenderer(svg: layout.svg)
|
|
83
|
+
} placeholder: {
|
|
84
|
+
Text("No active widget")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
.configurationDisplayName("Capgo Template")
|
|
88
|
+
.description("Home Screen widget rendered from the shared Capgo SVG template store.")
|
|
89
|
+
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Use the SwiftUI surface helpers when a custom WidgetKit view should be designed from JS but rendered by native widget code:
|
|
95
|
+
|
|
96
|
+
```swift
|
|
97
|
+
CapgoTemplateLatestWidgetSurface {
|
|
98
|
+
layout in
|
|
99
|
+
MySvgRenderer(svg: layout.svg)
|
|
100
|
+
} placeholder: {
|
|
101
|
+
Text("No active widget")
|
|
102
|
+
}
|
|
66
103
|
```
|
|
67
104
|
|
|
68
|
-
See `example-app/widget-extension/ExampleWidgetBundle.swift` for a complete
|
|
105
|
+
The helper positions `CapgoTemplateActionIntent` buttons over the resolved SVG hotspots on iOS 17+. See `example-app/widget-extension/ExampleWidgetBundle.swift` for a complete Home Screen widget and Live Activity scaffold.
|
|
69
106
|
|
|
70
107
|
## SVG Template Usage
|
|
71
108
|
|
|
72
|
-
This mode is for widgets that can render resolved SVG. Hotspot actions can switch frames, mutate state, pause/play timers, and emit events for the app to process later.
|
|
109
|
+
This mode is for Home Screen, Lock Screen, Dynamic Island, and Android widgets that can render resolved SVG. Hotspot actions can switch frames, mutate state, pause/play timers, and emit events for the app to process later.
|
|
73
110
|
|
|
74
111
|
```ts
|
|
75
112
|
import { CapgoWidgetKit } from '@capgo/capacitor-widget-kit';
|
|
76
113
|
|
|
77
|
-
const { activity } = await CapgoWidgetKit.
|
|
114
|
+
const { activity } = await CapgoWidgetKit.startTemplateWidget({
|
|
78
115
|
activityId: 'session-1',
|
|
79
116
|
openUrl: 'widgetkitdemo://session/session-1',
|
|
80
117
|
state: {
|
|
@@ -89,7 +126,7 @@ const { activity } = await CapgoWidgetKit.startTemplateActivity({
|
|
|
89
126
|
{
|
|
90
127
|
id: 'next-frame',
|
|
91
128
|
eventName: 'widget.frame.changed',
|
|
92
|
-
frameMutations: [{ op: 'next', path: 'frame', surface: '
|
|
129
|
+
frameMutations: [{ op: 'next', path: 'frame', surface: 'homeScreen' }],
|
|
93
130
|
},
|
|
94
131
|
{
|
|
95
132
|
id: 'toggle-rest',
|
|
@@ -98,7 +135,7 @@ const { activity } = await CapgoWidgetKit.startTemplateActivity({
|
|
|
98
135
|
},
|
|
99
136
|
],
|
|
100
137
|
layouts: {
|
|
101
|
-
|
|
138
|
+
homeScreen: {
|
|
102
139
|
width: 100,
|
|
103
140
|
height: 40,
|
|
104
141
|
frameIdPath: 'state.frame',
|
|
@@ -169,12 +206,12 @@ await CapgoWidgetKit.stopWidgetSession({ widgetId: session.widgetId });
|
|
|
169
206
|
|
|
170
207
|
The `example-app/` folder is a lightweight Vite demo for the generic template flow. It runs in the browser using the preview store and demonstrates:
|
|
171
208
|
|
|
172
|
-
- starting one SVG template
|
|
173
|
-
- resolving the
|
|
209
|
+
- starting one SVG template widget for the Home Screen surface
|
|
210
|
+
- resolving the Home Screen surface
|
|
174
211
|
- running an action from the app and from a hotspot overlay
|
|
175
|
-
- reading the stored
|
|
212
|
+
- reading the stored widget template back
|
|
176
213
|
- reading and acknowledging the event log
|
|
177
|
-
- ending the
|
|
214
|
+
- ending the stored template
|
|
178
215
|
|
|
179
216
|
The workout helper is only used there as an example template factory.
|
|
180
217
|
|
|
@@ -184,6 +221,7 @@ The workout helper is only used there as an example template factory.
|
|
|
184
221
|
|
|
185
222
|
* [`areActivitiesSupported()`](#areactivitiessupported)
|
|
186
223
|
* [`startTemplateActivity(...)`](#starttemplateactivity)
|
|
224
|
+
* [`startTemplateWidget(...)`](#starttemplatewidget)
|
|
187
225
|
* [`updateTemplateActivity(...)`](#updatetemplateactivity)
|
|
188
226
|
* [`endTemplateActivity(...)`](#endtemplateactivity)
|
|
189
227
|
* [`performTemplateAction(...)`](#performtemplateaction)
|
|
@@ -200,6 +238,7 @@ The workout helper is only used there as an example template factory.
|
|
|
200
238
|
* [`listWidgetMessages(...)`](#listwidgetmessages)
|
|
201
239
|
* [`acknowledgeWidgetMessages(...)`](#acknowledgewidgetmessages)
|
|
202
240
|
* [`completeWidgetMessage(...)`](#completewidgetmessage)
|
|
241
|
+
* [`reloadWidgets(...)`](#reloadwidgets)
|
|
203
242
|
* [`getPluginVersion()`](#getpluginversion)
|
|
204
243
|
* [Interfaces](#interfaces)
|
|
205
244
|
* [Type Aliases](#type-aliases)
|
|
@@ -211,14 +250,15 @@ The workout helper is only used there as an example template factory.
|
|
|
211
250
|
|
|
212
251
|
Capacitor bridge for an iOS-first WidgetKit / Live Activities plugin.
|
|
213
252
|
|
|
214
|
-
The core abstraction is a generic SVG template
|
|
253
|
+
The core abstraction is a generic SVG template record:
|
|
215
254
|
- raw SVG templates with binding placeholders
|
|
216
255
|
- declarative action patches
|
|
217
256
|
- timer bindings exposed to the template scope
|
|
218
257
|
- event logging so the host app can process button results later
|
|
219
258
|
|
|
220
259
|
The plugin owns shared persistence, declarative action execution, and event retrieval.
|
|
221
|
-
The host widget extension keeps full freedom over actual WidgetKit rendering
|
|
260
|
+
The host widget extension keeps full freedom over actual WidgetKit rendering, including
|
|
261
|
+
Home Screen / SpringBoard widgets backed by WidgetKit timelines.
|
|
222
262
|
|
|
223
263
|
Full-native widgets can use widget sessions for synchronous shared state and widget messages
|
|
224
264
|
for asynchronous app/widget jobs without adopting the SVG template renderer.
|
|
@@ -253,6 +293,23 @@ Persist a generic SVG template activity and start the matching native Live Activ
|
|
|
253
293
|
--------------------
|
|
254
294
|
|
|
255
295
|
|
|
296
|
+
### startTemplateWidget(...)
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
startTemplateWidget(options: StartTemplateWidgetOptions) => Promise<StartTemplateActivityResult>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Persist a generic SVG template for Home Screen / SpringBoard widgets without starting a Live Activity.
|
|
303
|
+
|
|
304
|
+
| Param | Type |
|
|
305
|
+
| ------------- | --------------------------------------------------------------------------------- |
|
|
306
|
+
| **`options`** | <code><a href="#starttemplatewidgetoptions">StartTemplateWidgetOptions</a></code> |
|
|
307
|
+
|
|
308
|
+
**Returns:** <code>Promise<<a href="#starttemplateactivityresult">StartTemplateActivityResult</a>></code>
|
|
309
|
+
|
|
310
|
+
--------------------
|
|
311
|
+
|
|
312
|
+
|
|
256
313
|
### updateTemplateActivity(...)
|
|
257
314
|
|
|
258
315
|
```typescript
|
|
@@ -509,6 +566,21 @@ Complete or fail an async widget bridge message.
|
|
|
509
566
|
--------------------
|
|
510
567
|
|
|
511
568
|
|
|
569
|
+
### reloadWidgets(...)
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
reloadWidgets(options?: ReloadWidgetsOptions | undefined) => Promise<void>
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Ask native widgets to reload after external app state changes.
|
|
576
|
+
|
|
577
|
+
| Param | Type |
|
|
578
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
579
|
+
| **`options`** | <code><a href="#reloadwidgetsoptions">ReloadWidgetsOptions</a></code> |
|
|
580
|
+
|
|
581
|
+
--------------------
|
|
582
|
+
|
|
583
|
+
|
|
512
584
|
### getPluginVersion()
|
|
513
585
|
|
|
514
586
|
```typescript
|
|
@@ -578,13 +650,14 @@ Generic SVG template definition stored by the plugin.
|
|
|
578
650
|
|
|
579
651
|
Bundle of optional WidgetKit surface layouts.
|
|
580
652
|
|
|
581
|
-
| Prop | Type | Description
|
|
582
|
-
| ---------------------------------- | --------------------------------------------------------------- |
|
|
583
|
-
| **`
|
|
584
|
-
| **`
|
|
585
|
-
| **`
|
|
586
|
-
| **`
|
|
587
|
-
| **`
|
|
653
|
+
| Prop | Type | Description |
|
|
654
|
+
| ---------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
655
|
+
| **`homeScreen`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional Home Screen / SpringBoard widget layout. When omitted, native Home Screen widgets may fall back to `lockScreen`. |
|
|
656
|
+
| **`lockScreen`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional lock-screen / Live Activity banner layout. |
|
|
657
|
+
| **`dynamicIslandExpanded`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional expanded Dynamic Island layout. |
|
|
658
|
+
| **`dynamicIslandCompactLeading`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional compact leading Dynamic Island layout. |
|
|
659
|
+
| **`dynamicIslandCompactTrailing`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional compact trailing Dynamic Island layout. |
|
|
660
|
+
| **`dynamicIslandMinimal`** | <code><a href="#svgtemplatelayout">SvgTemplateLayout</a></code> | Optional minimal Dynamic Island layout. |
|
|
588
661
|
|
|
589
662
|
|
|
590
663
|
#### SvgTemplateLayoutWithSvg
|
|
@@ -736,6 +809,22 @@ Persisted timer runtime state.
|
|
|
736
809
|
|
|
737
810
|
Options for starting a generic SVG template activity.
|
|
738
811
|
|
|
812
|
+
| Prop | Type | Description |
|
|
813
|
+
| ----------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
814
|
+
| **`activityId`** | <code>string</code> | Optional explicit activity identifier. When omitted, the native runtime creates one. |
|
|
815
|
+
| **`definition`** | <code><a href="#svgtemplatedefinition">SvgTemplateDefinition</a></code> | Generic SVG template definition. |
|
|
816
|
+
| **`state`** | <code><a href="#svgtemplatestate">SvgTemplateState</a></code> | Initial JSON state exposed under `state.*`. |
|
|
817
|
+
| **`openUrl`** | <code>string</code> | Optional deep link used when the widget body is tapped. |
|
|
818
|
+
| **`startLiveActivity`** | <code>boolean</code> | Whether iOS should also start a native Live Activity. Defaults to `true`. Set to `false` when the same SVG template should only back a home-screen or lock-screen widget surface. |
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
#### StartTemplateWidgetOptions
|
|
822
|
+
|
|
823
|
+
Options for starting or replacing a Home Screen / SpringBoard widget template.
|
|
824
|
+
|
|
825
|
+
This persists the same SVG template record as `startTemplateActivity`, but native iOS
|
|
826
|
+
implementations do not start an ActivityKit Live Activity.
|
|
827
|
+
|
|
739
828
|
| Prop | Type | Description |
|
|
740
829
|
| ---------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
741
830
|
| **`activityId`** | <code>string</code> | Optional explicit activity identifier. When omitted, the native runtime creates one. |
|
|
@@ -1042,6 +1131,15 @@ Options for completing an async widget bridge message.
|
|
|
1042
1131
|
| **`error`** | <code>string</code> | Optional error string. When set, the message status becomes `failed`. |
|
|
1043
1132
|
|
|
1044
1133
|
|
|
1134
|
+
#### ReloadWidgetsOptions
|
|
1135
|
+
|
|
1136
|
+
Options for forcing installed native widgets to reload their timeline.
|
|
1137
|
+
|
|
1138
|
+
| Prop | Type | Description |
|
|
1139
|
+
| ---------- | ------------------- | ---------------------------------------------------------------------------------------------- |
|
|
1140
|
+
| **`kind`** | <code>string</code> | Optional native widget kind to reload on iOS. When omitted, every widget timeline is reloaded. |
|
|
1141
|
+
|
|
1142
|
+
|
|
1045
1143
|
#### PluginVersionResult
|
|
1046
1144
|
|
|
1047
1145
|
Result payload for plugin version queries.
|
|
@@ -1086,7 +1184,7 @@ JSON-safe array used as activity state.
|
|
|
1086
1184
|
|
|
1087
1185
|
Named WidgetKit surface for one SVG layout variant.
|
|
1088
1186
|
|
|
1089
|
-
<code>'lockScreen' | 'dynamicIslandExpanded' | 'dynamicIslandCompactLeading' | 'dynamicIslandCompactTrailing' | 'dynamicIslandMinimal'</code>
|
|
1187
|
+
<code>'homeScreen' | 'lockScreen' | 'dynamicIslandExpanded' | 'dynamicIslandCompactLeading' | 'dynamicIslandCompactTrailing' | 'dynamicIslandMinimal'</code>
|
|
1090
1188
|
|
|
1091
1189
|
|
|
1092
1190
|
#### SvgTemplateState
|
|
@@ -185,6 +185,11 @@ public class CapgoWidgetKit {
|
|
|
185
185
|
return message;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
public void reloadWidgets(final String kind) {
|
|
189
|
+
notifyStoreChanged(null, kind);
|
|
190
|
+
notifyWidgetBridgeChanged(null, null, kind);
|
|
191
|
+
}
|
|
192
|
+
|
|
188
193
|
public JSONObject getPluginVersion() throws JSONException {
|
|
189
194
|
String versionName = "android";
|
|
190
195
|
try {
|
|
@@ -199,13 +204,25 @@ public class CapgoWidgetKit {
|
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
private void notifyStoreChanged(final String activityId) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
207
|
+
notifyStoreChanged(activityId, null);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private void notifyStoreChanged(final String activityId, final String kind) {
|
|
211
|
+
final Intent intent = new Intent(CapgoWidgetKitConstants.ACTION_TEMPLATE_STORE_CHANGED).setPackage(context.getPackageName());
|
|
212
|
+
if (activityId != null) {
|
|
213
|
+
intent.putExtra(CapgoWidgetKitConstants.EXTRA_ACTIVITY_ID, activityId);
|
|
214
|
+
}
|
|
215
|
+
if (kind != null) {
|
|
216
|
+
intent.putExtra(CapgoWidgetKitConstants.EXTRA_WIDGET_KIND, kind);
|
|
217
|
+
}
|
|
205
218
|
context.sendBroadcast(intent);
|
|
206
219
|
}
|
|
207
220
|
|
|
208
221
|
private void notifyWidgetBridgeChanged(final String widgetId, final String messageId) {
|
|
222
|
+
notifyWidgetBridgeChanged(widgetId, messageId, null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private void notifyWidgetBridgeChanged(final String widgetId, final String messageId, final String kind) {
|
|
209
226
|
final Intent intent = new Intent(CapgoWidgetKitConstants.ACTION_NATIVE_WIDGET_BRIDGE_CHANGED).setPackage(context.getPackageName());
|
|
210
227
|
if (widgetId != null) {
|
|
211
228
|
intent.putExtra(CapgoWidgetKitConstants.EXTRA_WIDGET_ID, widgetId);
|
|
@@ -213,6 +230,9 @@ public class CapgoWidgetKit {
|
|
|
213
230
|
if (messageId != null) {
|
|
214
231
|
intent.putExtra(CapgoWidgetKitConstants.EXTRA_MESSAGE_ID, messageId);
|
|
215
232
|
}
|
|
233
|
+
if (kind != null) {
|
|
234
|
+
intent.putExtra(CapgoWidgetKitConstants.EXTRA_WIDGET_KIND, kind);
|
|
235
|
+
}
|
|
216
236
|
context.sendBroadcast(intent);
|
|
217
237
|
}
|
|
218
238
|
}
|
|
@@ -10,6 +10,7 @@ public final class CapgoWidgetKitConstants {
|
|
|
10
10
|
public static final String EXTRA_ACTION_ID = "actionId";
|
|
11
11
|
public static final String EXTRA_SOURCE_ID = "sourceId";
|
|
12
12
|
public static final String EXTRA_PAYLOAD_JSON = "payloadJson";
|
|
13
|
+
public static final String EXTRA_WIDGET_KIND = "widgetKind";
|
|
13
14
|
public static final String EXTRA_WIDGET_ID = "widgetId";
|
|
14
15
|
public static final String EXTRA_MESSAGE_ID = "messageId";
|
|
15
16
|
public static final String ACTIVITY_IDS_KEY = "activityIds";
|
|
@@ -32,6 +32,15 @@ public class CapgoWidgetKitPlugin extends Plugin {
|
|
|
32
32
|
|
|
33
33
|
@PluginMethod
|
|
34
34
|
public void startTemplateActivity(final PluginCall call) {
|
|
35
|
+
startTemplateRecord(call);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@PluginMethod
|
|
39
|
+
public void startTemplateWidget(final PluginCall call) {
|
|
40
|
+
startTemplateRecord(call);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private void startTemplateRecord(final PluginCall call) {
|
|
35
44
|
final JSObject definition = call.getObject("definition");
|
|
36
45
|
final JSObject state = call.getObject("state");
|
|
37
46
|
|
|
@@ -347,6 +356,12 @@ public class CapgoWidgetKitPlugin extends Plugin {
|
|
|
347
356
|
}
|
|
348
357
|
}
|
|
349
358
|
|
|
359
|
+
@PluginMethod
|
|
360
|
+
public void reloadWidgets(final PluginCall call) {
|
|
361
|
+
implementation.reloadWidgets(call.getString("kind"));
|
|
362
|
+
call.resolve();
|
|
363
|
+
}
|
|
364
|
+
|
|
350
365
|
@PluginMethod
|
|
351
366
|
public void getPluginVersion(final PluginCall call) {
|
|
352
367
|
try {
|
|
@@ -167,7 +167,7 @@ final class TemplateRuntime {
|
|
|
167
167
|
|
|
168
168
|
static JSONObject resolveSurface(final JSONObject record, final String surface, final long nowMs) throws JSONException {
|
|
169
169
|
final JSONObject layouts = record.getJSONObject("definition").getJSONObject("layouts");
|
|
170
|
-
final JSONObject layout = layouts
|
|
170
|
+
final JSONObject layout = layoutForSurface(layouts, surface);
|
|
171
171
|
if (layout == null) {
|
|
172
172
|
return null;
|
|
173
173
|
}
|
|
@@ -431,7 +431,7 @@ final class TemplateRuntime {
|
|
|
431
431
|
return new JSONArray();
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
-
final JSONObject layout = activity.getJSONObject("definition").getJSONObject("layouts")
|
|
434
|
+
final JSONObject layout = layoutForSurface(activity.getJSONObject("definition").getJSONObject("layouts"), surface);
|
|
435
435
|
final JSONArray frames = layout != null ? TemplateJsonUtils.arrayOrEmpty(layout, "frames") : new JSONArray();
|
|
436
436
|
final JSONArray frameIds = new JSONArray();
|
|
437
437
|
for (int index = 0; index < frames.length(); index += 1) {
|
|
@@ -443,6 +443,14 @@ final class TemplateRuntime {
|
|
|
443
443
|
return frameIds;
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
+
private static JSONObject layoutForSurface(final JSONObject layouts, final String surface) {
|
|
447
|
+
final JSONObject layout = layouts.optJSONObject(surface);
|
|
448
|
+
if (layout != null) {
|
|
449
|
+
return layout;
|
|
450
|
+
}
|
|
451
|
+
return "homeScreen".equals(surface) ? layouts.optJSONObject("lockScreen") : null;
|
|
452
|
+
}
|
|
453
|
+
|
|
446
454
|
private static int indexOfString(final JSONArray values, final String target) {
|
|
447
455
|
for (int index = 0; index < values.length(); index += 1) {
|
|
448
456
|
if (target.equals(values.optString(index))) {
|
package/dist/docs.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"api": {
|
|
3
3
|
"name": "CapgoWidgetKitPlugin",
|
|
4
4
|
"slug": "capgowidgetkitplugin",
|
|
5
|
-
"docs": "Capacitor bridge for an iOS-first WidgetKit / Live Activities plugin.\n\nThe core abstraction is a generic SVG template
|
|
5
|
+
"docs": "Capacitor bridge for an iOS-first WidgetKit / Live Activities plugin.\n\nThe core abstraction is a generic SVG template record:\n- raw SVG templates with binding placeholders\n- declarative action patches\n- timer bindings exposed to the template scope\n- event logging so the host app can process button results later\n\nThe plugin owns shared persistence, declarative action execution, and event retrieval.\nThe host widget extension keeps full freedom over actual WidgetKit rendering, including\nHome Screen / SpringBoard widgets backed by WidgetKit timelines.\n\nFull-native widgets can use widget sessions for synchronous shared state and widget messages\nfor asynchronous app/widget jobs without adopting the SVG template renderer.",
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
@@ -36,6 +36,25 @@
|
|
|
36
36
|
],
|
|
37
37
|
"slug": "starttemplateactivity"
|
|
38
38
|
},
|
|
39
|
+
{
|
|
40
|
+
"name": "startTemplateWidget",
|
|
41
|
+
"signature": "(options: StartTemplateWidgetOptions) => Promise<StartTemplateActivityResult>",
|
|
42
|
+
"parameters": [
|
|
43
|
+
{
|
|
44
|
+
"name": "options",
|
|
45
|
+
"docs": "",
|
|
46
|
+
"type": "StartTemplateWidgetOptions"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"returns": "Promise<StartTemplateActivityResult>",
|
|
50
|
+
"tags": [],
|
|
51
|
+
"docs": "Persist a generic SVG template for Home Screen / SpringBoard widgets without starting a Live Activity.",
|
|
52
|
+
"complexTypes": [
|
|
53
|
+
"StartTemplateActivityResult",
|
|
54
|
+
"StartTemplateWidgetOptions"
|
|
55
|
+
],
|
|
56
|
+
"slug": "starttemplatewidget"
|
|
57
|
+
},
|
|
39
58
|
{
|
|
40
59
|
"name": "updateTemplateActivity",
|
|
41
60
|
"signature": "(options: UpdateTemplateActivityOptions) => Promise<TemplateActivityResult>",
|
|
@@ -322,6 +341,24 @@
|
|
|
322
341
|
],
|
|
323
342
|
"slug": "completewidgetmessage"
|
|
324
343
|
},
|
|
344
|
+
{
|
|
345
|
+
"name": "reloadWidgets",
|
|
346
|
+
"signature": "(options?: ReloadWidgetsOptions | undefined) => Promise<void>",
|
|
347
|
+
"parameters": [
|
|
348
|
+
{
|
|
349
|
+
"name": "options",
|
|
350
|
+
"docs": "",
|
|
351
|
+
"type": "ReloadWidgetsOptions | undefined"
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
"returns": "Promise<void>",
|
|
355
|
+
"tags": [],
|
|
356
|
+
"docs": "Ask native widgets to reload after external app state changes.",
|
|
357
|
+
"complexTypes": [
|
|
358
|
+
"ReloadWidgetsOptions"
|
|
359
|
+
],
|
|
360
|
+
"slug": "reloadwidgets"
|
|
361
|
+
},
|
|
325
362
|
{
|
|
326
363
|
"name": "getPluginVersion",
|
|
327
364
|
"signature": "() => Promise<PluginVersionResult>",
|
|
@@ -517,10 +554,19 @@
|
|
|
517
554
|
"tags": [],
|
|
518
555
|
"methods": [],
|
|
519
556
|
"properties": [
|
|
557
|
+
{
|
|
558
|
+
"name": "homeScreen",
|
|
559
|
+
"tags": [],
|
|
560
|
+
"docs": "Optional Home Screen / SpringBoard widget layout.\n\nWhen omitted, native Home Screen widgets may fall back to `lockScreen`.",
|
|
561
|
+
"complexTypes": [
|
|
562
|
+
"SvgTemplateLayout"
|
|
563
|
+
],
|
|
564
|
+
"type": "SvgTemplateLayout"
|
|
565
|
+
},
|
|
520
566
|
{
|
|
521
567
|
"name": "lockScreen",
|
|
522
568
|
"tags": [],
|
|
523
|
-
"docs": "
|
|
569
|
+
"docs": "Optional lock-screen / Live Activity banner layout.",
|
|
524
570
|
"complexTypes": [
|
|
525
571
|
"SvgTemplateLayout"
|
|
526
572
|
],
|
|
@@ -1110,6 +1156,54 @@
|
|
|
1110
1156
|
"docs": "Options for starting a generic SVG template activity.",
|
|
1111
1157
|
"tags": [],
|
|
1112
1158
|
"methods": [],
|
|
1159
|
+
"properties": [
|
|
1160
|
+
{
|
|
1161
|
+
"name": "activityId",
|
|
1162
|
+
"tags": [],
|
|
1163
|
+
"docs": "Optional explicit activity identifier. When omitted, the native runtime creates one.",
|
|
1164
|
+
"complexTypes": [],
|
|
1165
|
+
"type": "string | undefined"
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
"name": "definition",
|
|
1169
|
+
"tags": [],
|
|
1170
|
+
"docs": "Generic SVG template definition.",
|
|
1171
|
+
"complexTypes": [
|
|
1172
|
+
"SvgTemplateDefinition"
|
|
1173
|
+
],
|
|
1174
|
+
"type": "SvgTemplateDefinition"
|
|
1175
|
+
},
|
|
1176
|
+
{
|
|
1177
|
+
"name": "state",
|
|
1178
|
+
"tags": [],
|
|
1179
|
+
"docs": "Initial JSON state exposed under `state.*`.",
|
|
1180
|
+
"complexTypes": [
|
|
1181
|
+
"SvgTemplateState"
|
|
1182
|
+
],
|
|
1183
|
+
"type": "SvgTemplateState"
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
"name": "openUrl",
|
|
1187
|
+
"tags": [],
|
|
1188
|
+
"docs": "Optional deep link used when the widget body is tapped.",
|
|
1189
|
+
"complexTypes": [],
|
|
1190
|
+
"type": "string | undefined"
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
"name": "startLiveActivity",
|
|
1194
|
+
"tags": [],
|
|
1195
|
+
"docs": "Whether iOS should also start a native Live Activity.\n\nDefaults to `true`. Set to `false` when the same SVG template should only back\na home-screen or lock-screen widget surface.",
|
|
1196
|
+
"complexTypes": [],
|
|
1197
|
+
"type": "boolean | undefined"
|
|
1198
|
+
}
|
|
1199
|
+
]
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
"name": "StartTemplateWidgetOptions",
|
|
1203
|
+
"slug": "starttemplatewidgetoptions",
|
|
1204
|
+
"docs": "Options for starting or replacing a Home Screen / SpringBoard widget template.\n\nThis persists the same SVG template record as `startTemplateActivity`, but native iOS\nimplementations do not start an ActivityKit Live Activity.",
|
|
1205
|
+
"tags": [],
|
|
1206
|
+
"methods": [],
|
|
1113
1207
|
"properties": [
|
|
1114
1208
|
{
|
|
1115
1209
|
"name": "activityId",
|
|
@@ -2031,6 +2125,22 @@
|
|
|
2031
2125
|
}
|
|
2032
2126
|
]
|
|
2033
2127
|
},
|
|
2128
|
+
{
|
|
2129
|
+
"name": "ReloadWidgetsOptions",
|
|
2130
|
+
"slug": "reloadwidgetsoptions",
|
|
2131
|
+
"docs": "Options for forcing installed native widgets to reload their timeline.",
|
|
2132
|
+
"tags": [],
|
|
2133
|
+
"methods": [],
|
|
2134
|
+
"properties": [
|
|
2135
|
+
{
|
|
2136
|
+
"name": "kind",
|
|
2137
|
+
"tags": [],
|
|
2138
|
+
"docs": "Optional native widget kind to reload on iOS. When omitted, every widget timeline is reloaded.",
|
|
2139
|
+
"complexTypes": [],
|
|
2140
|
+
"type": "string | undefined"
|
|
2141
|
+
}
|
|
2142
|
+
]
|
|
2143
|
+
},
|
|
2034
2144
|
{
|
|
2035
2145
|
"name": "PluginVersionResult",
|
|
2036
2146
|
"slug": "pluginversionresult",
|
|
@@ -2135,6 +2245,10 @@
|
|
|
2135
2245
|
"slug": "svgtemplatesurface",
|
|
2136
2246
|
"docs": "Named WidgetKit surface for one SVG layout variant.",
|
|
2137
2247
|
"types": [
|
|
2248
|
+
{
|
|
2249
|
+
"text": "'homeScreen'",
|
|
2250
|
+
"complexTypes": []
|
|
2251
|
+
},
|
|
2138
2252
|
{
|
|
2139
2253
|
"text": "'lockScreen'",
|
|
2140
2254
|
"complexTypes": []
|