tauri-plugin-live-activity 0.5.1 → 0.7.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/README.ko.md +201 -234
- package/README.md +196 -226
- package/dist-js/index.d.ts +54 -1
- package/dist-js/index.js +103 -0
- package/dist-js/jsx/index.d.ts +14 -1
- package/dist-js/jsx/index.js +22 -6
- package/dist-js/layout.d.ts +15 -4
- package/dist-js/layout.js +21 -4
- package/dist-js/react/index.d.ts +2 -1
- package/dist-js/react/index.js +26 -2
- package/dist-js/react/session.d.ts +18 -1
- package/dist-js/react/session.js +40 -10
- package/dist-js/types.d.ts +508 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
Show what your Tauri 2 app is doing on the iPhone Lock Screen and in the Dynamic Island, and as
|
|
9
|
-
an ongoing notification on Android. You describe the layout in TypeScript; the plugin draws it.
|
|
9
|
+
an ongoing notification on Android. You describe the layout in TSX, TypeScript or Rust; the plugin draws it.
|
|
10
10
|
[한국어](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/README.ko.md)
|
|
11
11
|
|
|
12
12
|
<table>
|
|
@@ -22,12 +22,23 @@ an ongoing notification on Android. You describe the layout in TypeScript; the p
|
|
|
22
22
|
</tr>
|
|
23
23
|
</table>
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
The demo running, recorded on the iPhone 17 Pro simulator and an Android 16 emulator:
|
|
26
|
+
|
|
27
|
+
<table>
|
|
28
|
+
<tr><th>iOS: a snack delivery and a nap timer on the Lock Screen</th><th>iOS: a bound style changes with an update</th><th>Android: the same request as a notification on the lock screen</th></tr>
|
|
29
|
+
<tr>
|
|
30
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-demo.gif" width="250" alt="The demo starts Mochi's snack delivery, the Lock Screen shows its card with a progress bar, then a nap timer counts down"></td>
|
|
31
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-styles.gif" width="250" alt="The demo sends new values and the Lock Screen card's status turns red and bold"></td>
|
|
32
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-snack.gif" width="250" alt="The demo starts Mochi's snack delivery; the phone is locked and its lock screen shows the notification, whose progress bar moves with each update; a swipe unlocks and the delivery ends"></td>
|
|
33
|
+
</tr>
|
|
34
|
+
</table>
|
|
35
|
+
|
|
36
|
+
All of them come from the [demo app](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/examples/demo),
|
|
37
|
+
which follows a cat named Mochi. iOS 16.2+ and Android 8+; on desktop the activity commands answer
|
|
38
|
+
`UNSUPPORTED_PLATFORM`. The plugin is an adapter of the [liveactivity](https://github.com/1eedaegon/liveactivity-rs)
|
|
39
|
+
crate, which runs iOS on [activitykit](https://github.com/1eedaegon/activitykit-rs) and Android on
|
|
40
|
+
[liveupdate](https://github.com/1eedaegon/liveupdate-rs): the plugin has no Swift of its own, and its Kotlin answers
|
|
41
|
+
the permission commands and carries liveupdate's Android adapter. Before 1.0, a minor version may change the API.
|
|
31
42
|
|
|
32
43
|
## Install
|
|
33
44
|
|
|
@@ -39,160 +50,195 @@ npm i tauri-plugin-live-activity
|
|
|
39
50
|
npx tauri-plugin-live-activity setup
|
|
40
51
|
```
|
|
41
52
|
|
|
42
|
-
Then
|
|
53
|
+
Then register the plugin in `src-tauri/src/lib.rs`:
|
|
43
54
|
|
|
44
55
|
```rust
|
|
45
56
|
.plugin(tauri_plugin_live_activity::init())
|
|
46
57
|
```
|
|
47
58
|
|
|
48
|
-
`setup` grants the plugin's permissions, raises the Android minimum to API 26 and, on a Mac,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
scratch. On an app that 0.3 set up, run it again: it moves the widget and your custom views to
|
|
52
|
-
activitykit. `--dry-run` shows what it would change.
|
|
59
|
+
`setup` grants the plugin's permissions, raises the Android minimum to API 26 and, on a Mac, adds the
|
|
60
|
+
widget extension that draws the activity to the Xcode project. Run it after `tauri ios init`, and again
|
|
61
|
+
whenever `src-tauri/gen/apple` is made from scratch. `--dry-run` shows what it would change.
|
|
53
62
|
|
|
54
|
-
##
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
import { getCapabilities, layout, requestPermissions, startLayout, updateLayout, endLayout } from 'tauri-plugin-live-activity';
|
|
63
|
+
## React and TSX
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const snack = await startLayout({
|
|
64
|
-
activityKey: 'mochi:snack',
|
|
65
|
-
schemaVersion: 2,
|
|
66
|
-
fallback: 'notification',
|
|
67
|
-
layout: { lockScreen: vstack([bound('title'), bound('status'), progress('done')]) },
|
|
68
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', done: 0.15 } },
|
|
69
|
-
});
|
|
70
|
-
await updateLayout({ id: snack.id, snapshot: { revision: 1, values: { title: 'Mochi’s snack', status: 'On the way', done: 0.65 } } });
|
|
71
|
-
await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
The layout stays as it started. Each update sends every value again, with a higher revision.
|
|
75
|
-
|
|
76
|
-
## Changing styles
|
|
77
|
-
|
|
78
|
-
The tree is fixed at start, but a few style members can name a value. An update then changes them:
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
const { bind } = layout;
|
|
82
|
-
// styles: { status: { color: bind('tone'), weight: bind('weight') } }, values: { tone: 'green', weight: 'regular', … }
|
|
83
|
-
await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 'red', weight: 'bold' } } });
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
```rust
|
|
87
|
-
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
88
|
-
// Later: every value again, with the new color.
|
|
89
|
-
values.insert("tone".into(), Value::Text("red".into()));
|
|
90
|
-
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None, timestamp: None } })?;
|
|
91
|
-
```
|
|
65
|
+
A layout is a tree of components from `tauri-plugin-live-activity/jsx`, a JSX import source of its own: the
|
|
66
|
+
file needs no React, and a server can build the same tree for a push payload. Keep it in a file of its own,
|
|
67
|
+
since this JSX has no HTML elements.
|
|
92
68
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
the
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="400" alt="A cat, a multicolor heart and a speaker filled to 35%">
|
|
111
|
-
|
|
112
|
-
```ts
|
|
113
|
-
hstack([
|
|
114
|
-
symbol('cat.fill'),
|
|
115
|
-
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
116
|
-
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
117
|
-
])
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
SF Symbols. `variableBind` fills a variable symbol from a value between 0 and 1. iOS only.
|
|
121
|
-
|
|
122
|
-
### Image
|
|
123
|
-
|
|
124
|
-
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="400" alt="Mochi's portrait from the widget's asset catalog">
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
128
|
-
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
69
|
+
```tsx
|
|
70
|
+
/** @jsxImportSource tauri-plugin-live-activity/jsx */
|
|
71
|
+
// delivery-layout.tsx
|
|
72
|
+
import { Button, HStack, Progress, SFSymbol, Text, VStack } from 'tauri-plugin-live-activity/jsx';
|
|
73
|
+
|
|
74
|
+
// iOS: the Lock Screen draws this tree as it is, and the expanded Dynamic Island shows it too
|
|
75
|
+
// (iOS 16.2+; the Button needs iOS 17).
|
|
76
|
+
// Android: the notification takes the first two Texts as title and body, the first Progress as its
|
|
77
|
+
// bar and up to three Buttons as actions; symbols and styles are left out.
|
|
78
|
+
export const lockScreen = (
|
|
79
|
+
<VStack alignment="leading" spacing={8}>
|
|
80
|
+
<HStack spacing={8}><SFSymbol name="cat.fill" /><Text bind="title" /></HStack>
|
|
81
|
+
<Text bind="status" />
|
|
82
|
+
<Progress bind="done" />
|
|
83
|
+
<Button actionId="done"><Text>All done</Text></Button>
|
|
84
|
+
</VStack>
|
|
85
|
+
);
|
|
129
86
|
```
|
|
130
87
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="400" alt="A circular and a linear gauge at 80 of 100">
|
|
88
|
+
`tauri-plugin-live-activity/react` keeps one activity in step with a component (React 18+, an optional
|
|
89
|
+
peer dependency). It starts on mount, sends the values as an update whenever a render changes them, and
|
|
90
|
+
ends on unmount or `enabled: false`:
|
|
136
91
|
|
|
137
|
-
```
|
|
138
|
-
|
|
92
|
+
```tsx
|
|
93
|
+
// Delivery.tsx
|
|
94
|
+
import { getCapabilities, requestPermissions } from 'tauri-plugin-live-activity';
|
|
95
|
+
import { useLiveActivity } from 'tauri-plugin-live-activity/react';
|
|
96
|
+
import { lockScreen } from './delivery-layout';
|
|
97
|
+
|
|
98
|
+
// Once, before the first start: 'notifications' on Android, 'liveActivities' on iOS.
|
|
99
|
+
export async function allowActivities() {
|
|
100
|
+
const { platform } = await getCapabilities();
|
|
101
|
+
await requestPermissions(platform === 'android' ? 'notifications' : 'liveActivities');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function Delivery({ order }: { order: Order }) {
|
|
105
|
+
const { status, error, pushToken } = useLiveActivity({
|
|
106
|
+
activityKey: `delivery:${order.id}`,
|
|
107
|
+
layout: { lockScreen },
|
|
108
|
+
values: { title: order.title, status: order.status, done: order.done },
|
|
109
|
+
enabled: order.open,
|
|
110
|
+
// Android only: who sees the notification on the lock screen ('public', 'private' or 'secret').
|
|
111
|
+
android: { visibility: 'public' },
|
|
112
|
+
// iOS only: ask ActivityKit for the activity's APNs token; it lands in `pushToken`.
|
|
113
|
+
push: 'token',
|
|
114
|
+
// A tap on a Button of this activity, also when the tap launched the app.
|
|
115
|
+
onAction: ({ actionId }) => { if (actionId === 'done') closeOrder(order.id); },
|
|
116
|
+
});
|
|
117
|
+
// pushToken: the activity's APNs token on iOS, for your server.
|
|
118
|
+
return <p>{status}{error ? ` (${error.message})` : ''}</p>;
|
|
119
|
+
}
|
|
139
120
|
```
|
|
140
121
|
|
|
141
|
-
|
|
122
|
+
`layout` and `styles` are read at start: change the `activityKey` to start a new activity. A refused request
|
|
123
|
+
lands in `error`. One component per node: `VStack`, `HStack`, `ZStack`, `Spacer`, `Divider`, `Text`,
|
|
124
|
+
`SFSymbol`, `Image`, `Path`, `Progress`, `Gauge`, `TimerText`, `Button`, `Link`, `Toggle`, `Custom`, with the node's members as
|
|
125
|
+
props. [More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#tsx-and-react)
|
|
142
126
|
|
|
143
|
-
|
|
127
|
+
## Rust
|
|
144
128
|
|
|
145
|
-
|
|
129
|
+
The same requests from Rust, through `app.live_activity()`. The methods block until the platform answers, so
|
|
130
|
+
call them off the main thread (on iOS a call on the main thread answers `NATIVE_ERROR` at once):
|
|
146
131
|
|
|
147
|
-
```
|
|
148
|
-
|
|
132
|
+
```rust
|
|
133
|
+
use std::collections::BTreeMap;
|
|
134
|
+
use tauri::{AppHandle, Runtime};
|
|
135
|
+
use tauri_plugin_live_activity::{
|
|
136
|
+
Element, EndPolicy, Fallback, Layout, LayoutEndInput, LayoutSnapshot, LayoutStartInput,
|
|
137
|
+
LayoutUpdateInput, LiveActivityExt, Result, Value,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
fn snapshot(revision: u64, status: &str) -> LayoutSnapshot {
|
|
141
|
+
let values = BTreeMap::from([("status".to_string(), Value::Text(status.into()))]);
|
|
142
|
+
LayoutSnapshot::new(revision, values)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fn deliver<R: Runtime>(app: &AppHandle<R>) -> Result<()> {
|
|
146
|
+
let input = LayoutStartInput {
|
|
147
|
+
activity_key: "mochi:snack".into(),
|
|
148
|
+
schema_version: 2,
|
|
149
|
+
// Android, and iOS without Live Activities: shown as a notification.
|
|
150
|
+
fallback: Fallback::Notification,
|
|
151
|
+
layout: Layout {
|
|
152
|
+
lock_screen: Element::Text { value: None, bind: Some("status".into()) }.into(),
|
|
153
|
+
island: None, background: None, keyline: None, url: None,
|
|
154
|
+
},
|
|
155
|
+
styles: None,
|
|
156
|
+
snapshot: snapshot(0, "On time"),
|
|
157
|
+
android: None, // Android only: `AndroidOptions::new(visibility)` for the lock screen
|
|
158
|
+
ios: None, // iOS only: `IosOptions::new(transient)` for a transient activity (iOS 18)
|
|
159
|
+
scheduled: None, // iOS 26: `ScheduledStart::new(at, alert)` starts it later
|
|
160
|
+
push: None, // iOS only: `Some(LayoutPush::Token)` asks for the activity's APNs token
|
|
161
|
+
};
|
|
162
|
+
let activity = app.live_activity().start_layout(input)?;
|
|
163
|
+
// Every update sends all values again, with a higher revision.
|
|
164
|
+
app.live_activity().update_layout(LayoutUpdateInput::new(activity.id.clone(), snapshot(1, "At the door")))?;
|
|
165
|
+
app.live_activity().end_layout(LayoutEndInput { id: activity.id, policy: EndPolicy::Immediate {}, snapshot: None })?;
|
|
166
|
+
Ok(())
|
|
167
|
+
}
|
|
149
168
|
```
|
|
150
169
|
|
|
151
|
-
A
|
|
152
|
-
|
|
153
|
-
### Timer
|
|
154
|
-
|
|
155
|
-
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="400" alt="A countdown at 4:50 under Mochi's nap">
|
|
170
|
+
A tap that must not be lost belongs in Rust: the system can launch the app for it with no web view yet, and
|
|
171
|
+
JavaScript listeners are not awaited. Register the handler on the built `App` before `run`:
|
|
156
172
|
|
|
157
|
-
```
|
|
158
|
-
|
|
173
|
+
```rust
|
|
174
|
+
let handle = app.handle().clone();
|
|
175
|
+
app.live_activity().on_action(move |event| {
|
|
176
|
+
if event.action_id == "done" {
|
|
177
|
+
let input = LayoutEndInput { id: event.activity_id, policy: EndPolicy::Immediate {}, snapshot: None };
|
|
178
|
+
let _ = handle.live_activity().end_layout(input);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
159
181
|
```
|
|
160
182
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### Buttons
|
|
183
|
+
## Plain TypeScript
|
|
164
184
|
|
|
165
|
-
|
|
185
|
+
Without React, the three commands and the `layout` builders do the same:
|
|
166
186
|
|
|
167
187
|
```ts
|
|
168
|
-
|
|
188
|
+
import { endLayout, layout, startLayout, updateLayout } from 'tauri-plugin-live-activity';
|
|
169
189
|
|
|
170
|
-
|
|
171
|
-
|
|
190
|
+
const { vstack, bound, progress } = layout;
|
|
191
|
+
const snack = await startLayout({
|
|
192
|
+
activityKey: 'mochi:snack',
|
|
193
|
+
schemaVersion: 2,
|
|
194
|
+
fallback: 'notification',
|
|
195
|
+
layout: { lockScreen: vstack([bound('title'), bound('status'), progress('done')]) },
|
|
196
|
+
snapshot: { revision: 0, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', done: 0.15 } },
|
|
172
197
|
});
|
|
198
|
+
await updateLayout({ id: snack.id, snapshot: { revision: 1, values: { title: 'Mochi’s snack', status: 'On the way', done: 0.65 } } });
|
|
199
|
+
await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
173
200
|
```
|
|
174
201
|
|
|
175
|
-
A
|
|
202
|
+
A start may also carry `scheduled: { at, alert }` to begin later (iOS 26), and `ios: { transient: true }` for a transient
|
|
203
|
+
activity (iOS 18). The layout stays as it started; each update sends every value again, with a higher revision. Taps come to
|
|
204
|
+
`onAction`, push tokens and pushed content to `onPushToken`, `onPushToStartToken` and `onUpdated`, and what happens
|
|
205
|
+
to an activity outside the app's calls to `onState`, `onStarted`, `onOpened` (Android: the person opened the app from an
|
|
206
|
+
activity's notification) and `onPermissions`.
|
|
176
207
|
|
|
177
|
-
|
|
208
|
+
A snapshot may also carry a `relevance`, which decides which of the app's activities the Dynamic Island shows, and
|
|
209
|
+
an `android` content, the notification in Android's own terms (a segmented progress, metrics, the chip text) in
|
|
210
|
+
place of the projection of the layout; `updateLayout` takes an `alert`, which lights up the iPhone.
|
|
211
|
+
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#android-content)
|
|
178
212
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
213
|
+
## What a layout can hold
|
|
214
|
+
|
|
215
|
+
| Node | Shows | iOS | Android |
|
|
216
|
+
|---|---|---|---|
|
|
217
|
+
| `text`, `bound` | a string, or the value of a key | yes | the first two become title and body |
|
|
218
|
+
| `symbol` | an SF Symbol; `variableBind` fills a variable symbol from 0 to 1 | yes | no |
|
|
219
|
+
| `image` | a picture from the widget's asset catalog, or a PNG the app wrote | yes | the first drawn image is the large icon |
|
|
220
|
+
| `path` | SVG path data | yes | no |
|
|
221
|
+
| `gauge` | a number between `min` and `max`, as a ring or a bar | yes | no |
|
|
222
|
+
| `progress` | a number from 0 to 1, as a ring or a bar | yes | the first one is the notification's bar |
|
|
223
|
+
| `timerText` | a count down to `end` or up from `start`, kept by the system | yes | the chronometer |
|
|
224
|
+
| `button` | a tap for `onAction` / `on_action` | iOS 17+ | up to three actions |
|
|
225
|
+
| `link` | a tap that opens its URL in the app | iOS | an action that opens the URL (where the device offers `links`) |
|
|
226
|
+
| `toggle` | a switch of a boolean value; a tap comes as `on` | iOS 17+ | an action titled by its label, with a check mark while on |
|
|
227
|
+
| `vstack`, `hstack`, `zstack`, `spacer`, `divider` | arrangement | yes | flattened |
|
|
228
|
+
| `custom` | a SwiftUI view of your own, by name | yes | no |
|
|
229
|
+
|
|
230
|
+
Styles name a font, color, weight, frame and more by token (`styles: { title: { size: 22 } }`,
|
|
231
|
+
`bound('title', { style: 'title' })`); `color`, `background`, `tint`, `opacity`, `size`, `weight`,
|
|
232
|
+
`cornerRadius` and the layout's `background` and `keyline` may be bound to a value (`color: bind('tone')`)
|
|
233
|
+
and then change with an update. Android draws no styles. Layout, styles and values share a weight limit of 3584.
|
|
234
|
+
`degradedFeatures` in the record names what a platform left out.
|
|
235
|
+
|
|
236
|
+
The Dynamic Island takes its own parts next to `lockScreen`; a part left out shows the lock screen tree
|
|
237
|
+
(expanded) or its first symbol (compact leading, minimal):
|
|
187
238
|
|
|
188
239
|
```ts
|
|
189
240
|
island: {
|
|
190
|
-
expanded: {
|
|
191
|
-
leading: image('mochi', { resizable: true, style: 'portrait' }),
|
|
192
|
-
center: bound('title'),
|
|
193
|
-
trailing: bound('eta'),
|
|
194
|
-
bottom: vstack([bound('status'), progress('done')]),
|
|
195
|
-
},
|
|
241
|
+
expanded: { leading: image('mochi'), center: bound('title'), trailing: bound('eta'), bottom: progress('done') },
|
|
196
242
|
compactLeading: symbol('pawprint.fill'),
|
|
197
243
|
compactTrailing: bound('eta'),
|
|
198
244
|
minimal: progress('done', { kind: 'circular' }),
|
|
@@ -200,96 +246,22 @@ island: {
|
|
|
200
246
|
keyline: '#A3D9C2', // the island's edge color
|
|
201
247
|
```
|
|
202
248
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
Android shows a layout as a notification: the first two texts as title and body, the first progress bar and timer, and up to three buttons. `degradedFeatures` names what it left out.
|
|
206
|
-
|
|
207
|
-
## TSX and React
|
|
208
|
-
|
|
209
|
-
The same layouts can be written in TSX. `tauri-plugin-live-activity/jsx` is a JSX import source of its own, so a
|
|
210
|
-
`.tsx` file needs no React: set `"jsx": "react-jsx"` and `"jsxImportSource": "tauri-plugin-live-activity/jsx"` in
|
|
211
|
-
`tsconfig.json`, or `/** @jsxImportSource tauri-plugin-live-activity/jsx */` at the top of the file.
|
|
249
|
+
## Pushes (iOS)
|
|
212
250
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
<HStack spacing={8}><SFSymbol name="cat.fill" /><Text bind="title" /></HStack>
|
|
219
|
-
<Text bind="status" />
|
|
220
|
-
<Button actionId="pet"><Text>Pet Mochi</Text></Button>
|
|
221
|
-
</VStack>
|
|
222
|
-
);
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
One component per node (`VStack`, `HStack`, `ZStack`, `Spacer`, `Divider`, `Text`, `SFSymbol`, `Image`, `Path`,
|
|
226
|
-
`Progress`, `Gauge`, `TimerText`, `Button`, `Custom`), with the node's members as props. `Text` shows its
|
|
227
|
-
children or, with `bind`, a value; a stack takes nodes, arrays and `{late && <Text>Late</Text>}`; a `Button`
|
|
228
|
-
holds one node. There are no HTML elements and no fragments. The entry imports neither Tauri nor React, so a
|
|
229
|
-
server can build the same layout for a push payload.
|
|
230
|
-
|
|
231
|
-
`tauri-plugin-live-activity/react` keeps one activity in step with a component (React 18+, an optional peer
|
|
232
|
-
dependency):
|
|
233
|
-
|
|
234
|
-
```tsx
|
|
235
|
-
import { useLiveActivity } from 'tauri-plugin-live-activity/react';
|
|
236
|
-
|
|
237
|
-
const { status, record, error } = useLiveActivity({
|
|
238
|
-
activityKey: `delivery:${order.id}`,
|
|
239
|
-
layout: { lockScreen },
|
|
240
|
-
values: { title: order.title, status: order.status },
|
|
241
|
-
enabled: order.open,
|
|
242
|
-
onAction: ({ actionId }) => { if (actionId === 'done') closeOrder(order.id); },
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
The activity starts on mount, each render with other `values` sends one update at the next revision (one request
|
|
247
|
-
in flight at a time, the newest values last), and it ends on unmount or `enabled: false`. `layout` and `styles` are
|
|
248
|
-
read at start; change the `activityKey` to start a new activity. A refused request lands in `error`, and `onAction`
|
|
249
|
-
gets this activity's taps. [More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#tsx-and-react)
|
|
251
|
+
A server updates, ends or starts activities through APNs. Start with `push: 'token'` (or `{ channel }` on iOS 18)
|
|
252
|
+
and the activity's token comes to `onPushToken`; the app's push-to-start token (iOS 17.2, `pushToStart` in the
|
|
253
|
+
plugin configuration) to `onPushToStartToken`; content a push delivered to `onUpdated`. Tokens the plugin already
|
|
254
|
+
holds when a page subscribes come at once. The server builds the payloads with activitykit's `push::Payload`.
|
|
255
|
+
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#pushes)
|
|
250
256
|
|
|
251
257
|
## Beyond the built-in parts
|
|
252
258
|
|
|
253
|
-
Most customizing needs no Swift.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
styles: { title: { fontFamily: 'Pacifico-Regular', size: 22 } }, // setup prints the names a font answers to
|
|
261
|
-
lockScreen: hstack([image('paw'), bound('title', { style: 'title' })]),
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Pictures the app draws, on a canvas or in Rust, go through an App Group (`setup --app-group`). Write the PNG,
|
|
265
|
-
then start or update, and the widget draws it:
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
await writeImage('badge.png', png); // Rust: app.live_activity().write_image("badge.png", &png)
|
|
269
|
-
lockScreen: image({ file: 'badge.png' }, { resizable: true }),
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
For a view of your own, write it in SwiftUI in `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`, which
|
|
273
|
-
`setup` creates once and never overwrites, and place it with `custom`:
|
|
274
|
-
|
|
275
|
-
```ts
|
|
276
|
-
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
```swift
|
|
280
|
-
"ring": ActivityKitCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
A name without a view draws nothing and is reported in `degradedFeatures` as `layout.custom.ring`. The last
|
|
284
|
-
resort is to edit the copied `LiveActivityWidget.swift`, activitykit's widget template; `setup` then keeps your copy,
|
|
285
|
-
and template updates are yours to merge.
|
|
286
|
-
|
|
287
|
-
Limits: a Live Activity has no network and little memory. A drawn PNG is at most 1 MiB and 1224 × 480 pixels,
|
|
288
|
-
Apple's largest Lock Screen presentation at @3x. Fonts must be in the extension. On a device the App Group is
|
|
289
|
-
registered with your Apple account once; automatic signing does that. The validators check a custom view's name
|
|
290
|
-
and props, not the view. Android draws none of these, except that the first drawn image becomes the
|
|
291
|
-
notification's large icon. Layout, styles and values still share 3584.
|
|
292
|
-
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
259
|
+
Most customizing needs no Swift. `setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png` bundles fonts
|
|
260
|
+
and pictures in the widget extension, to be named in styles and `image('paw')`. Pictures the app draws go
|
|
261
|
+
through an App Group (`setup --app-group`): `writeImage('badge.png', png)`, then `image({ file: 'badge.png' })`.
|
|
262
|
+
A view of your own is SwiftUI in `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`, which `setup`
|
|
263
|
+
creates once and never overwrites, placed with `custom('ring', { props: { level: bind('done') } })`. A drawn PNG is
|
|
264
|
+
at most 1 MiB and 1224 × 480 pixels. [More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
293
265
|
|
|
294
266
|
## Limits
|
|
295
267
|
|
|
@@ -297,24 +269,22 @@ notification's large icon. Layout, styles and values still share 3584.
|
|
|
297
269
|
app is in the foreground (`NOT_FOREGROUND` otherwise), and the system ends it after 8 hours.
|
|
298
270
|
- iOS keeps each activity's last values in plain text in the app's Application Support, unless the plugin
|
|
299
271
|
configuration sets `"receipts": "redacted"`.
|
|
300
|
-
- A button's tap waits for
|
|
301
|
-
-
|
|
302
|
-
|
|
303
|
-
|
|
272
|
+
- A button's tap waits for the Rust `on_action` handlers, at most 4 seconds; JavaScript listeners are not awaited.
|
|
273
|
+
- Pushes are iOS only. Android shows an ongoing notification, promoted to a Live Update where the system allows it.
|
|
274
|
+
- Android 16 shows nothing of a notification whose time is more than two weeks past, and the app is told nothing. This
|
|
275
|
+
is a timer whose start or end lies that far before the post.
|
|
276
|
+
- Keep the npm package and the crate on the same minor version.
|
|
304
277
|
|
|
305
278
|
## Samsung Now Bar
|
|
306
279
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
"Live notifications for all apps" is on, and the plugin cannot add an app to that list.
|
|
280
|
+
`"plugins": { "live-activity": { "android": { "samsungNowBar": true } } }` in `tauri.conf.json` sends One UI 9
|
|
281
|
+
the title and body its Now Bar shows. One UI shows the Now Bar only for apps on Samsung's allow list, or for every
|
|
282
|
+
app while the developer option "Live notifications for all apps" is on.
|
|
311
283
|
|
|
312
284
|
## More
|
|
313
285
|
|
|
314
|
-
The [docs](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/docs) cover the
|
|
315
|
-
|
|
316
|
-
captures, buttons handled in Rust, the progress and timer templates, the plugin options and
|
|
317
|
-
the test records.
|
|
286
|
+
The [docs](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/docs) cover the rest: what `setup`
|
|
287
|
+
changes and how to do it by hand, every node with iOS and Android captures, the plugin options and the test records.
|
|
318
288
|
|
|
319
289
|
## License
|
|
320
290
|
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type UnlistenFn } from '@tauri-apps/api/event';
|
|
2
|
-
import type { ActionEvent, ActivityRecord, Capabilities, EndInput, LayoutActivityRecord, LayoutEndInput, LayoutStartInput, LayoutUpdateInput, PermissionKind, Permissions, StartInput, UpdateInput } from './types.js';
|
|
2
|
+
import type { ActionEvent, ActivityRecord, Capabilities, EndInput, LayoutActivityRecord, LayoutEndInput, LayoutStartInput, LayoutUpdateInput, OpenedEvent, PermissionKind, Permissions, PushToStartTokenEvent, PushTokenEvent, PushTokens, StartInput, StartedEvent, StateEvent, UpdateInput, UpdatedEvent } from './types.js';
|
|
3
3
|
export type * from './types.js';
|
|
4
4
|
/** Builders for the nodes of a layout tree. */
|
|
5
5
|
export * as layout from './layout.js';
|
|
@@ -42,3 +42,56 @@ export declare function writeImage(name: string, png: Uint8Array | ArrayBuffer):
|
|
|
42
42
|
* must not be lost.
|
|
43
43
|
*/
|
|
44
44
|
export declare function onAction(handler: (event: ActionEvent) => void): Promise<UnlistenFn>;
|
|
45
|
+
/**
|
|
46
|
+
* The push tokens the plugin holds since launch (iOS): the newest token of each of the last 32 activities that got
|
|
47
|
+
* one, and the app's push-to-start token. The events report each token as it comes, but an event reaches only the
|
|
48
|
+
* listeners there are when it goes out, and a token may come before the page listens, at launch above all:
|
|
49
|
+
* `onPushToken` and `onPushToStartToken` read this right after subscribing. Empty where there are no pushes. The
|
|
50
|
+
* read is in the plugin's `default` permission.
|
|
51
|
+
*/
|
|
52
|
+
export declare function pushTokens(): Promise<PushTokens>;
|
|
53
|
+
/**
|
|
54
|
+
* Receive the push token of each activity that asked for one (`push: 'token'`), when ActivityKit gives it and each
|
|
55
|
+
* time it changes (iOS), and first those the plugin already holds, each token once. Send it to the server, which
|
|
56
|
+
* pushes to it with activitykit's `push::Payload`. Rejects, subscribed to nothing, when the plugin cannot be asked
|
|
57
|
+
* for the tokens it holds.
|
|
58
|
+
*/
|
|
59
|
+
export declare function onPushToken(handler: (event: PushTokenEvent) => void): Promise<UnlistenFn>;
|
|
60
|
+
/**
|
|
61
|
+
* Receive the app's push-to-start token, with `pushToStart: true` in the plugin configuration (iOS 17.2), when the
|
|
62
|
+
* system gives it and each time it changes, and first the one the plugin already holds, each token once. The server
|
|
63
|
+
* starts activities with it. Rejects, subscribed to nothing, when the plugin cannot be asked for the token it holds.
|
|
64
|
+
*/
|
|
65
|
+
export declare function onPushToStartToken(handler: (event: PushToStartTokenEvent) => void): Promise<UnlistenFn>;
|
|
66
|
+
/**
|
|
67
|
+
* Receive the record of an activity whose content a push changed (iOS): content above every revision this app sent
|
|
68
|
+
* or accepted, so the app's own updates do not come this way. Content pushed before the page listened is in the
|
|
69
|
+
* activity's record, as `listLayout` gives it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function onUpdated(handler: (event: UpdatedEvent) => void): Promise<UnlistenFn>;
|
|
72
|
+
/**
|
|
73
|
+
* Receive the record of a layout activity that began while the app ran (iOS): one the app started, or one a push
|
|
74
|
+
* started with the app's push-to-start token. An activity that began before the page listened is in `listLayout`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function onStarted(handler: (event: StartedEvent) => void): Promise<UnlistenFn>;
|
|
77
|
+
/**
|
|
78
|
+
* Receive each new lifecycle state of an activity, of a template or a layout. iOS reports the changes ActivityKit
|
|
79
|
+
* tells of while the app runs. Android reports where an activity stands when the plugin looks, each state once:
|
|
80
|
+
* `active` once Android shows the notification, `stale` after the snapshot's `staleAt`, `ended` and `dismissed`.
|
|
81
|
+
* The plugin looks with every start, update, end and list, when Android stores a tap or a dismissal, and at the
|
|
82
|
+
* stale time of an activity while the app runs. A state that came while the app did not run is reported when it
|
|
83
|
+
* starts. An activity is over at `ended` and at `dismissed`: an end that removes an activity at once may be reported
|
|
84
|
+
* as `dismissed` alone.
|
|
85
|
+
*/
|
|
86
|
+
export declare function onState(handler: (event: StateEvent) => void): Promise<UnlistenFn>;
|
|
87
|
+
/**
|
|
88
|
+
* Receive each opening of the app from the notification of an activity (Android): which activity the person
|
|
89
|
+
* opened it from, and by which action when it was one that opens a URL. The URL itself comes to the app as any deep
|
|
90
|
+
* link. iOS hands the URL to the app and reports nothing here.
|
|
91
|
+
*/
|
|
92
|
+
export declare function onOpened(handler: (event: OpenedEvent) => void): Promise<UnlistenFn>;
|
|
93
|
+
/**
|
|
94
|
+
* Receive the permissions after the person changed them in Settings (iOS): Live Activities turned on or off, or
|
|
95
|
+
* frequent pushes. `checkPermissions` gives them at any time.
|
|
96
|
+
*/
|
|
97
|
+
export declare function onPermissions(handler: (permissions: Permissions) => void): Promise<UnlistenFn>;
|