@capgo/capacitor-widget-kit 8.1.2 → 8.1.4
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 +116 -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,7 +6,7 @@
|
|
|
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
10
|
|
|
11
11
|
## Demo
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ Create WidgetKit, ActivityKit, and Android widget experiences from Capacitor wit
|
|
|
14
14
|
|
|
15
15
|
The plugin has two implementation paths:
|
|
16
16
|
|
|
17
|
-
- 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.
|
|
18
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.
|
|
19
19
|
|
|
20
20
|
The included workout flow is only an example helper built on top of the generic SVG abstraction.
|
|
@@ -29,7 +29,8 @@ bunx cap sync android
|
|
|
29
29
|
|
|
30
30
|
## iOS Requirements
|
|
31
31
|
|
|
32
|
-
-
|
|
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.
|
|
33
34
|
- Add `NSSupportsLiveActivities` to the app `Info.plist` when using ActivityKit.
|
|
34
35
|
- Add the same App Group to the app target and the widget extension target.
|
|
35
36
|
- Set `CapgoWidgetKitAppGroup` in both `Info.plist` files to the shared App Group identifier.
|
|
@@ -47,7 +48,9 @@ The plugin ships the native pieces a widget extension or Android widget can use:
|
|
|
47
48
|
|
|
48
49
|
- `CapgoTemplateActivityAttributes` for the iOS Live Activity bridge
|
|
49
50
|
- `CapgoTemplateActionIntent` for interactive iOS template buttons
|
|
51
|
+
- `CapgoTemplateWidgetTimelineProvider` and `CapgoTemplateHomeWidgetView` for real iOS Home Screen / SpringBoard widgets backed by WidgetKit timelines
|
|
50
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
|
|
51
54
|
- `CapgoNativeWidgetBridge` to load full-native widget sessions and exchange async messages without using SVG templates
|
|
52
55
|
- `CapgoTemplateActionReceiver` and `CapgoTemplateWidgetBridge` for Android template widgets
|
|
53
56
|
|
|
@@ -62,23 +65,53 @@ import CapgoWidgetKitPlugin
|
|
|
62
65
|
@main
|
|
63
66
|
struct ExampleWidgetBundle: WidgetBundle {
|
|
64
67
|
var body: some Widget {
|
|
68
|
+
ExampleTemplateHomeWidget()
|
|
69
|
+
|
|
65
70
|
if #available(iOS 16.2, *) {
|
|
66
71
|
ExampleTemplateLiveActivityWidget()
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
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
|
+
}
|
|
70
103
|
```
|
|
71
104
|
|
|
72
|
-
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.
|
|
73
106
|
|
|
74
107
|
## SVG Template Usage
|
|
75
108
|
|
|
76
|
-
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.
|
|
77
110
|
|
|
78
111
|
```ts
|
|
79
112
|
import { CapgoWidgetKit } from '@capgo/capacitor-widget-kit';
|
|
80
113
|
|
|
81
|
-
const { activity } = await CapgoWidgetKit.
|
|
114
|
+
const { activity } = await CapgoWidgetKit.startTemplateWidget({
|
|
82
115
|
activityId: 'session-1',
|
|
83
116
|
openUrl: 'widgetkitdemo://session/session-1',
|
|
84
117
|
state: {
|
|
@@ -93,7 +126,7 @@ const { activity } = await CapgoWidgetKit.startTemplateActivity({
|
|
|
93
126
|
{
|
|
94
127
|
id: 'next-frame',
|
|
95
128
|
eventName: 'widget.frame.changed',
|
|
96
|
-
frameMutations: [{ op: 'next', path: 'frame', surface: '
|
|
129
|
+
frameMutations: [{ op: 'next', path: 'frame', surface: 'homeScreen' }],
|
|
97
130
|
},
|
|
98
131
|
{
|
|
99
132
|
id: 'toggle-rest',
|
|
@@ -102,7 +135,7 @@ const { activity } = await CapgoWidgetKit.startTemplateActivity({
|
|
|
102
135
|
},
|
|
103
136
|
],
|
|
104
137
|
layouts: {
|
|
105
|
-
|
|
138
|
+
homeScreen: {
|
|
106
139
|
width: 100,
|
|
107
140
|
height: 40,
|
|
108
141
|
frameIdPath: 'state.frame',
|
|
@@ -173,12 +206,12 @@ await CapgoWidgetKit.stopWidgetSession({ widgetId: session.widgetId });
|
|
|
173
206
|
|
|
174
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:
|
|
175
208
|
|
|
176
|
-
- starting one SVG template
|
|
177
|
-
- resolving the
|
|
209
|
+
- starting one SVG template widget for the Home Screen surface
|
|
210
|
+
- resolving the Home Screen surface
|
|
178
211
|
- running an action from the app and from a hotspot overlay
|
|
179
|
-
- reading the stored
|
|
212
|
+
- reading the stored widget template back
|
|
180
213
|
- reading and acknowledging the event log
|
|
181
|
-
- ending the
|
|
214
|
+
- ending the stored template
|
|
182
215
|
|
|
183
216
|
The workout helper is only used there as an example template factory.
|
|
184
217
|
|
|
@@ -188,6 +221,7 @@ The workout helper is only used there as an example template factory.
|
|
|
188
221
|
|
|
189
222
|
* [`areActivitiesSupported()`](#areactivitiessupported)
|
|
190
223
|
* [`startTemplateActivity(...)`](#starttemplateactivity)
|
|
224
|
+
* [`startTemplateWidget(...)`](#starttemplatewidget)
|
|
191
225
|
* [`updateTemplateActivity(...)`](#updatetemplateactivity)
|
|
192
226
|
* [`endTemplateActivity(...)`](#endtemplateactivity)
|
|
193
227
|
* [`performTemplateAction(...)`](#performtemplateaction)
|
|
@@ -204,6 +238,7 @@ The workout helper is only used there as an example template factory.
|
|
|
204
238
|
* [`listWidgetMessages(...)`](#listwidgetmessages)
|
|
205
239
|
* [`acknowledgeWidgetMessages(...)`](#acknowledgewidgetmessages)
|
|
206
240
|
* [`completeWidgetMessage(...)`](#completewidgetmessage)
|
|
241
|
+
* [`reloadWidgets(...)`](#reloadwidgets)
|
|
207
242
|
* [`getPluginVersion()`](#getpluginversion)
|
|
208
243
|
* [Interfaces](#interfaces)
|
|
209
244
|
* [Type Aliases](#type-aliases)
|
|
@@ -215,14 +250,15 @@ The workout helper is only used there as an example template factory.
|
|
|
215
250
|
|
|
216
251
|
Capacitor bridge for an iOS-first WidgetKit / Live Activities plugin.
|
|
217
252
|
|
|
218
|
-
The core abstraction is a generic SVG template
|
|
253
|
+
The core abstraction is a generic SVG template record:
|
|
219
254
|
- raw SVG templates with binding placeholders
|
|
220
255
|
- declarative action patches
|
|
221
256
|
- timer bindings exposed to the template scope
|
|
222
257
|
- event logging so the host app can process button results later
|
|
223
258
|
|
|
224
259
|
The plugin owns shared persistence, declarative action execution, and event retrieval.
|
|
225
|
-
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.
|
|
226
262
|
|
|
227
263
|
Full-native widgets can use widget sessions for synchronous shared state and widget messages
|
|
228
264
|
for asynchronous app/widget jobs without adopting the SVG template renderer.
|
|
@@ -257,6 +293,23 @@ Persist a generic SVG template activity and start the matching native Live Activ
|
|
|
257
293
|
--------------------
|
|
258
294
|
|
|
259
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
|
+
|
|
260
313
|
### updateTemplateActivity(...)
|
|
261
314
|
|
|
262
315
|
```typescript
|
|
@@ -513,6 +566,21 @@ Complete or fail an async widget bridge message.
|
|
|
513
566
|
--------------------
|
|
514
567
|
|
|
515
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
|
+
|
|
516
584
|
### getPluginVersion()
|
|
517
585
|
|
|
518
586
|
```typescript
|
|
@@ -582,13 +650,14 @@ Generic SVG template definition stored by the plugin.
|
|
|
582
650
|
|
|
583
651
|
Bundle of optional WidgetKit surface layouts.
|
|
584
652
|
|
|
585
|
-
| Prop | Type | Description
|
|
586
|
-
| ---------------------------------- | --------------------------------------------------------------- |
|
|
587
|
-
| **`
|
|
588
|
-
| **`
|
|
589
|
-
| **`
|
|
590
|
-
| **`
|
|
591
|
-
| **`
|
|
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. |
|
|
592
661
|
|
|
593
662
|
|
|
594
663
|
#### SvgTemplateLayoutWithSvg
|
|
@@ -740,6 +809,22 @@ Persisted timer runtime state.
|
|
|
740
809
|
|
|
741
810
|
Options for starting a generic SVG template activity.
|
|
742
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
|
+
|
|
743
828
|
| Prop | Type | Description |
|
|
744
829
|
| ---------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
745
830
|
| **`activityId`** | <code>string</code> | Optional explicit activity identifier. When omitted, the native runtime creates one. |
|
|
@@ -1046,6 +1131,15 @@ Options for completing an async widget bridge message.
|
|
|
1046
1131
|
| **`error`** | <code>string</code> | Optional error string. When set, the message status becomes `failed`. |
|
|
1047
1132
|
|
|
1048
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
|
+
|
|
1049
1143
|
#### PluginVersionResult
|
|
1050
1144
|
|
|
1051
1145
|
Result payload for plugin version queries.
|
|
@@ -1090,7 +1184,7 @@ JSON-safe array used as activity state.
|
|
|
1090
1184
|
|
|
1091
1185
|
Named WidgetKit surface for one SVG layout variant.
|
|
1092
1186
|
|
|
1093
|
-
<code>'lockScreen' | 'dynamicIslandExpanded' | 'dynamicIslandCompactLeading' | 'dynamicIslandCompactTrailing' | 'dynamicIslandMinimal'</code>
|
|
1187
|
+
<code>'homeScreen' | 'lockScreen' | 'dynamicIslandExpanded' | 'dynamicIslandCompactLeading' | 'dynamicIslandCompactTrailing' | 'dynamicIslandMinimal'</code>
|
|
1094
1188
|
|
|
1095
1189
|
|
|
1096
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": []
|