tauri-plugin-live-activity 0.2.0 → 0.3.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 +127 -449
- package/README.md +127 -453
- package/cli/bin.mjs +4 -0
- package/cli/ios.mjs +186 -0
- package/cli/main.mjs +69 -0
- package/cli/plist.mjs +83 -0
- package/cli/report.mjs +26 -0
- package/cli/setup.mjs +142 -0
- package/cli/steps.mjs +82 -0
- package/cli/widget-files.mjs +148 -0
- package/cli/xcodegen.mjs +187 -0
- package/dist-js/index.d.ts +8 -0
- package/dist-js/index.js +11 -0
- package/dist-js/layout.d.ts +14 -3
- package/dist-js/layout.js +18 -3
- package/dist-js/types.d.ts +67 -16
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -5,19 +5,12 @@
|
|
|
5
5
|
[](https://github.com/1eedaegon/tauri-plugin-live-activity/actions/workflows/ci.yml)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| Platform | Backend |
|
|
12
|
-
| --- | --- |
|
|
13
|
-
| iOS 16.1+ / iPadOS 17+ | ActivityKit · Lock Screen and Dynamic Island where available |
|
|
14
|
-
| Android API 26+ | Ongoing notifications · Live Update promotion on eligible API 36+ devices |
|
|
15
|
-
| macOS / Windows / Linux | Not implemented |
|
|
16
|
-
|
|
17
|
-
## Demo
|
|
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.
|
|
10
|
+
[한국어](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/README.ko.md)
|
|
18
11
|
|
|
19
12
|
<table>
|
|
20
|
-
<tr><th>iOS Lock Screen</th><th>
|
|
13
|
+
<tr><th>iOS Lock Screen</th><th>Dynamic Island</th></tr>
|
|
21
14
|
<tr>
|
|
22
15
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-paths.png" width="400" alt="Mochi's face drawn from SVG paths on the iOS Lock Screen"></td>
|
|
23
16
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="400" alt="Mochi's snack in the expanded Dynamic Island"></td>
|
|
@@ -29,557 +22,238 @@ Community plugin. **Before 1.0, a minor version may change the API.** [한국어
|
|
|
29
22
|
</tr>
|
|
30
23
|
</table>
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
which follows a cat named Mochi.
|
|
34
|
-
|
|
25
|
+
All four come from the [demo app](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/examples/demo),
|
|
26
|
+
which follows a cat named Mochi. The plugin runs on iOS 16.1+ and Android 8+; on desktop, its
|
|
27
|
+
activity commands return `UNSUPPORTED_PLATFORM`. Before 1.0, a minor version may change the API.
|
|
35
28
|
|
|
36
29
|
## Install
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
and the crate must have the same minor version.
|
|
31
|
+
In the folder of your Tauri 2 app:
|
|
40
32
|
|
|
41
33
|
```sh
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
cargo add tauri-plugin-live-activity --manifest-path src-tauri/Cargo.toml
|
|
35
|
+
npm i tauri-plugin-live-activity
|
|
36
|
+
npx tauri-plugin-live-activity setup
|
|
44
37
|
```
|
|
45
38
|
|
|
46
|
-
Then
|
|
39
|
+
Then add one line to the builder in `src-tauri/src/lib.rs`:
|
|
47
40
|
|
|
48
41
|
```rust
|
|
49
|
-
|
|
50
|
-
.plugin(tauri_plugin_live_activity::init())
|
|
42
|
+
.plugin(tauri_plugin_live_activity::init())
|
|
51
43
|
```
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
1. find the plugin's folder (`jq` comes with macOS 15 and later);
|
|
59
|
-
2. copy the widget, the button intent and the extension's Info.plist, which sets
|
|
60
|
-
`TauriLiveActivityLayout` to 2;
|
|
61
|
-
3. add `NSSupportsLiveActivities` to `src-tauri/Info.ios.plist`, which Tauri merges into the
|
|
62
|
-
app's Info.plist;
|
|
63
|
-
4. prepare the Tauri dependency of the plugin's Swift package. On an Apple silicon Mac, use
|
|
64
|
-
`--target aarch64-apple-ios-sim`.
|
|
65
|
-
|
|
66
|
-
```sh
|
|
67
|
-
LA=$(cargo metadata --format-version 1 --manifest-path src-tauri/Cargo.toml | jq -r '.packages[] | select(.name == "tauri-plugin-live-activity") | .manifest_path | rtrimstr("Cargo.toml")')
|
|
68
|
-
mkdir -p src-tauri/gen/apple/LiveActivityWidget && cp "$LA"templates/ios/* src-tauri/gen/apple/LiveActivityWidget/
|
|
69
|
-
/usr/libexec/PlistBuddy -c 'Add :NSSupportsLiveActivities bool true' src-tauri/Info.ios.plist
|
|
70
|
-
IPHONEOS_DEPLOYMENT_TARGET=16.1 cargo check --manifest-path src-tauri/Cargo.toml --target x86_64-apple-ios
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Tauri builds the Xcode project with XcodeGen, and a new target is a block of XcodeGen YAML, so
|
|
74
|
-
this step does not fit on one line. Paste the block, then the line after it:
|
|
75
|
-
|
|
76
|
-
```sh
|
|
77
|
-
cat > src-tauri/gen/apple/live-activity.yml <<EOF
|
|
78
|
-
packages:
|
|
79
|
-
LiveActivity: { path: "${LA}ios" }
|
|
80
|
-
targets:
|
|
81
|
-
$(sed -n 's/^name: //p' src-tauri/gen/apple/project.yml)_iOS:
|
|
82
|
-
sources: [LiveActivityWidget/LiveActivityActionIntent.swift]
|
|
83
|
-
dependencies: [{ target: LiveActivityWidget }]
|
|
84
|
-
settings: { base: { SWIFT_VERSION: "5.0" } }
|
|
85
|
-
LiveActivityWidget:
|
|
86
|
-
type: app-extension
|
|
87
|
-
platform: iOS
|
|
88
|
-
deploymentTarget: "16.1"
|
|
89
|
-
sources: [LiveActivityWidget]
|
|
90
|
-
dependencies: [{ package: LiveActivity, product: LiveActivityShared }, { package: LiveActivity, product: LiveActivityUI }]
|
|
91
|
-
info: { path: LiveActivityWidget/Info.plist, properties: { NSExtension: { NSExtensionPointIdentifier: com.apple.widgetkit-extension }, TauriLiveActivityLayout: 2 } }
|
|
92
|
-
settings: { base: { PRODUCT_BUNDLE_IDENTIFIER: $(jq -r .identifier src-tauri/tauri.conf.json).widget, SWIFT_VERSION: "5.0" } }
|
|
93
|
-
EOF
|
|
94
|
-
printf '\ninclude: [live-activity.yml]\n' >> src-tauri/gen/apple/project.yml && xcodegen generate --spec src-tauri/gen/apple/project.yml
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
The intent file goes into both targets: the widget builds its buttons from it, and the system
|
|
98
|
-
runs it in the app. `tauri ios init` writes `project.yml` again; run the last line after it.
|
|
99
|
-
The extension gets version 1.0 (1); give it the app's version before an App Store upload.
|
|
100
|
-
|
|
101
|
-
### Android
|
|
102
|
-
|
|
103
|
-
The plugin's manifest adds the notification permissions and its receivers. Builds need Android
|
|
104
|
-
SDK 37. The minimum is Android 8 (API 26); a new Tauri app starts at 24. The first line sets it
|
|
105
|
-
for `tauri android init`, the second for a project generated before:
|
|
106
|
-
|
|
107
|
-
```sh
|
|
108
|
-
node -e 'f="src-tauri/tauri.conf.json";c=require("./"+f);(c.bundle.android??={}).minSdkVersion=26;require("fs").writeFileSync(f,JSON.stringify(c,null,2)+"\n")'
|
|
109
|
-
perl -pi -e 's/minSdk = 2[0-5]$/minSdk = 26/' src-tauri/gen/android/app/build.gradle.kts
|
|
110
|
-
```
|
|
45
|
+
`setup` grants the plugin's permissions, raises the Android minimum to API 26 and, on a Mac,
|
|
46
|
+
adds the widget extension that draws the activity to the Xcode project. Run it after
|
|
47
|
+
`tauri ios init`, and again if `src-tauri/gen/apple` is ever made from scratch. `--dry-run`
|
|
48
|
+
shows what it would change.
|
|
111
49
|
|
|
112
|
-
##
|
|
113
|
-
|
|
114
|
-
The plugin shows state that the app sends. The app still owns the task, background work and
|
|
115
|
-
how often it updates. OS permissions, Focus and promotion rules decide where the activity
|
|
116
|
-
appears. `fallback: 'none'` rejects an unavailable native backend; it cannot force Android to
|
|
117
|
-
promote a notification.
|
|
118
|
-
|
|
119
|
-
Captures: iOS 26.3 on the iPhone 17 simulator, Android 16 on an emulator. The demo adds
|
|
120
|
-
Mochi's colors and padding to the code shown here.
|
|
121
|
-
|
|
122
|
-
### Progress
|
|
50
|
+
## Use
|
|
123
51
|
|
|
124
52
|
```ts
|
|
125
|
-
import { getCapabilities, requestPermissions,
|
|
53
|
+
import { getCapabilities, layout, requestPermissions, startLayout, updateLayout, endLayout } from 'tauri-plugin-live-activity';
|
|
126
54
|
|
|
55
|
+
const { vstack, bound, progress } = layout;
|
|
127
56
|
const { platform } = await getCapabilities();
|
|
128
57
|
await requestPermissions(platform === 'android' ? 'notifications' : 'liveActivities');
|
|
129
58
|
|
|
130
|
-
const snack = await
|
|
59
|
+
const snack = await startLayout({
|
|
131
60
|
activityKey: 'mochi:snack',
|
|
132
|
-
schemaVersion:
|
|
133
|
-
template: 'progress',
|
|
61
|
+
schemaVersion: 2,
|
|
134
62
|
fallback: 'notification',
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
await update({
|
|
138
|
-
id: snack.id,
|
|
139
|
-
snapshot: { revision: 1, title: 'Mochi’s snack delivery', status: 'On the way to Mochi', progress: 0.65 },
|
|
63
|
+
layout: { lockScreen: vstack([bound('title'), bound('status'), progress('done')]) },
|
|
64
|
+
snapshot: { revision: 0, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', done: 0.15 } },
|
|
140
65
|
});
|
|
141
|
-
await
|
|
66
|
+
await updateLayout({ id: snack.id, snapshot: { revision: 1, values: { title: 'Mochi’s snack', status: 'On the way', done: 0.65 } } });
|
|
67
|
+
await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
142
68
|
```
|
|
143
69
|
|
|
144
|
-
Each update sends
|
|
145
|
-
again after a restart.
|
|
146
|
-
|
|
147
|
-
<table>
|
|
148
|
-
<tr><th>iOS 26.3 simulator</th><th>Android 16 emulator</th></tr>
|
|
149
|
-
<tr>
|
|
150
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-v1-progress.png" width="400" alt="Mochi's snack delivery at 65% on the iOS Lock Screen"></td>
|
|
151
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-v1-progress.png" width="400" alt="Mochi's snack delivery with a progress bar in the Android notification shade"></td>
|
|
152
|
-
</tr>
|
|
153
|
-
</table>
|
|
70
|
+
The layout stays as it started. Each update sends every value again, with a higher revision.
|
|
154
71
|
|
|
155
|
-
|
|
156
|
-
status and bar.
|
|
72
|
+
## Changing styles
|
|
157
73
|
|
|
158
|
-
|
|
74
|
+
The tree is fixed at start, but a few style members can name a value. An update then changes them:
|
|
159
75
|
|
|
160
76
|
```ts
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
await start({
|
|
165
|
-
activityKey: 'mochi:nap',
|
|
166
|
-
schemaVersion: 1,
|
|
167
|
-
template: 'timer',
|
|
168
|
-
fallback: 'notification',
|
|
169
|
-
snapshot: {
|
|
170
|
-
revision: 0, title: 'Mochi’s nap', status: 'A little snooze, a little peace',
|
|
171
|
-
timer: { startedAt: now, endsAt: now + 5 * 60_000 },
|
|
172
|
-
},
|
|
173
|
-
});
|
|
77
|
+
const { bind } = layout;
|
|
78
|
+
// styles: { status: { color: bind('tone'), weight: bind('weight') } }, values: { tone: 'green', weight: 'regular', … }
|
|
79
|
+
await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 'red', weight: 'bold' } } });
|
|
174
80
|
```
|
|
175
81
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-v1-timer.png" width="400" alt="Mochi's nap counting down from 4:48 on the iOS Lock Screen"></td>
|
|
182
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-v1-timer.png" width="400" alt="Mochi's nap with the countdown in the Android notification header"></td>
|
|
183
|
-
</tr>
|
|
184
|
-
</table>
|
|
185
|
-
|
|
186
|
-
## Layouts
|
|
187
|
-
|
|
188
|
-
With a layout the app designs the activity itself: a tree of nodes, a table of styles and a
|
|
189
|
-
map of values. On iOS the plugin's widget template draws it, with no SwiftUI in the app.
|
|
190
|
-
Android shows part of it as a notification. The tree is fixed at start; an update sends new
|
|
191
|
-
values with the same keys and types. Layout, styles and values share ActivityKit's 4 KiB
|
|
192
|
-
limit.
|
|
193
|
-
|
|
194
|
-
### Text, values and styles
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { layout, startLayout, updateLayout, endLayout } from 'tauri-plugin-live-activity';
|
|
198
|
-
|
|
199
|
-
const { vstack, bound, text } = layout;
|
|
200
|
-
|
|
201
|
-
const card = await startLayout({
|
|
202
|
-
activityKey: 'mochi:text',
|
|
203
|
-
schemaVersion: 2,
|
|
204
|
-
fallback: 'notification',
|
|
205
|
-
layout: {
|
|
206
|
-
lockScreen: vstack([
|
|
207
|
-
bound('title', { style: 'title' }),
|
|
208
|
-
bound('status', { style: 'status', unless: 'arrived' }),
|
|
209
|
-
text('Snack time! Made it home', { style: 'done', if: 'arrived' }),
|
|
210
|
-
], { alignment: 'leading' }),
|
|
211
|
-
},
|
|
212
|
-
styles: {
|
|
213
|
-
title: { font: 'headline' },
|
|
214
|
-
status: { font: 'subheadline', color: 'secondary' },
|
|
215
|
-
done: { font: 'subheadline', weight: 'bold', color: '#C9654D' },
|
|
216
|
-
},
|
|
217
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', arrived: false } },
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
await updateLayout({
|
|
221
|
-
id: card.id,
|
|
222
|
-
snapshot: { revision: 1, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', arrived: true } },
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
await endLayout({ id: card.id, policy: { kind: 'immediate' } });
|
|
82
|
+
```rust
|
|
83
|
+
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
84
|
+
// Later: every value again, with the new color.
|
|
85
|
+
values.insert("tone".into(), Value::Text("red".into()));
|
|
86
|
+
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None } })?;
|
|
226
87
|
```
|
|
227
88
|
|
|
228
|
-
`
|
|
229
|
-
`
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
<tr>
|
|
235
|
-
<td><code>arrived: false</code></td>
|
|
236
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-text.png" width="380" alt="Title and status text on the iOS Lock Screen"></td>
|
|
237
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-text.png" width="380" alt="The same title and status as an Android notification"></td>
|
|
238
|
-
</tr>
|
|
239
|
-
<tr>
|
|
240
|
-
<td><code>arrived: true</code></td>
|
|
241
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-text-arrived.png" width="380" alt="The status replaced by Snack time in bold coral on iOS"></td>
|
|
242
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-text-arrived.png" width="380" alt="The body replaced by Snack time on Android"></td>
|
|
243
|
-
</tr>
|
|
244
|
-
</table>
|
|
245
|
-
|
|
246
|
-
Android drops styles: the first text is the title and the second the body.
|
|
89
|
+
Only `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius` and the layout's
|
|
90
|
+
`background` and `keyline` can be bound. A bound color is a name or a hex color, not a light and
|
|
91
|
+
dark pair. Everything else stays as started; end the activity and start it again to change it.
|
|
92
|
+
Each update sends all values again, and layout, styles and values share the weight limit of 3584.
|
|
93
|
+
Android draws no styles. A 0.2.x crate rejects bindings, so keep the npm package and the crate on
|
|
94
|
+
the same minor version. [More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#changing-styles)
|
|
247
95
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
```ts
|
|
251
|
-
layout: {
|
|
252
|
-
lockScreen: hstack([
|
|
253
|
-
symbol('cat.fill'),
|
|
254
|
-
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
255
|
-
symbol('speaker.wave.3.fill', { variableBind: 'purr' }),
|
|
256
|
-
bound('title'),
|
|
257
|
-
], { spacing: 12 }),
|
|
258
|
-
},
|
|
259
|
-
snapshot: { revision: 0, values: { title: 'Purr meter', purr: 0.35 } },
|
|
260
|
-
```
|
|
96
|
+
## What a layout can hold
|
|
261
97
|
|
|
262
|
-
|
|
98
|
+
Layouts are built from `text`/`bound`, `path` (SVG path data) and `vstack`, `hstack`, `zstack`,
|
|
99
|
+
`spacer`, `divider`, plus the six below. Each picture is the iOS Lock Screen. The snippets take
|
|
100
|
+
the builders from `layout` (`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
263
101
|
|
|
264
|
-
|
|
265
|
-
| --- | --- |
|
|
266
|
-
| <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% on the iOS Lock Screen"> | Not shown. Listed as `layout.symbol` in `degradedFeatures`. |
|
|
102
|
+
### Symbols
|
|
267
103
|
|
|
268
|
-
|
|
104
|
+
<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%">
|
|
269
105
|
|
|
270
106
|
```ts
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
|
|
107
|
+
hstack([
|
|
108
|
+
symbol('cat.fill'),
|
|
109
|
+
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
110
|
+
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
111
|
+
])
|
|
276
112
|
```
|
|
277
113
|
|
|
278
|
-
`
|
|
279
|
-
folder in `src-tauri/gen/apple/LiveActivityWidget` and run
|
|
280
|
-
`xcodegen generate --spec src-tauri/gen/apple/project.yml`; the widget target picks it up. The
|
|
281
|
-
demo's `mochi` is a PNG drawn from an SVG file.
|
|
114
|
+
SF Symbols. `variableBind` fills a variable symbol from a value between 0 and 1. iOS only.
|
|
282
115
|
|
|
283
|
-
|
|
284
|
-
| --- | --- |
|
|
285
|
-
| <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 on the iOS Lock Screen"> | Not shown. Listed as `layout.image`. |
|
|
116
|
+
### Image
|
|
286
117
|
|
|
287
|
-
|
|
118
|
+
<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">
|
|
288
119
|
|
|
289
120
|
```ts
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
lockScreen: zstack([
|
|
293
|
-
path(head, [100, 90], { style: 'fur' }),
|
|
294
|
-
path(head, [100, 90], { stroke: 1.5 }),
|
|
295
|
-
path('M28 54Q33 58 38 54M62 54Q67 58 72 54', [100, 90], { stroke: 2 }),
|
|
296
|
-
path('M48 64Q50 62 52 64Q50 66 48 64Z', [100, 90], { style: 'nose' }),
|
|
297
|
-
], { style: 'face' }),
|
|
298
|
-
},
|
|
299
|
-
styles: { face: { frame: { width: 60, height: 54 } }, fur: { color: '#F6E9CD' }, nose: { color: '#C9654D' } },
|
|
300
|
-
snapshot: { revision: 0, values: {} },
|
|
121
|
+
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
122
|
+
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
301
123
|
```
|
|
302
124
|
|
|
303
|
-
|
|
304
|
-
filled, or stroked when `stroke` gives a line width. `d` takes `M L H V C S Q T Z`, up to
|
|
305
|
-
512 bytes. Arcs (`A`) are not supported; convert them to curves first.
|
|
306
|
-
|
|
307
|
-
| iOS 26.3 simulator | Android |
|
|
308
|
-
| --- | --- |
|
|
309
|
-
| <img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-paths.png" width="400" alt="Mochi's face drawn from four paths on the iOS Lock Screen"> | Not shown. Listed as `layout.path`. |
|
|
125
|
+
A picture from the widget extension's asset catalog. iOS only.
|
|
310
126
|
|
|
311
127
|
### Gauge
|
|
312
128
|
|
|
313
|
-
|
|
314
|
-
layout: {
|
|
315
|
-
lockScreen: hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })], { spacing: 12 }),
|
|
316
|
-
},
|
|
317
|
-
snapshot: { revision: 0, values: { bowl: 80 } },
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
A gauge shows a number between `min` and `max` (0 and 1 when left out), as a ring or a bar.
|
|
321
|
-
|
|
322
|
-
| iOS 26.3 simulator | Android |
|
|
323
|
-
| --- | --- |
|
|
324
|
-
| <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 on the iOS Lock Screen"> | Not shown. Listed as `layout.gauge`. |
|
|
325
|
-
|
|
326
|
-
### Progress
|
|
129
|
+
<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">
|
|
327
130
|
|
|
328
131
|
```ts
|
|
329
|
-
|
|
330
|
-
lockScreen: vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]),
|
|
331
|
-
},
|
|
332
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s snack delivery', done: 0.65 } },
|
|
132
|
+
hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })]) // bowl: 80
|
|
333
133
|
```
|
|
334
134
|
|
|
335
|
-
A
|
|
135
|
+
A number between `min` and `max` as a ring or a bar. iOS only.
|
|
336
136
|
|
|
337
|
-
|
|
338
|
-
<tr><th>iOS 26.3 simulator</th><th>Android 16 emulator</th></tr>
|
|
339
|
-
<tr>
|
|
340
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="400" alt="A ring and a bar at 65% on the iOS Lock Screen"></td>
|
|
341
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-progress.png" width="400" alt="The first progress view as the bar of an Android notification"></td>
|
|
342
|
-
</tr>
|
|
343
|
-
</table>
|
|
344
|
-
|
|
345
|
-
Android turns the first progress view into the notification's bar.
|
|
137
|
+
### Progress
|
|
346
138
|
|
|
347
|
-
|
|
139
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="400" alt="A ring and a bar at 65%">
|
|
348
140
|
|
|
349
141
|
```ts
|
|
350
|
-
|
|
351
|
-
lockScreen: vstack([bound('title'), timerText('start', 'end')]),
|
|
352
|
-
},
|
|
353
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s nap', start: Date.now(), end: Date.now() + 5 * 60_000 } },
|
|
142
|
+
vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]) // done: 0.65
|
|
354
143
|
```
|
|
355
144
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
<table>
|
|
359
|
-
<tr><th>iOS 26.3 simulator</th><th>Android 16 emulator</th></tr>
|
|
360
|
-
<tr>
|
|
361
|
-
<td><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 on the iOS Lock Screen"></td>
|
|
362
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-timer.png" width="400" alt="The countdown as the chronometer in the Android notification header"></td>
|
|
363
|
-
</tr>
|
|
364
|
-
</table>
|
|
145
|
+
A number from 0 to 1. On Android the first one becomes the notification's bar.
|
|
365
146
|
|
|
366
|
-
|
|
147
|
+
### Timer
|
|
367
148
|
|
|
368
|
-
|
|
149
|
+
<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">
|
|
369
150
|
|
|
370
151
|
```ts
|
|
371
|
-
|
|
372
|
-
lockScreen: vstack([
|
|
373
|
-
hstack([zstack([symbol('circle.fill'), symbol('pawprint.fill', { style: 'mark' })]), bound('title'), spacer(), bound('eta')]),
|
|
374
|
-
divider(),
|
|
375
|
-
hstack([bound('from'), spacer(), bound('to')]),
|
|
376
|
-
], { spacing: 10 }),
|
|
377
|
-
},
|
|
378
|
-
styles: { mark: { size: 13, color: 'white' } },
|
|
379
|
-
snapshot: { revision: 0, values: { title: 'Snack route', eta: '4 min', from: 'Kitchen', to: 'Mochi’s bowl' } },
|
|
152
|
+
vstack([bound('title'), timerText('start', 'end')]) // end: Date.now() + 5 * 60_000
|
|
380
153
|
```
|
|
381
154
|
|
|
382
|
-
|
|
383
|
-
`spacer` takes the free space and `divider` draws a line.
|
|
384
|
-
|
|
385
|
-
| iOS 26.3 simulator | Android |
|
|
386
|
-
| --- | --- |
|
|
387
|
-
| <img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-stacks.png" width="400" alt="A paw badge, title and time in a row, a line, and From and To below on the iOS Lock Screen"> | Only the first two texts, as the title and the body. Not captured. |
|
|
155
|
+
The system counts it, down to `end` or up from `start` (`countsDown: false`). On Android it is the notification's chronometer.
|
|
388
156
|
|
|
389
157
|
### Buttons
|
|
390
158
|
|
|
391
|
-
|
|
392
|
-
layout: {
|
|
393
|
-
lockScreen: vstack([
|
|
394
|
-
bound('title'),
|
|
395
|
-
bound('status'),
|
|
396
|
-
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))], { spacing: 8 }),
|
|
397
|
-
], { alignment: 'leading' }),
|
|
398
|
-
},
|
|
399
|
-
snapshot: { revision: 0, values: { title: 'Mochi wants attention', status: 'No pets yet', pets: 0 } },
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
A tap reports the button's action ID. It does not change the activity: update or end it in a
|
|
403
|
-
handler. `onAction` hears taps while the web view runs:
|
|
159
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="400" alt="Pet Mochi and All done buttons after one pet">
|
|
404
160
|
|
|
405
161
|
```ts
|
|
406
|
-
|
|
162
|
+
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))])
|
|
407
163
|
|
|
408
164
|
await onAction(async ({ actionId, activityId }) => {
|
|
409
165
|
if (actionId === 'done') await endLayout({ id: activityId, policy: { kind: 'immediate' } });
|
|
410
166
|
});
|
|
411
167
|
```
|
|
412
168
|
|
|
413
|
-
|
|
414
|
-
view. Taps that must work then belong in Rust. Register the handler on the built `App`
|
|
415
|
-
before `run`:
|
|
416
|
-
|
|
417
|
-
```rust
|
|
418
|
-
use tauri_plugin_live_activity::{EndInput, EndPolicy, LiveActivityExt};
|
|
419
|
-
|
|
420
|
-
let app = tauri::Builder::default()
|
|
421
|
-
.plugin(tauri_plugin_live_activity::init())
|
|
422
|
-
.build(tauri::generate_context!())
|
|
423
|
-
.expect("error while building tauri application");
|
|
424
|
-
let handle = app.handle().clone();
|
|
425
|
-
app.live_activity().on_action(move |event| {
|
|
426
|
-
if event.action_id == "done" {
|
|
427
|
-
let input = EndInput { id: event.activity_id, policy: EndPolicy::Immediate {} };
|
|
428
|
-
let _ = handle.live_activity().end_layout(input);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
app.run(|_, _| {});
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
Rust handlers run first, on a plugin thread, and may call the plugin. `onAction` needs
|
|
435
|
-
`core:event:default`, which a new app has.
|
|
436
|
-
|
|
437
|
-
<table>
|
|
438
|
-
<tr><th></th><th>iOS 26.3 simulator</th><th>Android 16 emulator</th></tr>
|
|
439
|
-
<tr>
|
|
440
|
-
<td>Start</td>
|
|
441
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-before.png" width="380" alt="Pet Mochi and All done buttons on the iOS Lock Screen"></td>
|
|
442
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-buttons-before.png" width="380" alt="Pet Mochi and All done as Android notification actions"></td>
|
|
443
|
-
</tr>
|
|
444
|
-
<tr>
|
|
445
|
-
<td>After taps on Pet Mochi</td>
|
|
446
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="380" alt="The status reads Purring. 1 pet so far after one tap on iOS"></td>
|
|
447
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-buttons-after.png" width="380" alt="The body reads Purring. 2 pets so far after two taps on Android"></td>
|
|
448
|
-
</tr>
|
|
449
|
-
</table>
|
|
450
|
-
|
|
451
|
-
The demo's Rust handler counts the pets and updates the status. Buttons need iOS 17
|
|
452
|
-
(`getCapabilities()` reports `actions`). Android shows up to three buttons as notification
|
|
453
|
-
actions. On Android, a tap that starts a killed app waits in memory and is lost if the Tauri
|
|
454
|
-
runtime does not start.
|
|
169
|
+
A tap reaches `onAction`, or `on_action` in Rust, which also runs when the app was not open. iOS 17+; Android shows up to three as notification actions.
|
|
455
170
|
|
|
456
171
|
### Dynamic Island
|
|
457
172
|
|
|
458
|
-
```ts
|
|
459
|
-
layout: {
|
|
460
|
-
lockScreen: vstack([bound('title'), bound('status'), progress('done')]),
|
|
461
|
-
island: {
|
|
462
|
-
expanded: {
|
|
463
|
-
leading: image('mochi', { resizable: true, style: 'portrait' }),
|
|
464
|
-
center: bound('title'),
|
|
465
|
-
trailing: bound('eta'),
|
|
466
|
-
bottom: vstack([bound('status'), progress('done')]),
|
|
467
|
-
},
|
|
468
|
-
compactLeading: symbol('pawprint.fill'),
|
|
469
|
-
compactTrailing: bound('eta'),
|
|
470
|
-
minimal: progress('done', { kind: 'circular' }),
|
|
471
|
-
},
|
|
472
|
-
keyline: '#A3D9C2',
|
|
473
|
-
},
|
|
474
|
-
styles: { portrait: { frame: { width: 44, height: 44 } } },
|
|
475
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s snack', status: 'Packing a tiny treat', done: 0.15, eta: '9 min' } },
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
`island` gives each part its own nodes. A part left out gets a default: the expanded view
|
|
479
|
-
shows the lock screen tree, compact leading and minimal show its first symbol. `keyline` tints
|
|
480
|
-
the island's edge.
|
|
481
|
-
|
|
482
173
|
<table>
|
|
483
174
|
<tr><th>Compact</th><th>Minimal</th><th>Expanded</th></tr>
|
|
484
175
|
<tr>
|
|
485
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-compact.png" width="270" alt="A paw
|
|
176
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-compact.png" width="270" alt="A paw and 9 min in the compact Dynamic Island"></td>
|
|
486
177
|
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-minimal.png" width="180" alt="A progress ring in the minimal Dynamic Island"></td>
|
|
487
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="265" alt="
|
|
178
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="265" alt="Portrait, title, time, status and bar in the expanded Dynamic Island"></td>
|
|
488
179
|
</tr>
|
|
489
180
|
</table>
|
|
490
181
|
|
|
491
|
-
iOS 26.3 on the iPhone 17 simulator. Android has no Dynamic Island and lists `layout.island`.
|
|
492
|
-
|
|
493
|
-
### Android
|
|
494
|
-
|
|
495
|
-
A notification cannot draw a layout. Android takes these parts of the lock screen tree, in
|
|
496
|
-
order, with the current values:
|
|
497
|
-
|
|
498
|
-
| Layout | Notification |
|
|
499
|
-
| --- | --- |
|
|
500
|
-
| first `text` | title |
|
|
501
|
-
| second `text` | body |
|
|
502
|
-
| first `progress` | progress bar |
|
|
503
|
-
| first `timerText` | chronometer |
|
|
504
|
-
| up to three `button`s | actions, labelled with their first text |
|
|
505
|
-
| `android.visibility` | lock screen visibility: `public`, `private` (default) or `secret` |
|
|
506
|
-
|
|
507
|
-
Everything else is listed in `degradedFeatures`, here `layout.symbol` and `layout.styles`:
|
|
508
|
-
|
|
509
182
|
```ts
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
bound('
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
183
|
+
island: {
|
|
184
|
+
expanded: {
|
|
185
|
+
leading: image('mochi', { resizable: true, style: 'portrait' }),
|
|
186
|
+
center: bound('title'),
|
|
187
|
+
trailing: bound('eta'),
|
|
188
|
+
bottom: vstack([bound('status'), progress('done')]),
|
|
189
|
+
},
|
|
190
|
+
compactLeading: symbol('pawprint.fill'),
|
|
191
|
+
compactTrailing: bound('eta'),
|
|
192
|
+
minimal: progress('done', { kind: 'circular' }),
|
|
517
193
|
},
|
|
518
|
-
|
|
519
|
-
snapshot: { revision: 0, values: { title: 'Mochi’s nap', status: 'Dozing off', sleep: 0.2 } },
|
|
520
|
-
android: { visibility: 'public' },
|
|
194
|
+
keyline: '#A3D9C2', // the island's edge color
|
|
521
195
|
```
|
|
522
196
|
|
|
523
|
-
|
|
524
|
-
| --- | --- |
|
|
525
|
-
| Drawn as written, like the examples above. | <img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/android-layout-android.png" width="400" alt="Mochi's nap at 60% with a Wake Mochi action in the Android notification shade"> |
|
|
197
|
+
Put `island` next to `lockScreen` in the layout. A part you leave out shows the lock screen tree (expanded) or its first symbol (compact leading, minimal).
|
|
526
198
|
|
|
527
|
-
|
|
528
|
-
requests promotion to a Live Update where the app may post one; `promotionState` reports what
|
|
529
|
-
Android did.
|
|
199
|
+
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.
|
|
530
200
|
|
|
531
|
-
|
|
201
|
+
## Beyond the built-in parts
|
|
532
202
|
|
|
533
|
-
|
|
534
|
-
for every app while the user has the developer option "Live notifications for all apps" on.
|
|
535
|
-
Samsung adds apps to the list privately; no public way to apply was found. To show the title
|
|
536
|
-
and the body there on Android 17 and later, turn on the plugin's One UI extras:
|
|
203
|
+
Most customizing needs no Swift. Bundle your fonts and pictures in the widget extension, and name them:
|
|
537
204
|
|
|
538
205
|
```sh
|
|
539
|
-
|
|
206
|
+
npx tauri-plugin-live-activity setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png
|
|
540
207
|
```
|
|
541
208
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
209
|
+
```ts
|
|
210
|
+
styles: { title: { fontFamily: 'Pacifico-Regular', size: 22 } }, // setup prints the names a font answers to
|
|
211
|
+
lockScreen: hstack([image('paw'), bound('title', { style: 'title' })]),
|
|
212
|
+
```
|
|
545
213
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
extras do not put the app on the allow list. An app that Samsung lists without its `RON` flag
|
|
549
|
-
also needs this manifest entry, which the plugin does not add:
|
|
214
|
+
Pictures the app draws, on a canvas or in Rust, go through an App Group (`setup --app-group`). Write the PNG,
|
|
215
|
+
then start or update, and the widget draws it:
|
|
550
216
|
|
|
551
|
-
```
|
|
552
|
-
|
|
217
|
+
```ts
|
|
218
|
+
await writeImage('badge.png', png); // Rust: app.live_activity().write_image("badge.png", &png)
|
|
219
|
+
lockScreen: image({ file: 'badge.png' }, { resizable: true }),
|
|
553
220
|
```
|
|
554
221
|
|
|
555
|
-
|
|
222
|
+
For a view of your own, write it in SwiftUI in `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`, which
|
|
223
|
+
`setup` creates once and never overwrites, and place it with `custom`:
|
|
556
224
|
|
|
557
|
-
|
|
225
|
+
```ts
|
|
226
|
+
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
227
|
+
```
|
|
558
228
|
|
|
559
|
-
```
|
|
560
|
-
|
|
229
|
+
```swift
|
|
230
|
+
"ring": LiveActivityCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
561
231
|
```
|
|
562
232
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
values that cannot be guessed. Android ignores the option for now and stores records in
|
|
567
|
-
full in app-private preferences.
|
|
568
|
-
- `android.samsungNowBar`: the [Samsung Now Bar](#samsung-now-bar) extras; off when absent.
|
|
233
|
+
A name without a view draws nothing and is reported in `degradedFeatures` as `layout.custom.ring`. The last
|
|
234
|
+
resort is to edit the copied `LiveActivityWidget.swift`; `setup` then keeps your copy, and template updates are
|
|
235
|
+
yours to merge.
|
|
569
236
|
|
|
570
|
-
|
|
237
|
+
Limits: a Live Activity has no network and little memory. A drawn PNG is at most 1 MiB and 1224 × 480 pixels,
|
|
238
|
+
Apple's largest Lock Screen presentation at @3x. Fonts must be in the extension. On a device the App Group is
|
|
239
|
+
registered with your Apple account once; automatic signing does that. The validators check a custom view's name
|
|
240
|
+
and props, not the view. Android draws none of these, except that the first drawn image becomes the
|
|
241
|
+
notification's large icon. Layout, styles and values still share 3584.
|
|
242
|
+
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
571
243
|
|
|
572
|
-
|
|
244
|
+
## Samsung Now Bar
|
|
573
245
|
|
|
574
|
-
|
|
575
|
-
|
|
246
|
+
Set `"plugins": { "live-activity": { "android": { "samsungNowBar": true } } }` in
|
|
247
|
+
`tauri.conf.json` to send One UI 9 the title and body that its Now Bar shows. One UI shows the
|
|
248
|
+
Now Bar only for apps on Samsung's allow list, or for every app while the developer option
|
|
249
|
+
"Live notifications for all apps" is on, and the plugin cannot add an app to that list.
|
|
576
250
|
|
|
577
|
-
|
|
578
|
-
npm ci && npm run build:demo && cd examples/demo && npm run tauri -- ios dev
|
|
579
|
-
```
|
|
251
|
+
## More
|
|
580
252
|
|
|
581
|
-
|
|
582
|
-
|
|
253
|
+
The [docs](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/docs) cover the
|
|
254
|
+
rest: what `setup` changes and how to do it by hand, every layout node with iOS and Android
|
|
255
|
+
captures, buttons handled in Rust, the progress and timer templates, the plugin options and
|
|
256
|
+
the test records.
|
|
583
257
|
|
|
584
258
|
## License
|
|
585
259
|
|