tauri-plugin-live-activity 0.3.0 → 0.5.1
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 +69 -8
- package/README.md +70 -9
- package/cli/ios.mjs +65 -46
- package/cli/migration.mjs +55 -0
- package/cli/report.mjs +2 -2
- package/cli/setup.mjs +18 -7
- package/cli/steps.mjs +1 -1
- package/cli/templates/LiveActivityCustomViews.swift +25 -0
- package/cli/xcodegen.mjs +28 -20
- package/dist-js/index.d.ts +9 -5
- package/dist-js/index.js +7 -3
- package/dist-js/jsx/index.d.ts +59 -0
- package/dist-js/jsx/index.js +101 -0
- package/dist-js/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist-js/jsx/jsx-dev-runtime.js +6 -0
- package/dist-js/jsx/jsx-runtime.d.ts +16 -0
- package/dist-js/jsx/jsx-runtime.js +9 -0
- package/dist-js/react/index.d.ts +12 -0
- package/dist-js/react/index.js +42 -0
- package/dist-js/react/session.d.ts +68 -0
- package/dist-js/react/session.js +138 -0
- package/dist-js/types.d.ts +16 -3
- package/package.json +17 -4
package/README.ko.md
CHANGED
|
@@ -23,8 +23,12 @@ Tauri 2 앱이 하고 있는 일을 iPhone 잠금 화면과 Dynamic Island에, A
|
|
|
23
23
|
</table>
|
|
24
24
|
|
|
25
25
|
네 장 모두 고양이 Mochi를 따라가는 [데모 앱](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/examples/demo)에서
|
|
26
|
-
캡처했습니다. 플러그인은 iOS 16.
|
|
27
|
-
`UNSUPPORTED_PLATFORM`을 돌려줍니다.
|
|
26
|
+
캡처했습니다. 플러그인은 iOS 16.2 이상과 Android 8 이상에서 동작하고, 데스크톱에서는 활동 명령이
|
|
27
|
+
`UNSUPPORTED_PLATFORM`을 돌려줍니다. iOS에서는 [activitykit](https://github.com/1eedaegon/activitykit-rs) 크레이트
|
|
28
|
+
위에서 동작하므로 플러그인 자체의 Swift 코드가 없습니다. Android에서는 진행률과 타이머 템플릿의 수명 주기를
|
|
29
|
+
[liveupdate](https://github.com/1eedaegon/liveupdate-rs) 크레이트로 Rust에서 처리합니다. 레이아웃도 이 크레이트가
|
|
30
|
+
안드로이드 알림 스타일로 그리고, 플러그인의 Kotlin은 권한 명령만 맡습니다. 1.0 전까지는 마이너 버전이 바뀔 때 API도 바뀔 수
|
|
31
|
+
있습니다.
|
|
28
32
|
|
|
29
33
|
## 설치
|
|
30
34
|
|
|
@@ -43,8 +47,9 @@ npx tauri-plugin-live-activity setup
|
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
`setup`은 플러그인 권한을 허용하고, Android 최소 버전을 API 26으로 올리고, Mac에서는 활동을 그리는
|
|
46
|
-
위젯 확장을 Xcode 프로젝트에 추가합니다. `tauri ios init` 뒤에 실행하고, 나중에
|
|
47
|
-
처음부터 다시 만들었다면 한 번 더 실행하세요.
|
|
50
|
+
위젯 확장을 activitykit의 Swift 패키지로 Xcode 프로젝트에 추가합니다. `tauri ios init` 뒤에 실행하고, 나중에
|
|
51
|
+
`src-tauri/gen/apple`을 처음부터 다시 만들었다면 한 번 더 실행하세요. 0.3으로 설정한 앱이라면 다시 한 번
|
|
52
|
+
실행하면 위젯과 직접 만든 뷰를 activitykit으로 옮겨 줍니다. 무엇이 바뀔지는 `--dry-run`으로 먼저 볼 수 있습니다.
|
|
48
53
|
|
|
49
54
|
## 사용법
|
|
50
55
|
|
|
@@ -83,7 +88,7 @@ await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 're
|
|
|
83
88
|
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
84
89
|
// 나중에: 값을 모두 다시 보내면서 색만 바꿉니다.
|
|
85
90
|
values.insert("tone".into(), Value::Text("red".into()));
|
|
86
|
-
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None } })?;
|
|
91
|
+
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None, timestamp: None } })?;
|
|
87
92
|
```
|
|
88
93
|
|
|
89
94
|
값을 가리킬 수 있는 것은 `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius`와
|
|
@@ -98,6 +103,7 @@ app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapsh
|
|
|
98
103
|
레이아웃은 `text`/`bound`, `path`(SVG path 데이터), `vstack`·`hstack`·`zstack`·`spacer`·`divider`와
|
|
99
104
|
아래 여섯 가지로 만듭니다. 그림은 모두 iOS 잠금화면입니다. 예시의 빌더는 `layout`에서 꺼내 씁니다
|
|
100
105
|
(`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
106
|
+
같은 레이아웃을 TSX로 쓸 수 있고, React 훅으로 컴포넌트와 액티비티를 함께 움직일 수도 있습니다([TSX와 React](#tsx와-react)).
|
|
101
107
|
|
|
102
108
|
### 심볼
|
|
103
109
|
|
|
@@ -198,6 +204,50 @@ keyline: '#A3D9C2', // 아일랜드 테두리 색
|
|
|
198
204
|
|
|
199
205
|
Android는 레이아웃을 알림으로 보여 줍니다. 첫 두 텍스트가 제목과 본문이 되고, 첫 진행률 막대와 타이머, 버튼 최대 세 개가 들어갑니다. 빠진 것은 `degradedFeatures`에 이름이 남습니다.
|
|
200
206
|
|
|
207
|
+
## TSX와 React
|
|
208
|
+
|
|
209
|
+
같은 레이아웃을 TSX로 쓸 수 있습니다. `tauri-plugin-live-activity/jsx`는 자체 JSX 소스라 `.tsx` 파일에 React가
|
|
210
|
+
필요 없습니다. `tsconfig.json`에 `"jsx": "react-jsx"`와 `"jsxImportSource": "tauri-plugin-live-activity/jsx"`를
|
|
211
|
+
두거나, 파일 맨 위에 `/** @jsxImportSource tauri-plugin-live-activity/jsx */`를 적습니다.
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { Button, HStack, SFSymbol, Text, VStack } from 'tauri-plugin-live-activity/jsx';
|
|
215
|
+
|
|
216
|
+
const lockScreen = (
|
|
217
|
+
<VStack alignment="leading" spacing={8}>
|
|
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
|
+
노드마다 컴포넌트가 하나씩 있고(`VStack`, `HStack`, `ZStack`, `Spacer`, `Divider`, `Text`, `SFSymbol`, `Image`,
|
|
226
|
+
`Path`, `Progress`, `Gauge`, `TimerText`, `Button`, `Custom`), 노드의 멤버가 그대로 prop입니다. `Text`는 자식을
|
|
227
|
+
글자로 보여 주고 `bind`를 주면 값을 보여 줍니다. 스택은 노드, 배열, `{late && <Text>Late</Text>}`를 받고, `Button`은
|
|
228
|
+
노드 하나를 감쌉니다. HTML 요소와 프래그먼트는 없습니다. 이 엔트리는 Tauri도 React도 불러오지 않아서, 서버에서 푸시
|
|
229
|
+
페이로드용으로 같은 레이아웃을 만들 수 있습니다.
|
|
230
|
+
|
|
231
|
+
`tauri-plugin-live-activity/react`는 액티비티 하나를 컴포넌트와 함께 움직입니다(React 18 이상, 선택적 peer
|
|
232
|
+
의존성).
|
|
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
|
+
마운트되면 시작하고, `values`가 바뀐 렌더마다 다음 revision으로 갱신 하나를 보내며(한 번에 요청 하나, 겹치면 마지막
|
|
247
|
+
값만), 언마운트나 `enabled: false`에 끝납니다. `layout`과 `styles`는 시작할 때만 읽으니 바꾸려면 `activityKey`를
|
|
248
|
+
바꿔 새 액티비티를 시작합니다. 거부된 요청은 `error`에 남고, `onAction`은 이 액티비티의 탭만 받습니다.
|
|
249
|
+
[더 보기](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#tsx-and-react)
|
|
250
|
+
|
|
201
251
|
## 기본 부품 너머
|
|
202
252
|
|
|
203
253
|
대부분은 Swift 없이 바꿀 수 있습니다. 글꼴과 그림을 위젯 확장에 넣고 이름으로 부르면 됩니다.
|
|
@@ -227,12 +277,12 @@ custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
|
227
277
|
```
|
|
228
278
|
|
|
229
279
|
```swift
|
|
230
|
-
"ring":
|
|
280
|
+
"ring": ActivityKitCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
231
281
|
```
|
|
232
282
|
|
|
233
283
|
뷰가 없는 이름은 아무것도 그리지 않고 `degradedFeatures`에 `layout.custom.ring`으로 남습니다. 마지막 수단은
|
|
234
|
-
복사된 `LiveActivityWidget.swift
|
|
235
|
-
바뀐 부분은 직접 합쳐야 합니다.
|
|
284
|
+
복사된 `LiveActivityWidget.swift`(activitykit의 위젯 템플릿)를 직접 고치는 것입니다. 그러면 `setup`은 그 파일을
|
|
285
|
+
그대로 두고, 템플릿이 바뀐 부분은 직접 합쳐야 합니다.
|
|
236
286
|
|
|
237
287
|
제한: Live Activity는 네트워크를 쓸 수 없고 메모리도 적습니다. 그린 PNG는 1 MiB, 1224 × 480 픽셀까지이고,
|
|
238
288
|
이는 Apple의 가장 큰 잠금화면 크기를 @3x로 잰 값입니다. 글꼴은 확장 안에 있어야 합니다. 기기에서는 App
|
|
@@ -241,6 +291,17 @@ Group을 Apple 계정에 한 번 등록해야 하는데, 자동 서명이 대신
|
|
|
241
291
|
아이콘이 됩니다. 레이아웃, 스타일, 값은 여전히 3584를 나눠 씁니다.
|
|
242
292
|
[자세히](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
243
293
|
|
|
294
|
+
## 제약
|
|
295
|
+
|
|
296
|
+
- iOS: iOS 16.2 이상의 iPhone 또는 iPadOS 17 이상의 iPad가 필요하고, 버튼은 iOS 17부터 동작합니다. 활동은 앱이
|
|
297
|
+
포그라운드에 있을 때만 시작되고(아니면 `NOT_FOREGROUND`), 시스템이 8시간 뒤에 끝냅니다.
|
|
298
|
+
- iOS는 활동마다 마지막 값을 앱의 Application Support에 평문으로 남깁니다. 플러그인 설정에
|
|
299
|
+
`"receipts": "redacted"`를 주면 값 대신 다이제스트만 남깁니다.
|
|
300
|
+
- 버튼을 누르면 Rust의 `on_action` 핸들러가 끝날 때까지 최대 4초 기다립니다. JavaScript 리스너는 기다리지 않습니다.
|
|
301
|
+
- `app.live_activity()`의 Rust 메서드는 응답이 올 때까지 스레드를 멈추므로 메인 스레드가 아닌 곳에서 호출하세요. iOS에서
|
|
302
|
+
메인 스레드에서 호출하면 바로 `NATIVE_ERROR`를 돌려줍니다. JavaScript의 명령은 멈추지 않습니다.
|
|
303
|
+
- 푸시 갱신은 없습니다. Android는 진행 중 알림으로 보여 주고, 시스템이 허용하면 Live Update로 올립니다.
|
|
304
|
+
|
|
244
305
|
## Samsung Now Bar
|
|
245
306
|
|
|
246
307
|
`tauri.conf.json`에 `"plugins": { "live-activity": { "android": { "samsungNowBar": true } } }`를 넣으면
|
package/README.md
CHANGED
|
@@ -23,8 +23,11 @@ an ongoing notification on Android. You describe the layout in TypeScript; the p
|
|
|
23
23
|
</table>
|
|
24
24
|
|
|
25
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.
|
|
27
|
-
activity commands return `UNSUPPORTED_PLATFORM`.
|
|
26
|
+
which follows a cat named Mochi. The plugin runs on iOS 16.2+ and Android 8+; on desktop, its
|
|
27
|
+
activity commands return `UNSUPPORTED_PLATFORM`. On iOS it is built on the
|
|
28
|
+
[activitykit](https://github.com/1eedaegon/activitykit-rs) crate and has no Swift of its own. On Android every activity runs
|
|
29
|
+
its lifecycle in Rust, on the [liveupdate](https://github.com/1eedaegon/liveupdate-rs) crate, which draws templates
|
|
30
|
+
and layouts as Android's notification styles; the plugin's Kotlin only answers the permission commands. Before 1.0, a minor version may change the API.
|
|
28
31
|
|
|
29
32
|
## Install
|
|
30
33
|
|
|
@@ -43,9 +46,10 @@ Then add one line to the builder in `src-tauri/src/lib.rs`:
|
|
|
43
46
|
```
|
|
44
47
|
|
|
45
48
|
`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
|
|
47
|
-
`tauri ios init`, and again if `src-tauri/gen/apple` is ever made from
|
|
48
|
-
|
|
49
|
+
adds the widget extension that draws the activity to the Xcode project, on activitykit's Swift
|
|
50
|
+
package. Run it after `tauri ios init`, and again if `src-tauri/gen/apple` is ever made from
|
|
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.
|
|
49
53
|
|
|
50
54
|
## Use
|
|
51
55
|
|
|
@@ -83,7 +87,7 @@ await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 're
|
|
|
83
87
|
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
84
88
|
// Later: every value again, with the new color.
|
|
85
89
|
values.insert("tone".into(), Value::Text("red".into()));
|
|
86
|
-
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None } })?;
|
|
90
|
+
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None, timestamp: None } })?;
|
|
87
91
|
```
|
|
88
92
|
|
|
89
93
|
Only `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius` and the layout's
|
|
@@ -98,6 +102,8 @@ the same minor version. [More](https://github.com/1eedaegon/tauri-plugin-live-ac
|
|
|
98
102
|
Layouts are built from `text`/`bound`, `path` (SVG path data) and `vstack`, `hstack`, `zstack`,
|
|
99
103
|
`spacer`, `divider`, plus the six below. Each picture is the iOS Lock Screen. The snippets take
|
|
100
104
|
the builders from `layout` (`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
105
|
+
The same layouts can be written in TSX, and a React hook keeps an activity in step with a component
|
|
106
|
+
([TSX and React](#tsx-and-react)).
|
|
101
107
|
|
|
102
108
|
### Symbols
|
|
103
109
|
|
|
@@ -198,6 +204,50 @@ Put `island` next to `lockScreen` in the layout. A part you leave out shows the
|
|
|
198
204
|
|
|
199
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.
|
|
200
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.
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { Button, HStack, SFSymbol, Text, VStack } from 'tauri-plugin-live-activity/jsx';
|
|
215
|
+
|
|
216
|
+
const lockScreen = (
|
|
217
|
+
<VStack alignment="leading" spacing={8}>
|
|
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)
|
|
250
|
+
|
|
201
251
|
## Beyond the built-in parts
|
|
202
252
|
|
|
203
253
|
Most customizing needs no Swift. Bundle your fonts and pictures in the widget extension, and name them:
|
|
@@ -227,12 +277,12 @@ custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
|
227
277
|
```
|
|
228
278
|
|
|
229
279
|
```swift
|
|
230
|
-
"ring":
|
|
280
|
+
"ring": ActivityKitCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
231
281
|
```
|
|
232
282
|
|
|
233
283
|
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
|
|
235
|
-
yours to merge.
|
|
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.
|
|
236
286
|
|
|
237
287
|
Limits: a Live Activity has no network and little memory. A drawn PNG is at most 1 MiB and 1224 × 480 pixels,
|
|
238
288
|
Apple's largest Lock Screen presentation at @3x. Fonts must be in the extension. On a device the App Group is
|
|
@@ -241,6 +291,17 @@ and props, not the view. Android draws none of these, except that the first draw
|
|
|
241
291
|
notification's large icon. Layout, styles and values still share 3584.
|
|
242
292
|
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
243
293
|
|
|
294
|
+
## Limits
|
|
295
|
+
|
|
296
|
+
- iOS: an iPhone with iOS 16.2 or an iPad with iPadOS 17; buttons need iOS 17. An activity starts only while the
|
|
297
|
+
app is in the foreground (`NOT_FOREGROUND` otherwise), and the system ends it after 8 hours.
|
|
298
|
+
- iOS keeps each activity's last values in plain text in the app's Application Support, unless the plugin
|
|
299
|
+
configuration sets `"receipts": "redacted"`.
|
|
300
|
+
- A button's tap waits for your Rust `on_action` handlers, at most 4 seconds; JavaScript listeners are not awaited.
|
|
301
|
+
- The Rust methods of `app.live_activity()` block until the answer: call them off the main thread. On iOS a call on
|
|
302
|
+
the main thread answers `NATIVE_ERROR` at once. The commands from JavaScript never block.
|
|
303
|
+
- No push updates. Android shows an ongoing notification, promoted to a Live Update where the system allows it.
|
|
304
|
+
|
|
244
305
|
## Samsung Now Bar
|
|
245
306
|
|
|
246
307
|
Set `"plugins": { "live-activity": { "android": { "samsungNowBar": true } } }` in
|
package/cli/ios.mjs
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
// The iOS part of setup: Info.ios.plist, the widget files in gen/apple with the fonts and images it
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// The iOS part of setup: Info.ios.plist, the widget files in gen/apple with the fonts and images it bundles, the
|
|
2
|
+
// XcodeGen spec that adds the widget extension on activitykit's Swift package, the App Group, and the regenerated
|
|
3
|
+
// Xcode project. An app that 0.2 or 0.3 set up loses the plugin's old Swift files on the way (migration.mjs).
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import {
|
|
6
|
-
import { join,
|
|
5
|
+
import { readdirSync, rmSync } from 'node:fs';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { OLD_MODULES, RETIRED, released, renameCustomViews } from './migration.mjs';
|
|
7
8
|
import { newPlist, setTrueKey } from './plist.mjs';
|
|
8
9
|
import { SetupError, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
|
|
9
10
|
import { assetSteps, bundledFonts, fontSteps } from './widget-files.mjs';
|
|
10
11
|
import { SPEC_FILE, WIDGET, addInclude, appGroupOf, readProject, widgetSpec, writtenBySetup } from './xcodegen.mjs';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/** The widget bundle: activitykit's template, under the name 0.2 and 0.3 gave the plugin's. */
|
|
14
|
+
const WIDGET_FILE = 'LiveActivityWidget.swift';
|
|
15
|
+
const WIDGET_TEMPLATE = join('templates', 'ios', 'Widget.swift');
|
|
16
|
+
/** The app's own file: created once from the template and never written again, but for the names of activitykit. */
|
|
14
17
|
const CUSTOM_VIEWS = 'LiveActivityCustomViews.swift';
|
|
18
|
+
const CUSTOM_VIEWS_TEMPLATE = new URL('./templates/LiveActivityCustomViews.swift', import.meta.url);
|
|
15
19
|
const GROUP = /^group\.[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
|
|
16
20
|
const PLIST_KEY = 'NSSupportsLiveActivities';
|
|
17
|
-
// Left out of the copy of Tauri's Swift API, as the plugin's build script does.
|
|
18
|
-
const NOT_COPIED = ['.build', 'Package.resolved', 'Tests'];
|
|
19
21
|
|
|
20
22
|
export function iosSteps(context) {
|
|
21
23
|
const { srcTauri, platform, show } = context;
|
|
@@ -42,12 +44,13 @@ export function iosSteps(context) {
|
|
|
42
44
|
const widget = join(apple, WIDGET);
|
|
43
45
|
const appGroup = appGroupFor(context, apple, project);
|
|
44
46
|
const include = includeStep(context, specPath, yaml);
|
|
45
|
-
// XcodeGen lists the files of a folder when it generates, so a new widget file also needs a run.
|
|
47
|
+
// XcodeGen lists the files of a folder when it generates, so a new or removed widget file also needs a run.
|
|
46
48
|
const projectSteps = [
|
|
47
|
-
|
|
49
|
+
widgetStep(context, widget), ...retiredSteps(context, widget, readText(join(apple, SPEC_FILE))), customViewsStep(context, widget),
|
|
50
|
+
...fontSteps(context, widget), ...assetSteps(context, widget),
|
|
48
51
|
specStep(context, apple, project, { fonts: bundledFonts(context, widget), appGroup }), include,
|
|
49
52
|
];
|
|
50
|
-
return [plist, ...projectSteps,
|
|
53
|
+
return [plist, ...projectSteps, xcodegenStep(context, apple, specPath, projectSteps, include)];
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -63,12 +66,19 @@ function appGroupFor({ appGroup, config }, apple, project) {
|
|
|
63
66
|
return group;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
69
|
+
/**
|
|
70
|
+
* LiveActivityCustomViews.swift belongs to the app: created once, then never written again, except that a file of 0.3
|
|
71
|
+
* takes activitykit's names, its views kept.
|
|
72
|
+
*/
|
|
73
|
+
function customViewsStep({ show }, widget) {
|
|
68
74
|
const path = join(widget, CUSTOM_VIEWS);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const current = readText(path);
|
|
76
|
+
if (current !== undefined) {
|
|
77
|
+
const renamed = renameCustomViews(current);
|
|
78
|
+
if (renamed === undefined) return step('unchanged', show(path));
|
|
79
|
+
return step('updated', show(path), "activitykit's names for the registry and its types; your views are kept", writeFile(path, renamed));
|
|
80
|
+
}
|
|
81
|
+
const stub = readText(CUSTOM_VIEWS_TEMPLATE);
|
|
72
82
|
return step('created', show(path), 'yours, for custom views; setup never changes it again', writeFile(path, stub));
|
|
73
83
|
}
|
|
74
84
|
|
|
@@ -86,20 +96,44 @@ function infoPlistStep({ srcTauri, show }) {
|
|
|
86
96
|
return step('kept', show(path), `it sets ${PLIST_KEY} to something other than true; Live Activities need true`);
|
|
87
97
|
}
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
/** The widget bundle from activitykit's template; one that 0.2 or 0.3 wrote is replaced, one of the app's kept. */
|
|
100
|
+
function widgetStep({ activitykit, show }, widget) {
|
|
101
|
+
const wanted = readText(join(activitykit.dir, WIDGET_TEMPLATE));
|
|
102
|
+
if (wanted === undefined) throw new SetupError(`The activitykit crate at ${activitykit.dir} has no ${WIDGET_TEMPLATE}.`);
|
|
103
|
+
const path = join(widget, WIDGET_FILE);
|
|
104
|
+
const current = readText(path);
|
|
105
|
+
if (current === undefined) return step('created', show(path), '', writeFile(path, wanted));
|
|
106
|
+
if (current === wanted) return step('unchanged', show(path));
|
|
107
|
+
if (released(WIDGET_FILE, current)) {
|
|
108
|
+
return step('updated', show(path), "activitykit's widget, in place of the one tauri-plugin-live-activity 0.3 wrote", writeFile(path, wanted));
|
|
109
|
+
}
|
|
110
|
+
if (OLD_MODULES.test(current)) {
|
|
111
|
+
return step('todo', show(path), "imports the Swift modules of tauri-plugin-live-activity 0.3, which 0.4 no longer has: draw with ActivityKitWidget's ActivityKitLayoutWidget(), or delete the file and run setup again");
|
|
112
|
+
}
|
|
113
|
+
return step('kept', show(path), "differs from activitykit's template; to take the template, delete it and run setup again");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The button intent and the custom views registry of 0.2 and 0.3, which activitykit's products replace. A spec changed
|
|
118
|
+
* by hand, which setup keeps, may still name one: XcodeGen would fail without it, so it stays as a step to do.
|
|
119
|
+
*/
|
|
120
|
+
function retiredSteps({ show }, widget, spec) {
|
|
121
|
+
const kept = spec !== undefined && !writtenBySetup(spec);
|
|
122
|
+
return RETIRED.flatMap(name => {
|
|
123
|
+
const path = join(widget, name);
|
|
94
124
|
const current = readText(path);
|
|
95
|
-
if (current === undefined) return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
125
|
+
if (current === undefined) return [];
|
|
126
|
+
if (kept && spec.includes(name)) {
|
|
127
|
+
return [step('todo', show(path), `${SPEC_FILE}, which you changed, still names it: take it out of the spec, then delete it; activitykit's Swift package replaces it`)];
|
|
128
|
+
}
|
|
129
|
+
if (released(name, current)) {
|
|
130
|
+
return [step('removed', show(path), "activitykit's Swift package replaces it", () => rmSync(path))];
|
|
131
|
+
}
|
|
132
|
+
return [step('todo', show(path), "changed by hand; activitykit's Swift package replaces it, so move your changes and delete it")];
|
|
99
133
|
});
|
|
100
134
|
}
|
|
101
135
|
|
|
102
|
-
function specStep({ plugin, config, srcTauri, show }, apple, project, { fonts, appGroup }) {
|
|
136
|
+
function specStep({ plugin, activitykit, config, srcTauri, show }, apple, project, { fonts, appGroup }) {
|
|
103
137
|
const path = join(apple, SPEC_FILE);
|
|
104
138
|
const wanted = widgetSpec({
|
|
105
139
|
fonts,
|
|
@@ -107,7 +141,7 @@ function specStep({ plugin, config, srcTauri, show }, apple, project, { fonts, a
|
|
|
107
141
|
// XcodeGen writes the entitlements file from the spec, so the App Group goes into the spec, at the app's path.
|
|
108
142
|
appEntitlements: project.entitlements ?? `${project.appTarget}/${project.appTarget}.entitlements`,
|
|
109
143
|
pluginVersion: plugin.version,
|
|
110
|
-
packagePath: join(
|
|
144
|
+
packagePath: join(activitykit.dir, 'swift'),
|
|
111
145
|
appTarget: project.appTarget,
|
|
112
146
|
bundleId: `${project.bundleId ?? config.identifier}.widget`,
|
|
113
147
|
...appVersions(config, srcTauri),
|
|
@@ -115,13 +149,13 @@ function specStep({ plugin, config, srcTauri, show }, apple, project, { fonts, a
|
|
|
115
149
|
});
|
|
116
150
|
const current = readText(path);
|
|
117
151
|
if (current === undefined) {
|
|
118
|
-
return step('created', show(path),
|
|
152
|
+
return step('created', show(path), "the widget extension on activitykit's Swift package, and the button intent and custom views in the app", writeFile(path, wanted));
|
|
119
153
|
}
|
|
120
154
|
if (current === wanted) return step('unchanged', show(path));
|
|
121
155
|
if (!writtenBySetup(current)) {
|
|
122
156
|
return step('kept', show(path), 'it was changed by hand; delete it and run setup again to have it written anew');
|
|
123
157
|
}
|
|
124
|
-
return step('updated', show(path), 'for the current plugin and app version', writeFile(path, wanted));
|
|
158
|
+
return step('updated', show(path), 'for the current plugin, activitykit and app version', writeFile(path, wanted));
|
|
125
159
|
}
|
|
126
160
|
|
|
127
161
|
/** The `version` of Cargo.toml's [package] section. */
|
|
@@ -150,21 +184,6 @@ function includeStep({ show }, specPath, yaml) {
|
|
|
150
184
|
return step('todo', show(specPath), `add ${SPEC_FILE} to its include list`);
|
|
151
185
|
}
|
|
152
186
|
|
|
153
|
-
/** The plugin's Swift package refers to Tauri's at ../.tauri/tauri-api, which the plugin's iOS build copies there. */
|
|
154
|
-
function swiftPackageStep({ plugin, show }) {
|
|
155
|
-
const target = join(plugin.dir, '.tauri', 'tauri-api');
|
|
156
|
-
if (existsSync(join(target, 'Package.swift'))) return step('unchanged', show(target));
|
|
157
|
-
const source = plugin.tauriDir && join(plugin.tauriDir, 'mobile', 'ios-api');
|
|
158
|
-
if (!source || !existsSync(join(source, 'Package.swift'))) {
|
|
159
|
-
const detail = "the plugin's Swift package needs Tauri's Swift API here. Build the Rust code for iOS once to make it: "
|
|
160
|
-
+ 'cargo build --target aarch64-apple-ios-sim (x86_64-apple-ios on an Intel Mac) in src-tauri';
|
|
161
|
-
return step('todo', show(target), detail);
|
|
162
|
-
}
|
|
163
|
-
const copied = path => !NOT_COPIED.some(name => relative(source, path) === name || relative(source, path).startsWith(name + sep));
|
|
164
|
-
const detail = "Tauri's Swift API for the plugin's Swift package, as the plugin's iOS build copies it";
|
|
165
|
-
return step('created', show(target), detail, () => cpSync(source, target, { recursive: true, filter: copied }));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
187
|
function generatedWithWidget(apple) {
|
|
169
188
|
return readdirSync(apple).filter(name => name.endsWith('.xcodeproj'))
|
|
170
189
|
.some(name => readText(join(apple, name, 'project.pbxproj'))?.includes(WIDGET));
|
|
@@ -173,7 +192,7 @@ function generatedWithWidget(apple) {
|
|
|
173
192
|
function xcodegenStep({ env, show }, apple, specPath, projectSteps, include) {
|
|
174
193
|
const command = `xcodegen generate --spec ${show(specPath)}`;
|
|
175
194
|
if (include.status === 'todo') return step('skipped', 'Xcode project', 'waits for the include in project.yml');
|
|
176
|
-
const changed = projectSteps.some(item =>
|
|
195
|
+
const changed = projectSteps.some(item => ['created', 'updated', 'removed'].includes(item.status));
|
|
177
196
|
if (!changed && generatedWithWidget(apple)) return step('unchanged', 'Xcode project');
|
|
178
197
|
const xcodegen = which('xcodegen', env);
|
|
179
198
|
if (!xcodegen) return step('todo', 'Xcode project', `XcodeGen is not on PATH. Install it (brew install xcodegen), then run: ${command}`);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// What setup changes in an app that tauri-plugin-live-activity 0.2 or 0.3 set up, whose widget extension and app
|
|
2
|
+
// target compiled the plugin's own Swift: 0.4 takes the widget, the button intent and the custom views registry from
|
|
3
|
+
// activitykit's Swift package.
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
/** The SHA-256 of each template as a release of the plugin wrote it into the widget folder. */
|
|
7
|
+
export const RELEASED = {
|
|
8
|
+
// 0.2.0, 0.2.1 and 0.3.0: the button intent, which activitykit's ActivityKitIntent product replaces.
|
|
9
|
+
'LiveActivityActionIntent.swift': ['cd96e40c42aae84b2e76db2f264f8ead892bf77c282e51f7443dc8624bc3ead5'],
|
|
10
|
+
// 0.3.0: the base of the custom views, which activitykit's ActivityKitViews product replaces.
|
|
11
|
+
'LiveActivityCustomRegistry.swift': ['75c2275fe63da34234fca039ed459151edb851c1acf1faf0e6a400791345983f'],
|
|
12
|
+
// 0.2.x and 0.3.0: the widget bundle on the plugin's own Swift modules.
|
|
13
|
+
'LiveActivityWidget.swift': [
|
|
14
|
+
'2a76d033acbbd208c7050e10394c31c120ad96d0ff55189daed11ad5255cbd2c',
|
|
15
|
+
'a8abe58a70300204b1406e5dbcc0d53f6265b525785903d5b2e6e1d2b317476d',
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Files that only the plugin's own Swift needed. */
|
|
20
|
+
export const RETIRED = ['LiveActivityActionIntent.swift', 'LiveActivityCustomRegistry.swift'];
|
|
21
|
+
|
|
22
|
+
/** The Swift modules of the plugin before 0.4; a widget file that imports one no longer builds. */
|
|
23
|
+
export const OLD_MODULES = /\bimport\s+(LiveActivityShared|LiveActivityUI|LiveActivityCore)\b/;
|
|
24
|
+
|
|
25
|
+
const sha256 = text => createHash('sha256').update(text).digest('hex');
|
|
26
|
+
|
|
27
|
+
/** True when `text` is the file `name` exactly as a release wrote it. */
|
|
28
|
+
export function released(name, text) {
|
|
29
|
+
return RELEASED[name]?.includes(sha256(text)) ?? false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The names of 0.3's custom views file and activitykit's, longest first: `LiveActivityCustomView` is a prefix of the
|
|
33
|
+
// other two, and the class `LiveActivityCustomViews` keeps its Swift name.
|
|
34
|
+
const RENAMES = [
|
|
35
|
+
['TauriLiveActivityCustomViews', 'ActivityKitCustomViews'],
|
|
36
|
+
['LiveActivityCustomViewRegistry', 'ActivityKitCustomViewRegistry'],
|
|
37
|
+
['LiveActivityCustomProps', 'ActivityKitCustomProps'],
|
|
38
|
+
['LiveActivityCustomView', 'ActivityKitCustomView'],
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The app's custom views file with activitykit's names: the Objective-C name, the registry, the view and props types,
|
|
43
|
+
* and `import ActivityKitViews`. The app's views stay as they are. Undefined when the file has none of 0.3's names.
|
|
44
|
+
*/
|
|
45
|
+
export function renameCustomViews(text) {
|
|
46
|
+
if (!RENAMES.some(([old]) => new RegExp(`\\b${old}\\b`).test(text))) return undefined;
|
|
47
|
+
let next = RENAMES.reduce((current, [old, name]) => current.replace(new RegExp(`\\b${old}\\b`, 'g'), name), text);
|
|
48
|
+
if (!/^\s*import\s+ActivityKitViews\b/m.test(next)) {
|
|
49
|
+
const swiftUI = /^import SwiftUI[ \t]*$/m.exec(next);
|
|
50
|
+
next = swiftUI
|
|
51
|
+
? `${next.slice(0, swiftUI.index)}import ActivityKitViews\n${next.slice(swiftUI.index)}`
|
|
52
|
+
: `import ActivityKitViews\n${next}`;
|
|
53
|
+
}
|
|
54
|
+
return next;
|
|
55
|
+
}
|
package/cli/report.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The summary that setup prints.
|
|
2
2
|
|
|
3
|
-
const DONE = { created: 'created', updated: 'updated', ran: 'ran', kept: 'kept', skipped: 'skipped' };
|
|
4
|
-
const WOULD = { created: 'would create', updated: 'would update', ran: 'would run', kept: 'would keep', skipped: 'would skip' };
|
|
3
|
+
const DONE = { created: 'created', updated: 'updated', removed: 'removed', ran: 'ran', kept: 'kept', skipped: 'skipped' };
|
|
4
|
+
const WOULD = { created: 'would create', updated: 'would update', removed: 'would remove', ran: 'would run', kept: 'would keep', skipped: 'would skip' };
|
|
5
5
|
|
|
6
6
|
function line(item, dryRun) {
|
|
7
7
|
const label = (dryRun ? WOULD : DONE)[item.status];
|
package/cli/setup.mjs
CHANGED
|
@@ -10,6 +10,8 @@ import { widgetFiles } from './widget-files.mjs';
|
|
|
10
10
|
export { SetupError } from './steps.mjs';
|
|
11
11
|
|
|
12
12
|
export const CRATE = 'tauri-plugin-live-activity';
|
|
13
|
+
/** The crate whose Swift package the widget extension and the app target link. */
|
|
14
|
+
export const ACTIVITYKIT = 'activitykit';
|
|
13
15
|
/** `default` reads; the others allow the commands that change activities. */
|
|
14
16
|
export const PERMISSIONS = [
|
|
15
17
|
'live-activity:default',
|
|
@@ -31,8 +33,8 @@ export function setup({
|
|
|
31
33
|
} = {}) {
|
|
32
34
|
const files = widgetFiles(cwd, { fonts, assets });
|
|
33
35
|
const app = findApp(cwd);
|
|
34
|
-
const plugin =
|
|
35
|
-
const context = { ...app, plugin, env, platform, files, appGroup, show: path => display(cwd, path) };
|
|
36
|
+
const { plugin, activitykit } = findCrates(app, env);
|
|
37
|
+
const context = { ...app, plugin, activitykit, env, platform, files, appGroup, show: path => display(cwd, path) };
|
|
36
38
|
const planned = [...(iosOnly ? [] : [capabilitiesStep(context), ...androidSteps(context)]), ...iosSteps(context)];
|
|
37
39
|
const steps = dryRun ? planned : planned.map(apply);
|
|
38
40
|
return { dryRun, version: plugin.version, steps: steps.map(({ effect, ...rest }) => rest), notes: notes(context) };
|
|
@@ -63,8 +65,11 @@ function findApp(cwd) {
|
|
|
63
65
|
return { srcTauri, configPath, configText, config };
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
+
/**
|
|
69
|
+
* The plugin crate's version and the folder of the activitykit crate it depends on, from `cargo metadata`: the widget
|
|
70
|
+
* extension and the app target link activitykit's Swift package, which lies in that folder.
|
|
71
|
+
*/
|
|
72
|
+
export function findCrates({ srcTauri }, env) {
|
|
68
73
|
const args = ['metadata', '--format-version', '1', '--manifest-path', join(srcTauri, 'Cargo.toml')];
|
|
69
74
|
const result = spawnSync(env.CARGO || 'cargo', args, { env, encoding: 'utf8', maxBuffer: 1024 ** 3 });
|
|
70
75
|
if (result.error?.code === 'ENOENT') throw new SetupError('cargo was not found. Install Rust from https://rustup.rs, then run this again.');
|
|
@@ -76,9 +81,15 @@ function findPlugin({ srcTauri }, env) {
|
|
|
76
81
|
if (!crate) {
|
|
77
82
|
throw new SetupError(`${CRATE} is not a dependency of src-tauri/Cargo.toml yet. Add it first:\n cargo add ${CRATE} --manifest-path src-tauri/Cargo.toml`);
|
|
78
83
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
84
|
+
const kitId = metadata.resolve?.nodes?.find(node => node.id === crate.id)?.deps?.find(dep => dep.name === ACTIVITYKIT)?.pkg;
|
|
85
|
+
const kit = metadata.packages.find(item => (kitId ? item.id === kitId : item.name === ACTIVITYKIT));
|
|
86
|
+
if (!kit) {
|
|
87
|
+
throw new SetupError(`${CRATE} ${crate.version} does not depend on ${ACTIVITYKIT}, whose Swift package the widget extension links: use the crate of the npm package's version, ${NPM_VERSION}.`);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
plugin: { version: crate.version, dir: dirname(crate.manifest_path) },
|
|
91
|
+
activitykit: { version: kit.version, dir: dirname(kit.manifest_path) },
|
|
92
|
+
};
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
/** Adds the plugin's permissions to the app's capability: default.json, or the only capability file. */
|
package/cli/steps.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export class SetupError extends Error {
|
|
|
9
9
|
name = 'SetupError';
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/** Status: created, updated, ran, kept, skipped, todo or unchanged. */
|
|
12
|
+
/** Status: created, updated, removed, ran, kept, skipped, todo or unchanged. */
|
|
13
13
|
export function step(status, path, detail = '', effect = undefined) {
|
|
14
14
|
return effect ? { status, path, detail, effect } : { status, path, detail };
|
|
15
15
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ActivityKitViews
|
|
2
|
+
import SwiftUI
|
|
3
|
+
|
|
4
|
+
// Your SwiftUI views for `custom` layout nodes. `npx tauri-plugin-live-activity setup` created this file once and never
|
|
5
|
+
// changes it. It is compiled into the widget extension, which draws the views, and into the app, so that activitykit can
|
|
6
|
+
// report a node whose name has no view here (`degradedFeatures`: `layout.custom.<name>`). Both targets link activitykit's
|
|
7
|
+
// `ActivityKitViews` product. Keep the Objective-C name: activitykit finds the views by it.
|
|
8
|
+
//
|
|
9
|
+
// A view gets the node's props: `props.number("level")`, `props.string("label")`, `props.bool("full")`. A prop bound to a
|
|
10
|
+
// value, `props: { level: bind('bowl') }`, has the value of the latest update. The node's style sets the frame, padding,
|
|
11
|
+
// colors and font around the view. A Live Activity has no network and little memory: draw with shapes, text and images
|
|
12
|
+
// of the extension; no timers, no animations of your own.
|
|
13
|
+
|
|
14
|
+
@available(iOS 16.1, *)
|
|
15
|
+
@objc(ActivityKitCustomViews)
|
|
16
|
+
final class LiveActivityCustomViews: ActivityKitCustomViewRegistry {
|
|
17
|
+
override class var views: [String: ActivityKitCustomView] {
|
|
18
|
+
[
|
|
19
|
+
// The layout node `custom('ring', { props: { level: bind('bowl') } })` draws this ring:
|
|
20
|
+
// "ring": ActivityKitCustomView { props in
|
|
21
|
+
// Circle().trim(from: 0, to: props.number("level") ?? 0).stroke(lineWidth: 4).rotationEffect(.degrees(-90))
|
|
22
|
+
// },
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|