tauri-plugin-live-activity 0.2.1 → 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 +163 -21
- package/README.md +163 -21
- package/cli/ios.mjs +51 -11
- package/cli/main.mjs +32 -7
- package/cli/setup.mjs +10 -4
- package/cli/widget-files.mjs +148 -0
- package/cli/xcodegen.mjs +52 -6
- 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 +1 -1
package/README.ko.md
CHANGED
|
@@ -69,35 +69,177 @@ await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
|
69
69
|
레이아웃은 시작할 때 모습 그대로 유지됩니다. 갱신할 때는 모든 값을 더 높은 revision과 함께 다시
|
|
70
70
|
보냅니다.
|
|
71
71
|
|
|
72
|
+
## 스타일 바꾸기
|
|
73
|
+
|
|
74
|
+
트리는 시작할 때 정해지지만, 몇몇 스타일 멤버는 값을 가리킬 수 있습니다. 그러면 갱신으로 바꿀 수 있습니다.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
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' } } });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```rust
|
|
83
|
+
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
84
|
+
// 나중에: 값을 모두 다시 보내면서 색만 바꿉니다.
|
|
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 } })?;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
값을 가리킬 수 있는 것은 `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius`와
|
|
90
|
+
레이아웃의 `background`, `keyline`뿐입니다. 색은 이름이나 hex 색만 되고, 라이트·다크 쌍은 쓸 수 없습니다.
|
|
91
|
+
나머지는 시작한 그대로 남으니, 바꾸려면 활동을 끝내고 다시 시작하세요. 갱신마다 값을 전부 다시 보내고,
|
|
92
|
+
레이아웃·스타일·값을 합친 weight는 3584를 넘을 수 없습니다. Android는 스타일을 그리지 않습니다.
|
|
93
|
+
0.2.x 크레이트는 바인딩을 거부하므로 npm 패키지와 크레이트의 마이너 버전을 맞추세요.
|
|
94
|
+
[자세히](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#changing-styles)
|
|
95
|
+
|
|
72
96
|
## 레이아웃에 넣을 수 있는 것
|
|
73
97
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
레이아웃은 `text`/`bound`, `path`(SVG path 데이터), `vstack`·`hstack`·`zstack`·`spacer`·`divider`와
|
|
99
|
+
아래 여섯 가지로 만듭니다. 그림은 모두 iOS 잠금화면입니다. 예시의 빌더는 `layout`에서 꺼내 씁니다
|
|
100
|
+
(`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
101
|
+
|
|
102
|
+
### 심볼
|
|
103
|
+
|
|
104
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="400" alt="고양이, 여러 색 하트, 35% 채운 스피커">
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
hstack([
|
|
108
|
+
symbol('cat.fill'),
|
|
109
|
+
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
110
|
+
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
111
|
+
])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
SF Symbols입니다. `variableBind`는 0~1 값으로 가변 심볼을 채웁니다. iOS 전용입니다.
|
|
115
|
+
|
|
116
|
+
### 이미지
|
|
117
|
+
|
|
118
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="400" alt="위젯 에셋 카탈로그의 Mochi 사진">
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
122
|
+
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
위젯 확장의 에셋 카탈로그에 있는 그림입니다. iOS 전용입니다.
|
|
126
|
+
|
|
127
|
+
### 게이지
|
|
128
|
+
|
|
129
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="400" alt="100 중 80을 가리키는 원형·선형 게이지">
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })]) // bowl: 80
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`min`~`max` 사이의 숫자를 원이나 막대로 보여 줍니다. iOS 전용입니다.
|
|
136
|
+
|
|
137
|
+
### 진행률
|
|
138
|
+
|
|
139
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="400" alt="65%를 가리키는 원과 막대">
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]) // done: 0.65
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
0~1 사이의 숫자입니다. Android에서는 첫 번째 진행률이 알림의 막대가 됩니다.
|
|
146
|
+
|
|
147
|
+
### 타이머
|
|
148
|
+
|
|
149
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="400" alt="Mochi 낮잠 아래 4:50에서 줄어드는 타이머">
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
vstack([bound('title'), timerText('start', 'end')]) // end: Date.now() + 5 * 60_000
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
시스템이 세는 타이머로, `end`까지 줄어들거나 `start`부터 늘어납니다(`countsDown: false`). Android에서는 알림의 크로노미터가 됩니다.
|
|
156
|
+
|
|
157
|
+
### 버튼
|
|
158
|
+
|
|
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·All done 버튼">
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))])
|
|
163
|
+
|
|
164
|
+
await onAction(async ({ actionId, activityId }) => {
|
|
165
|
+
if (actionId === 'done') await endLayout({ id: activityId, policy: { kind: 'immediate' } });
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
탭은 `onAction`으로, 앱이 열려 있지 않을 때는 Rust의 `on_action`으로 전달됩니다. iOS 17 이상이며, Android는 최대 세 개를 알림 버튼으로 보여 줍니다.
|
|
170
|
+
|
|
171
|
+
### Dynamic Island
|
|
83
172
|
|
|
84
173
|
<table>
|
|
85
|
-
<tr><th
|
|
86
|
-
<tr>
|
|
87
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="260" alt="고양이, 다색 하트, 35% 채운 스피커 심볼"></td>
|
|
88
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="260" alt="위젯 asset catalog에서 가져온 Mochi 초상"></td>
|
|
89
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="260" alt="100 중 80을 가리키는 원형 게이지와 막대 게이지"></td>
|
|
90
|
-
</tr>
|
|
91
|
-
<tr><th>진행률</th><th>타이머</th><th>버튼</th></tr>
|
|
174
|
+
<tr><th>컴팩트</th><th>미니멀</th><th>확장</th></tr>
|
|
92
175
|
<tr>
|
|
93
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
94
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
95
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
176
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-compact.png" width="270" alt="컴팩트 Dynamic Island의 발바닥과 9 min"></td>
|
|
177
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-minimal.png" width="180" alt="미니멀 Dynamic Island의 진행률 링"></td>
|
|
178
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="265" alt="확장 Dynamic Island의 사진, 제목, 시간, 상태, 막대"></td>
|
|
96
179
|
</tr>
|
|
97
180
|
</table>
|
|
98
181
|
|
|
99
|
-
|
|
100
|
-
|
|
182
|
+
```ts
|
|
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' }),
|
|
193
|
+
},
|
|
194
|
+
keyline: '#A3D9C2', // 아일랜드 테두리 색
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
레이아웃에서 `lockScreen` 옆에 `island`를 둡니다. 빠진 부분은 잠금화면 트리(확장)나 그 첫 심볼(컴팩트 왼쪽, 미니멀)을 보여 줍니다.
|
|
198
|
+
|
|
199
|
+
Android는 레이아웃을 알림으로 보여 줍니다. 첫 두 텍스트가 제목과 본문이 되고, 첫 진행률 막대와 타이머, 버튼 최대 세 개가 들어갑니다. 빠진 것은 `degradedFeatures`에 이름이 남습니다.
|
|
200
|
+
|
|
201
|
+
## 기본 부품 너머
|
|
202
|
+
|
|
203
|
+
대부분은 Swift 없이 바꿀 수 있습니다. 글꼴과 그림을 위젯 확장에 넣고 이름으로 부르면 됩니다.
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
npx tauri-plugin-live-activity setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
styles: { title: { fontFamily: 'Pacifico-Regular', size: 22 } }, // 글꼴을 부르는 이름은 setup이 알려 줍니다
|
|
211
|
+
lockScreen: hstack([image('paw'), bound('title', { style: 'title' })]),
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
앱이 캔버스나 Rust로 직접 그린 그림은 App Group을 거칩니다(`setup --app-group`). PNG를 쓴 다음 시작하거나
|
|
215
|
+
갱신하면 위젯이 그 그림을 그립니다.
|
|
216
|
+
|
|
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 }),
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
직접 만든 뷰가 필요하면 `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`에 SwiftUI로 쓰고 `custom`으로
|
|
223
|
+
놓습니다. 이 파일은 `setup`이 한 번 만들고 다시는 덮어쓰지 않습니다.
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```swift
|
|
230
|
+
"ring": LiveActivityCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
뷰가 없는 이름은 아무것도 그리지 않고 `degradedFeatures`에 `layout.custom.ring`으로 남습니다. 마지막 수단은
|
|
234
|
+
복사된 `LiveActivityWidget.swift`를 직접 고치는 것입니다. 그러면 `setup`은 그 파일을 그대로 두고, 템플릿이
|
|
235
|
+
바뀐 부분은 직접 합쳐야 합니다.
|
|
236
|
+
|
|
237
|
+
제한: Live Activity는 네트워크를 쓸 수 없고 메모리도 적습니다. 그린 PNG는 1 MiB, 1224 × 480 픽셀까지이고,
|
|
238
|
+
이는 Apple의 가장 큰 잠금화면 크기를 @3x로 잰 값입니다. 글꼴은 확장 안에 있어야 합니다. 기기에서는 App
|
|
239
|
+
Group을 Apple 계정에 한 번 등록해야 하는데, 자동 서명이 대신 해 줍니다. 검증기는 커스텀 뷰의 이름과 props만
|
|
240
|
+
보고 뷰 자체는 보지 않습니다. Android는 이 가운데 아무것도 그리지 않고, 처음 나오는 그린 그림만 알림의 큰
|
|
241
|
+
아이콘이 됩니다. 레이아웃, 스타일, 값은 여전히 3584를 나눠 씁니다.
|
|
242
|
+
[자세히](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
101
243
|
|
|
102
244
|
## Samsung Now Bar
|
|
103
245
|
|
package/README.md
CHANGED
|
@@ -69,35 +69,177 @@ await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
|
69
69
|
|
|
70
70
|
The layout stays as it started. Each update sends every value again, with a higher revision.
|
|
71
71
|
|
|
72
|
+
## Changing styles
|
|
73
|
+
|
|
74
|
+
The tree is fixed at start, but a few style members can name a value. An update then changes them:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
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' } } });
|
|
80
|
+
```
|
|
81
|
+
|
|
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 } })?;
|
|
87
|
+
```
|
|
88
|
+
|
|
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)
|
|
95
|
+
|
|
72
96
|
## What a layout can hold
|
|
73
97
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
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;`).
|
|
101
|
+
|
|
102
|
+
### Symbols
|
|
103
|
+
|
|
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%">
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
hstack([
|
|
108
|
+
symbol('cat.fill'),
|
|
109
|
+
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
110
|
+
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
111
|
+
])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
SF Symbols. `variableBind` fills a variable symbol from a value between 0 and 1. iOS only.
|
|
115
|
+
|
|
116
|
+
### Image
|
|
117
|
+
|
|
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">
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
122
|
+
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
A picture from the widget extension's asset catalog. iOS only.
|
|
126
|
+
|
|
127
|
+
### Gauge
|
|
128
|
+
|
|
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">
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })]) // bowl: 80
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
A number between `min` and `max` as a ring or a bar. iOS only.
|
|
136
|
+
|
|
137
|
+
### Progress
|
|
138
|
+
|
|
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%">
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]) // done: 0.65
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
A number from 0 to 1. On Android the first one becomes the notification's bar.
|
|
146
|
+
|
|
147
|
+
### Timer
|
|
148
|
+
|
|
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">
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
vstack([bound('title'), timerText('start', 'end')]) // end: Date.now() + 5 * 60_000
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The system counts it, down to `end` or up from `start` (`countsDown: false`). On Android it is the notification's chronometer.
|
|
156
|
+
|
|
157
|
+
### Buttons
|
|
158
|
+
|
|
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">
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))])
|
|
163
|
+
|
|
164
|
+
await onAction(async ({ actionId, activityId }) => {
|
|
165
|
+
if (actionId === 'done') await endLayout({ id: activityId, policy: { kind: 'immediate' } });
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
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.
|
|
170
|
+
|
|
171
|
+
### Dynamic Island
|
|
83
172
|
|
|
84
173
|
<table>
|
|
85
|
-
<tr><th>
|
|
86
|
-
<tr>
|
|
87
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="260" alt="A cat, a multicolor heart and a speaker filled to 35%"></td>
|
|
88
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="260" alt="Mochi's portrait from the widget's asset catalog"></td>
|
|
89
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="260" alt="A circular and a linear gauge at 80 of 100"></td>
|
|
90
|
-
</tr>
|
|
91
|
-
<tr><th>Progress</th><th>Timer</th><th>Buttons</th></tr>
|
|
174
|
+
<tr><th>Compact</th><th>Minimal</th><th>Expanded</th></tr>
|
|
92
175
|
<tr>
|
|
93
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
94
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
95
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
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>
|
|
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>
|
|
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>
|
|
96
179
|
</tr>
|
|
97
180
|
</table>
|
|
98
181
|
|
|
99
|
-
|
|
100
|
-
|
|
182
|
+
```ts
|
|
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' }),
|
|
193
|
+
},
|
|
194
|
+
keyline: '#A3D9C2', // the island's edge color
|
|
195
|
+
```
|
|
196
|
+
|
|
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).
|
|
198
|
+
|
|
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.
|
|
200
|
+
|
|
201
|
+
## Beyond the built-in parts
|
|
202
|
+
|
|
203
|
+
Most customizing needs no Swift. Bundle your fonts and pictures in the widget extension, and name them:
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
npx tauri-plugin-live-activity setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png
|
|
207
|
+
```
|
|
208
|
+
|
|
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
|
+
```
|
|
213
|
+
|
|
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:
|
|
216
|
+
|
|
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 }),
|
|
220
|
+
```
|
|
221
|
+
|
|
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`:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```swift
|
|
230
|
+
"ring": LiveActivityCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
231
|
+
```
|
|
232
|
+
|
|
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.
|
|
236
|
+
|
|
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)
|
|
101
243
|
|
|
102
244
|
## Samsung Now Bar
|
|
103
245
|
|
package/cli/ios.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
// The iOS part of setup: Info.ios.plist, the widget files in gen/apple
|
|
2
|
-
// the widget extension, the plugin's Swift package
|
|
1
|
+
// The iOS part of setup: Info.ios.plist, the widget files in gen/apple with the fonts and images it
|
|
2
|
+
// bundles, the XcodeGen spec that adds the widget extension, the App Group, the plugin's Swift package
|
|
3
|
+
// and the regenerated Xcode project.
|
|
3
4
|
import { spawnSync } from 'node:child_process';
|
|
4
5
|
import { cpSync, existsSync, readdirSync } from 'node:fs';
|
|
5
6
|
import { join, relative, resolve, sep } from 'node:path';
|
|
6
7
|
import { newPlist, setTrueKey } from './plist.mjs';
|
|
7
8
|
import { SetupError, parseJson, readText, step, tail, which, writeFile } from './steps.mjs';
|
|
8
|
-
import {
|
|
9
|
+
import { assetSteps, bundledFonts, fontSteps } from './widget-files.mjs';
|
|
10
|
+
import { SPEC_FILE, WIDGET, addInclude, appGroupOf, readProject, widgetSpec, writtenBySetup } from './xcodegen.mjs';
|
|
9
11
|
|
|
10
|
-
const TEMPLATES = ['LiveActivityWidget.swift', 'LiveActivityActionIntent.swift', 'Info.plist'];
|
|
12
|
+
const TEMPLATES = ['LiveActivityWidget.swift', 'LiveActivityActionIntent.swift', 'LiveActivityCustomRegistry.swift', 'Info.plist'];
|
|
13
|
+
/** The app's own file: created once from the template and never written again. */
|
|
14
|
+
const CUSTOM_VIEWS = 'LiveActivityCustomViews.swift';
|
|
15
|
+
const GROUP = /^group\.[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;
|
|
11
16
|
const PLIST_KEY = 'NSSupportsLiveActivities';
|
|
12
17
|
// Left out of the copy of Tauri's Swift API, as the plugin's build script does.
|
|
13
18
|
const NOT_COPIED = ['.build', 'Package.resolved', 'Tests'];
|
|
@@ -25,15 +30,46 @@ export function iosSteps(context) {
|
|
|
25
30
|
const plist = infoPlistStep(context);
|
|
26
31
|
if (project.widget) {
|
|
27
32
|
const detail = `already has a widget extension, ${project.widget}; add the plugin's widget to it by hand (docs/ios-integration.md)`;
|
|
28
|
-
|
|
33
|
+
const { files, appGroup } = context;
|
|
34
|
+
const given = [files.fonts.length && '--font', files.assets.length && '--asset', appGroup && '--app-group'].filter(Boolean);
|
|
35
|
+
const left = given.length === 0 ? [] : [step('todo', show(specPath), `${given.join(', ')} not applied: that widget is yours to give fonts, images and an App Group (docs/ios-integration.md)`)];
|
|
36
|
+
return [plist, step('skipped', show(specPath), detail), ...left];
|
|
29
37
|
}
|
|
30
38
|
if (!project.appTarget) {
|
|
31
39
|
const detail = `no target named ${project.name ?? '<name>'}_iOS, so setup did not add the widget; see docs/usage.md`;
|
|
32
40
|
return [plist, step('todo', show(specPath), detail)];
|
|
33
41
|
}
|
|
42
|
+
const widget = join(apple, WIDGET);
|
|
43
|
+
const appGroup = appGroupFor(context, apple, project);
|
|
44
|
+
const include = includeStep(context, specPath, yaml);
|
|
34
45
|
// XcodeGen lists the files of a folder when it generates, so a new widget file also needs a run.
|
|
35
|
-
const projectSteps = [
|
|
36
|
-
|
|
46
|
+
const projectSteps = [
|
|
47
|
+
...templateSteps(context, apple), customViewsStep(context, widget), ...fontSteps(context, widget), ...assetSteps(context, widget),
|
|
48
|
+
specStep(context, apple, project, { fonts: bundledFonts(context, widget), appGroup }), include,
|
|
49
|
+
];
|
|
50
|
+
return [plist, ...projectSteps, swiftPackageStep(context), xcodegenStep(context, apple, specPath, projectSteps, include)];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The App Group of `--app-group`: the group it names, or `group.<app identifier>`. A spec that setup wrote
|
|
55
|
+
* with a group keeps it on later runs.
|
|
56
|
+
*/
|
|
57
|
+
function appGroupFor({ appGroup, config }, apple, project) {
|
|
58
|
+
const kept = appGroupOf(readText(join(apple, SPEC_FILE)));
|
|
59
|
+
const group = typeof appGroup === 'string' ? appGroup : kept ?? (appGroup ? `group.${project.bundleId ?? config.identifier}` : undefined);
|
|
60
|
+
if (group !== undefined && !GROUP.test(group)) {
|
|
61
|
+
throw new SetupError(`The App Group ${JSON.stringify(group)} must be "group." followed by letters, digits, '-' and '.'.`);
|
|
62
|
+
}
|
|
63
|
+
return group;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** LiveActivityCustomViews.swift belongs to the app: created once, then never written again. */
|
|
67
|
+
function customViewsStep({ plugin, show }, widget) {
|
|
68
|
+
const path = join(widget, CUSTOM_VIEWS);
|
|
69
|
+
if (readText(path) !== undefined) return step('unchanged', show(path));
|
|
70
|
+
const stub = readText(join(plugin.dir, 'templates', 'ios', CUSTOM_VIEWS));
|
|
71
|
+
if (stub === undefined) throw new SetupError(`The plugin crate at ${plugin.dir} has no templates/ios/${CUSTOM_VIEWS}.`);
|
|
72
|
+
return step('created', show(path), 'yours, for custom views; setup never changes it again', writeFile(path, stub));
|
|
37
73
|
}
|
|
38
74
|
|
|
39
75
|
/** Tauri merges src-tauri/Info.ios.plist into the app's Info.plist when it builds. */
|
|
@@ -63,9 +99,13 @@ function templateSteps({ plugin, show }, apple) {
|
|
|
63
99
|
});
|
|
64
100
|
}
|
|
65
101
|
|
|
66
|
-
function specStep({ plugin, config, srcTauri, show }, apple, project) {
|
|
102
|
+
function specStep({ plugin, config, srcTauri, show }, apple, project, { fonts, appGroup }) {
|
|
67
103
|
const path = join(apple, SPEC_FILE);
|
|
68
104
|
const wanted = widgetSpec({
|
|
105
|
+
fonts,
|
|
106
|
+
appGroup,
|
|
107
|
+
// XcodeGen writes the entitlements file from the spec, so the App Group goes into the spec, at the app's path.
|
|
108
|
+
appEntitlements: project.entitlements ?? `${project.appTarget}/${project.appTarget}.entitlements`,
|
|
69
109
|
pluginVersion: plugin.version,
|
|
70
110
|
packagePath: join(plugin.dir, 'ios'),
|
|
71
111
|
appTarget: project.appTarget,
|
|
@@ -75,7 +115,7 @@ function specStep({ plugin, config, srcTauri, show }, apple, project) {
|
|
|
75
115
|
});
|
|
76
116
|
const current = readText(path);
|
|
77
117
|
if (current === undefined) {
|
|
78
|
-
return step('created', show(path), 'the widget extension, and the button intent in both targets', writeFile(path, wanted));
|
|
118
|
+
return step('created', show(path), 'the widget extension, and the button intent and custom views in both targets', writeFile(path, wanted));
|
|
79
119
|
}
|
|
80
120
|
if (current === wanted) return step('unchanged', show(path));
|
|
81
121
|
if (!writtenBySetup(current)) {
|
|
@@ -130,9 +170,9 @@ function generatedWithWidget(apple) {
|
|
|
130
170
|
.some(name => readText(join(apple, name, 'project.pbxproj'))?.includes(WIDGET));
|
|
131
171
|
}
|
|
132
172
|
|
|
133
|
-
function xcodegenStep({ env, show }, apple, specPath, projectSteps) {
|
|
173
|
+
function xcodegenStep({ env, show }, apple, specPath, projectSteps, include) {
|
|
134
174
|
const command = `xcodegen generate --spec ${show(specPath)}`;
|
|
135
|
-
if (
|
|
175
|
+
if (include.status === 'todo') return step('skipped', 'Xcode project', 'waits for the include in project.yml');
|
|
136
176
|
const changed = projectSteps.some(item => item.status === 'created' || item.status === 'updated');
|
|
137
177
|
if (!changed && generatedWithWidget(apple)) return step('unchanged', 'Xcode project');
|
|
138
178
|
const xcodegen = which('xcodegen', env);
|
package/cli/main.mjs
CHANGED
|
@@ -2,20 +2,42 @@
|
|
|
2
2
|
import { formatReport } from './report.mjs';
|
|
3
3
|
import { SetupError, setup } from './setup.mjs';
|
|
4
4
|
|
|
5
|
-
const USAGE = `Usage: npx tauri-plugin-live-activity setup [--dry-run] [--ios-only]
|
|
5
|
+
const USAGE = `Usage: npx tauri-plugin-live-activity setup [--dry-run] [--ios-only] [--font <file>]... [--asset <file>]... [--app-group[=<id>]]
|
|
6
6
|
|
|
7
7
|
Run it in the folder of a Tauri 2 app after \`cargo add\` and \`npm i\`. It grants the plugin's
|
|
8
8
|
permissions, sets the Android minimum to API 26 and, on a Mac, adds the Live Activity widget
|
|
9
9
|
extension to src-tauri/gen/apple. Run it after \`tauri ios init\`, and again if that folder is
|
|
10
10
|
ever made from scratch.
|
|
11
11
|
|
|
12
|
-
--dry-run
|
|
13
|
-
--ios-only
|
|
12
|
+
--dry-run show what would change, and write nothing
|
|
13
|
+
--ios-only do only the iOS part: leave the capabilities and tauri.conf.json alone
|
|
14
|
+
--font <file> bundle a .ttf, .otf or .ttc font in the widget extension, for a style's fontFamily
|
|
15
|
+
--asset <file> put a .png, .jpg, .pdf or .svg image in the widget's asset catalog, for image('<name>');
|
|
16
|
+
name@2x.png and name@3x.png are scales of the asset name
|
|
17
|
+
--app-group[=<id>] give the app and the widget extension an App Group, group.<app identifier> unless
|
|
18
|
+
named, so writeImage can share images; later runs keep it
|
|
14
19
|
`;
|
|
15
20
|
|
|
16
21
|
const FLAGS = { '--dry-run': 'dryRun', '--ios-only': 'iosOnly' };
|
|
22
|
+
const FILES = { '--font': 'fonts', '--asset': 'assets' };
|
|
17
23
|
const HELP = new Set(['help', '--help', '-h']);
|
|
18
24
|
|
|
25
|
+
/** The options of `setup`, or the argument it does not take and why. */
|
|
26
|
+
function parseOptions(args) {
|
|
27
|
+
const options = { fonts: [], assets: [] };
|
|
28
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
29
|
+
const [name, inline] = args[index].split(/=(.*)/s);
|
|
30
|
+
if (Object.hasOwn(FLAGS, args[index])) options[FLAGS[args[index]]] = true;
|
|
31
|
+
else if (name === '--app-group') options.appGroup = inline ?? true;
|
|
32
|
+
else if (Object.hasOwn(FILES, name)) {
|
|
33
|
+
const file = inline ?? args[(index += 1)];
|
|
34
|
+
if (!file) return { error: `${name} needs a file.` };
|
|
35
|
+
options[FILES[name]].push(file);
|
|
36
|
+
} else return { error: `Unknown option ${args[index]}.` };
|
|
37
|
+
}
|
|
38
|
+
return { options };
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
/** Runs the command and returns its exit status: 0 done, 1 something left to do or an error, 2 usage. */
|
|
20
42
|
export function main(argv, {
|
|
21
43
|
cwd = process.cwd(), env = process.env, platform = process.platform,
|
|
@@ -26,12 +48,15 @@ export function main(argv, {
|
|
|
26
48
|
out(USAGE);
|
|
27
49
|
return 0;
|
|
28
50
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
if (command !== 'setup') {
|
|
52
|
+
err(`Unknown command ${command}.\n\n${USAGE}`);
|
|
53
|
+
return 2;
|
|
54
|
+
}
|
|
55
|
+
const { options, error } = parseOptions(rest);
|
|
56
|
+
if (error) {
|
|
57
|
+
err(`${error}\n\n${USAGE}`);
|
|
32
58
|
return 2;
|
|
33
59
|
}
|
|
34
|
-
const options = Object.fromEntries(rest.map(arg => [FLAGS[arg], true]));
|
|
35
60
|
try {
|
|
36
61
|
const result = setup({ cwd, env, platform, ...options });
|
|
37
62
|
out(formatReport(result));
|
package/cli/setup.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { iosSteps } from './ios.mjs';
|
|
7
7
|
import { SetupError, display, jsonLike, parseJson, readText, step, tail, writeFile } from './steps.mjs';
|
|
8
|
+
import { widgetFiles } from './widget-files.mjs';
|
|
8
9
|
|
|
9
10
|
export { SetupError } from './steps.mjs';
|
|
10
11
|
|
|
@@ -12,7 +13,7 @@ export const CRATE = 'tauri-plugin-live-activity';
|
|
|
12
13
|
/** `default` reads; the others allow the commands that change activities. */
|
|
13
14
|
export const PERMISSIONS = [
|
|
14
15
|
'live-activity:default',
|
|
15
|
-
...['request-permissions', 'start', 'update', 'end', 'start-layout', 'update-layout', 'end-layout']
|
|
16
|
+
...['request-permissions', 'start', 'update', 'end', 'start-layout', 'update-layout', 'end-layout', 'write-image']
|
|
16
17
|
.map(command => `live-activity:allow-${command}`),
|
|
17
18
|
];
|
|
18
19
|
// The plugin's Android library needs API 26: Tauri's Jackson runtime fails below it.
|
|
@@ -21,12 +22,17 @@ const NPM_VERSION = JSON.parse(readFileSync(new URL('../package.json', import.me
|
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Sets up the app in `cwd` (its folder or its src-tauri folder) and returns the steps with their
|
|
24
|
-
* status, and notes for the person who runs it.
|
|
25
|
+
* status, and notes for the person who runs it. `fonts` and `assets` are files for the widget
|
|
26
|
+
* extension; `appGroup` is true or the name of an App Group. Throws SetupError when it cannot start.
|
|
25
27
|
*/
|
|
26
|
-
export function setup({
|
|
28
|
+
export function setup({
|
|
29
|
+
cwd = process.cwd(), env = process.env, dryRun = false, iosOnly = false, platform = process.platform,
|
|
30
|
+
fonts = [], assets = [], appGroup = undefined,
|
|
31
|
+
} = {}) {
|
|
32
|
+
const files = widgetFiles(cwd, { fonts, assets });
|
|
27
33
|
const app = findApp(cwd);
|
|
28
34
|
const plugin = findPlugin(app, env);
|
|
29
|
-
const context = { ...app, plugin, env, platform, show: path => display(cwd, path) };
|
|
35
|
+
const context = { ...app, plugin, env, platform, files, appGroup, show: path => display(cwd, path) };
|
|
30
36
|
const planned = [...(iosOnly ? [] : [capabilitiesStep(context), ...androidSteps(context)]), ...iosSteps(context)];
|
|
31
37
|
const steps = dryRun ? planned : planned.map(apply);
|
|
32
38
|
return { dryRun, version: plugin.version, steps: steps.map(({ effect, ...rest }) => rest), notes: notes(context) };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// The files that `setup --font` and `setup --asset` copy into the widget extension: fonts into
|
|
2
|
+
// LiveActivityWidget/Fonts, which the extension's Info.plist lists under UIAppFonts, and images into the
|
|
3
|
+
// extension's asset catalog, LiveActivityWidget/Assets.xcassets.
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
5
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
6
|
+
import { SetupError, parseJson, readText, step, writeFile } from './steps.mjs';
|
|
7
|
+
|
|
8
|
+
export const FONTS = 'Fonts';
|
|
9
|
+
export const CATALOG = 'Assets.xcassets';
|
|
10
|
+
const FONT_TYPES = new Set(['.ttf', '.otf', '.ttc']);
|
|
11
|
+
const IMAGE_TYPES = new Set(['.png', '.jpg', '.jpeg', '.pdf', '.svg']);
|
|
12
|
+
const VECTOR_TYPES = new Set(['.pdf', '.svg']);
|
|
13
|
+
// The rule of an image node's asset name, and a file name the bundle can carry.
|
|
14
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
15
|
+
const FILE_NAME = /^[A-Za-z0-9][A-Za-z0-9 ._@-]{0,127}$/;
|
|
16
|
+
const CATALOG_INFO = { info: { author: 'xcode', version: 1 } };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The fonts and images named on the command line, checked before anything is written: each exists, is a
|
|
20
|
+
* file of a kind the widget can use and has a name the bundle and a layout can carry.
|
|
21
|
+
*/
|
|
22
|
+
export function widgetFiles(cwd, { fonts = [], assets = [] }) {
|
|
23
|
+
const file = (given, kinds, what) => {
|
|
24
|
+
const source = resolve(cwd, given);
|
|
25
|
+
if (!existsSync(source) || !statSync(source).isFile()) throw new SetupError(`${given}: no such file.`);
|
|
26
|
+
const kind = extname(source).toLowerCase();
|
|
27
|
+
if (!kinds.has(kind)) throw new SetupError(`${given}: ${what} must be ${[...kinds].join(', ')}.`);
|
|
28
|
+
if (!FILE_NAME.test(basename(source))) {
|
|
29
|
+
throw new SetupError(`${given}: rename it to ASCII letters, digits, spaces, '.', '_', '@' and '-' first.`);
|
|
30
|
+
}
|
|
31
|
+
return { source, file: basename(source), kind };
|
|
32
|
+
};
|
|
33
|
+
const once = list => {
|
|
34
|
+
const repeated = list.find((item, index) => list.findIndex(other => other.file === item.file) !== index);
|
|
35
|
+
if (repeated) throw new SetupError(`${repeated.file} is named twice; the widget keeps one file of each name.`);
|
|
36
|
+
return list;
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
fonts: once(fonts.map(given => file(given, FONT_TYPES, 'a font'))),
|
|
40
|
+
assets: once(assets.map(given => {
|
|
41
|
+
const image = file(given, IMAGE_TYPES, 'an image');
|
|
42
|
+
const [, name, scale] = /^(.*?)(?:@([23])x)?$/.exec(basename(image.file, extname(image.file)));
|
|
43
|
+
if (!NAME.test(name)) throw new SetupError(`${given}: the asset name ${JSON.stringify(name)} must be 1 to 64 ASCII letters, digits, '.', '_' or '-'.`);
|
|
44
|
+
if (scale && VECTOR_TYPES.has(image.kind)) throw new SetupError(`${given}: a PDF or SVG image has one scale; drop the @${scale}x.`);
|
|
45
|
+
return { ...image, name, scale: scale && `${scale}x` };
|
|
46
|
+
})),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Copies `source` to `target`: created when absent, updated when its bytes differ, unchanged otherwise. */
|
|
51
|
+
function copyStep(show, source, target, detail) {
|
|
52
|
+
if (!existsSync(target)) return step('created', show(target), detail, copyEffect(source, target));
|
|
53
|
+
if (readFileSync(source).equals(readFileSync(target))) return step('unchanged', show(target));
|
|
54
|
+
return step('updated', show(target), detail, copyEffect(source, target));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const copyEffect = (source, target) => () => {
|
|
58
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
59
|
+
copyFileSync(source, target);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** The steps that copy the fonts into the widget's Fonts folder. */
|
|
63
|
+
export function fontSteps({ files, show }, widget) {
|
|
64
|
+
return files.fonts.map(({ source, file }) => {
|
|
65
|
+
const names = fontNames(readFileSync(source));
|
|
66
|
+
const detail = names ? `fontFamily: ${[...new Set([names.postScript, names.family].filter(Boolean))].map(name => JSON.stringify(name)).join(' or ')}` : '';
|
|
67
|
+
return copyStep(show, source, join(widget, FONTS, file), detail);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The font files the widget bundles after this run: those in its Fonts folder and those being copied there. */
|
|
72
|
+
export function bundledFonts({ files }, widget) {
|
|
73
|
+
const folder = join(widget, FONTS);
|
|
74
|
+
const present = existsSync(folder) ? readdirSync(folder).filter(name => FONT_TYPES.has(extname(name).toLowerCase())) : [];
|
|
75
|
+
return [...new Set([...present, ...files.fonts.map(({ file }) => file)])].sort();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The steps that put the images into the widget's asset catalog, one image set per asset name. */
|
|
79
|
+
export function assetSteps({ files, show }, widget) {
|
|
80
|
+
if (files.assets.length === 0) return [];
|
|
81
|
+
const catalog = join(widget, CATALOG);
|
|
82
|
+
const root = join(catalog, 'Contents.json');
|
|
83
|
+
const steps = existsSync(root) ? [] : [step('created', show(root), '', writeFile(root, catalogJson(CATALOG_INFO)))];
|
|
84
|
+
const sets = Map.groupBy(files.assets, ({ name }) => name);
|
|
85
|
+
for (const [name, images] of sets) {
|
|
86
|
+
const folder = join(catalog, `${name}.imageset`);
|
|
87
|
+
steps.push(...images.map(({ source, file }) => copyStep(show, source, join(folder, file), `the asset "${name}"`)));
|
|
88
|
+
steps.push(contentsStep(show, join(folder, 'Contents.json'), images));
|
|
89
|
+
}
|
|
90
|
+
return steps;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** An image set's Contents.json with an entry for each image; entries already there stay as they are. */
|
|
94
|
+
function contentsStep(show, path, images) {
|
|
95
|
+
const text = readText(path);
|
|
96
|
+
const current = text === undefined ? { images: [], ...CATALOG_INFO } : parseJson(text);
|
|
97
|
+
if (!Array.isArray(current?.images)) return step('todo', show(path), `not an image set's Contents.json; add ${images.map(({ file }) => file).join(', ')} to it in Xcode`);
|
|
98
|
+
const missing = images.filter(({ file }) => !current.images.some(entry => entry?.filename === file));
|
|
99
|
+
if (missing.length === 0) return step('unchanged', show(path));
|
|
100
|
+
const next = { ...current, images: [...current.images, ...missing.map(entry)] };
|
|
101
|
+
return step(text === undefined ? 'created' : 'updated', show(path), '', writeFile(path, catalogJson(next)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The entry of an image: a bitmap at its scale or for any scale, a PDF or SVG kept as vector data. */
|
|
105
|
+
function entry({ file, kind, scale }) {
|
|
106
|
+
const vector = VECTOR_TYPES.has(kind) ? { properties: { 'preserves-vector-representation': true } } : {};
|
|
107
|
+
return { filename: file, idiom: 'universal', ...vector, ...(scale && { scale }) };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** JSON as Xcode writes an asset catalog: two spaces, and a space before each colon. */
|
|
111
|
+
const catalogJson = value => `${JSON.stringify(value, null, 2).replace(/^(\s*"(?:[^"\\]|\\.)*"): /gm, '$1 : ')}\n`;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The family and PostScript names in the name table of a TrueType or OpenType font, for the report: they are
|
|
115
|
+
* what a style's `fontFamily` takes. Undefined for a collection or a file it cannot read.
|
|
116
|
+
*/
|
|
117
|
+
export function fontNames(bytes) {
|
|
118
|
+
try {
|
|
119
|
+
if (!['\0\u0001\0\0', 'OTTO', 'true'].includes(bytes.toString('latin1', 0, 4))) return undefined;
|
|
120
|
+
for (let index = 0; index < bytes.readUInt16BE(4); index += 1) {
|
|
121
|
+
const record = 12 + index * 16;
|
|
122
|
+
if (bytes.toString('latin1', record, record + 4) !== 'name') continue;
|
|
123
|
+
const offset = bytes.readUInt32BE(record + 8);
|
|
124
|
+
return names(bytes.subarray(offset, offset + bytes.readUInt32BE(record + 12)));
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (!(error instanceof RangeError)) throw error;
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Name IDs 1 (family), 16 (typographic family) and 6 (PostScript), Windows Unicode before Macintosh Roman. */
|
|
133
|
+
function names(table) {
|
|
134
|
+
const strings = table.readUInt16BE(4);
|
|
135
|
+
const found = {};
|
|
136
|
+
for (let index = 0; index < table.readUInt16BE(2); index += 1) {
|
|
137
|
+
const record = 6 + index * 12;
|
|
138
|
+
const [platform, , , id, length, offset] = [0, 2, 4, 6, 8, 10].map(at => table.readUInt16BE(record + at));
|
|
139
|
+
if (![1, 6, 16].includes(id) || (platform !== 3 && platform !== 1) || found[id]?.platform === 3) continue;
|
|
140
|
+
const raw = table.subarray(strings + offset, strings + offset + length);
|
|
141
|
+
if (raw.length !== length) throw new RangeError('name record outside the table');
|
|
142
|
+
const text = platform === 3 ? Buffer.from(raw).swap16().toString('utf16le') : raw.toString('latin1');
|
|
143
|
+
found[id] = { platform, text };
|
|
144
|
+
}
|
|
145
|
+
const family = (found[16] ?? found[1])?.text;
|
|
146
|
+
const postScript = found[6]?.text;
|
|
147
|
+
return family || postScript ? { family, postScript } : undefined;
|
|
148
|
+
}
|
package/cli/xcodegen.mjs
CHANGED
|
@@ -4,6 +4,12 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
|
|
5
5
|
export const SPEC_FILE = 'live-activity.yml';
|
|
6
6
|
export const WIDGET = 'LiveActivityWidget';
|
|
7
|
+
/** The extension's entitlements, next to its folder so that XcodeGen does not take them for a source. */
|
|
8
|
+
export const WIDGET_ENTITLEMENTS = `${WIDGET}.entitlements`;
|
|
9
|
+
/** The Info.plist key of the extension that names the App Group, for the plugin and the widget. */
|
|
10
|
+
export const APP_GROUP_KEY = 'TauriLiveActivityAppGroup';
|
|
11
|
+
/** The files of the widget folder that the app target compiles too. */
|
|
12
|
+
export const APP_SOURCES = ['LiveActivityActionIntent.swift', 'LiveActivityCustomRegistry.swift', 'LiveActivityCustomViews.swift'];
|
|
7
13
|
|
|
8
14
|
const DIGEST_LINE = /^# setup-digest: ([0-9a-f]{16})\n/m;
|
|
9
15
|
|
|
@@ -37,24 +43,45 @@ function children(body) {
|
|
|
37
43
|
return result;
|
|
38
44
|
}
|
|
39
45
|
|
|
46
|
+
/** The `path` under the `entitlements` key of a target's lines. */
|
|
47
|
+
function entitlementsPath(lines) {
|
|
48
|
+
const at = lines.findIndex(line => /^\s+entitlements:\s*$/.test(line));
|
|
49
|
+
if (at === -1) return undefined;
|
|
50
|
+
const indent = /^\s*/.exec(lines[at])[0].length;
|
|
51
|
+
for (const line of lines.slice(at + 1)) {
|
|
52
|
+
if (isContent(line) && /^\s*/.exec(line)[0].length <= indent) break;
|
|
53
|
+
const path = /^\s+path:\s*(.+?)\s*$/.exec(line)?.[1];
|
|
54
|
+
if (path) return unquote(path);
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
40
59
|
/**
|
|
41
|
-
* The project name, Tauri's app target (`<name>_iOS`) when it exists, the
|
|
42
|
-
* bundle identifier and a target that already is a widget extension.
|
|
60
|
+
* The project name, Tauri's app target (`<name>_iOS`) when it exists, the path of its entitlements, the
|
|
61
|
+
* setting groups, the first bundle identifier and a target that already is a widget extension.
|
|
43
62
|
*/
|
|
44
63
|
export function readProject(text) {
|
|
45
64
|
const lines = text.split('\n');
|
|
46
65
|
const name = unquote(/^name:\s*(.+?)\s*$/m.exec(text)?.[1]);
|
|
47
66
|
const targets = children(topLevel(lines, 'targets')?.body ?? []);
|
|
48
67
|
const isWidget = target => target.name === WIDGET || target.lines.some(line => line.includes('com.apple.widgetkit-extension'));
|
|
68
|
+
const app = targets.find(target => name && target.name === `${name}_iOS`);
|
|
49
69
|
return {
|
|
50
70
|
name,
|
|
51
|
-
appTarget:
|
|
71
|
+
appTarget: app?.name,
|
|
72
|
+
entitlements: app && entitlementsPath(app.lines),
|
|
52
73
|
settingGroups: children(topLevel(lines, 'settingGroups')?.body ?? []).map(group => group.name),
|
|
53
74
|
bundleId: unquote(/^\s*PRODUCT_BUNDLE_IDENTIFIER:\s*(\S+)\s*$/m.exec(text)?.[1]),
|
|
54
75
|
widget: targets.find(isWidget)?.name,
|
|
55
76
|
};
|
|
56
77
|
}
|
|
57
78
|
|
|
79
|
+
/** The App Group of a spec that setup wrote, so that a later run keeps it. */
|
|
80
|
+
export function appGroupOf(spec = '') {
|
|
81
|
+
const value = new RegExp(`^\\s+${APP_GROUP_KEY}: ("[^"\\n]*")$`, 'm').exec(spec)?.[1];
|
|
82
|
+
return value && JSON.parse(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
58
85
|
/**
|
|
59
86
|
* Adds `file` to the spec's `include` list. Status: `added` (with the new `text`), `present`, or
|
|
60
87
|
* `unsupported` when the list has a form this does not edit.
|
|
@@ -86,20 +113,36 @@ export function writtenBySetup(text) {
|
|
|
86
113
|
|
|
87
114
|
const quoted = value => JSON.stringify(String(value));
|
|
88
115
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
116
|
+
/**
|
|
117
|
+
* The included spec: the widget extension target, and the button intent, the custom views and the extension
|
|
118
|
+
* in the app target. `fonts` go to the extension's UIAppFonts. An `appGroup` goes to the entitlements of both
|
|
119
|
+
* targets, the app's at `appEntitlements`, and to the extension's Info.plist, where the plugin and the widget
|
|
120
|
+
* read it. XcodeGen merges the app target's part into the target of project.yml.
|
|
121
|
+
*/
|
|
122
|
+
export function widgetSpec({
|
|
123
|
+
pluginVersion, packagePath, appTarget, bundleId, appVersion, buildVersion, teamGroup, fonts = [], appGroup, appEntitlements,
|
|
124
|
+
}) {
|
|
91
125
|
const versions = appVersion === undefined ? [] : [
|
|
92
126
|
` CFBundleShortVersionString: ${quoted(appVersion)}`,
|
|
93
127
|
` CFBundleVersion: ${quoted(buildVersion ?? appVersion)}`,
|
|
94
128
|
];
|
|
129
|
+
const fontList = fonts.length === 0 ? [] : [' UIAppFonts:', ...fonts.map(font => ` - ${quoted(font)}`)];
|
|
130
|
+
const group = appGroup === undefined ? [] : [` ${APP_GROUP_KEY}: ${quoted(appGroup)}`];
|
|
131
|
+
const entitlements = path => (appGroup === undefined ? [] : [
|
|
132
|
+
' entitlements:',
|
|
133
|
+
` path: ${path}`,
|
|
134
|
+
' properties:',
|
|
135
|
+
` com.apple.security.application-groups: [${quoted(appGroup)}]`,
|
|
136
|
+
]);
|
|
95
137
|
const body = [
|
|
96
138
|
'packages:',
|
|
97
139
|
' LiveActivity:',
|
|
98
140
|
` path: ${quoted(packagePath)}`,
|
|
99
141
|
'targets:',
|
|
100
142
|
` ${quoted(appTarget)}:`,
|
|
101
|
-
` sources: [${WIDGET}
|
|
143
|
+
` sources: [${APP_SOURCES.map(file => `${WIDGET}/${file}`).join(', ')}]`,
|
|
102
144
|
` dependencies: [{ target: ${WIDGET} }]`,
|
|
145
|
+
...entitlements(quoted(appEntitlements)),
|
|
103
146
|
' settings:',
|
|
104
147
|
' base:',
|
|
105
148
|
' SWIFT_VERSION: "5.0"',
|
|
@@ -121,6 +164,9 @@ export function widgetSpec({ pluginVersion, packagePath, appTarget, bundleId, ap
|
|
|
121
164
|
' NSExtensionPointIdentifier: com.apple.widgetkit-extension',
|
|
122
165
|
' # startLayout answers CONFIGURATION_REQUIRED without an extension that declares this.',
|
|
123
166
|
' TauriLiveActivityLayout: 2',
|
|
167
|
+
...fontList,
|
|
168
|
+
...group,
|
|
169
|
+
...entitlements(WIDGET_ENTITLEMENTS),
|
|
124
170
|
' settings:',
|
|
125
171
|
...(teamGroup ? [' groups: [app]'] : []),
|
|
126
172
|
' base:',
|
package/dist-js/index.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export declare function updateLayout(input: LayoutUpdateInput): Promise<LayoutAc
|
|
|
25
25
|
export declare function endLayout(input: EndInput): Promise<LayoutActivityRecord>;
|
|
26
26
|
/** Reconcile plugin-owned layout records with the OS; `list` reports contract v1 activities. */
|
|
27
27
|
export declare function listLayout(): Promise<readonly LayoutActivityRecord[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Write a PNG that `image` nodes with the source `{ file: name }` show, replacing one of that name. The widget
|
|
30
|
+
* reads it each time it draws the activity, on start and on every update, so write the picture first and then
|
|
31
|
+
* update. At most 1 MiB and 1224 x 480 pixels (`PAYLOAD_TOO_LARGE` beyond). On iOS it needs the App Group
|
|
32
|
+
* that `setup --app-group` configures (`CONFIGURATION_REQUIRED` without one); on Android the first such image
|
|
33
|
+
* becomes the notification's large icon.
|
|
34
|
+
*/
|
|
35
|
+
export declare function writeImage(name: string, png: Uint8Array | ArrayBuffer): Promise<void>;
|
|
28
36
|
/**
|
|
29
37
|
* Receive button taps while this webview is alive; resolves to the function that stops listening.
|
|
30
38
|
* Listening uses Tauri's event permissions (`core:event:default`).
|
package/dist-js/index.js
CHANGED
|
@@ -46,6 +46,17 @@ export function endLayout(input) {
|
|
|
46
46
|
export function listLayout() {
|
|
47
47
|
return invoke('plugin:live-activity|list_layout', {});
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Write a PNG that `image` nodes with the source `{ file: name }` show, replacing one of that name. The widget
|
|
51
|
+
* reads it each time it draws the activity, on start and on every update, so write the picture first and then
|
|
52
|
+
* update. At most 1 MiB and 1224 x 480 pixels (`PAYLOAD_TOO_LARGE` beyond). On iOS it needs the App Group
|
|
53
|
+
* that `setup --app-group` configures (`CONFIGURATION_REQUIRED` without one); on Android the first such image
|
|
54
|
+
* becomes the notification's large icon.
|
|
55
|
+
*/
|
|
56
|
+
export function writeImage(name, png) {
|
|
57
|
+
const bytes = png instanceof Uint8Array ? png : new Uint8Array(png);
|
|
58
|
+
return invoke('plugin:live-activity|write_image', { input: { name, png: Array.from(bytes) } });
|
|
59
|
+
}
|
|
49
60
|
/**
|
|
50
61
|
* Receive button taps while this webview is alive; resolves to the function that stops listening.
|
|
51
62
|
* Listening uses Tauri's event permissions (`core:event:default`).
|
package/dist-js/layout.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LayoutButtonNode, LayoutDividerNode, LayoutGaugeNode, LayoutHStackNode, LayoutImageNode, LayoutNode, LayoutPathNode, LayoutProgressNode, LayoutSpacerNode, LayoutSymbolNode, LayoutTextNode, LayoutTimerTextNode, LayoutVStackNode, LayoutZStackNode } from './types.js';
|
|
1
|
+
import type { LayoutBound, LayoutButtonNode, LayoutCustomNode, LayoutDividerNode, LayoutGaugeNode, LayoutHStackNode, LayoutImageNode, LayoutImageSource, LayoutNode, LayoutPathNode, LayoutProgressNode, LayoutSpacerNode, LayoutSymbolNode, LayoutTextNode, LayoutTimerTextNode, LayoutVStackNode, LayoutZStackNode } from './types.js';
|
|
2
2
|
/** The members of a node that its builder does not take as arguments. */
|
|
3
3
|
type Options<N extends LayoutNode, Argument extends keyof N = never> = N extends unknown ? Omit<N, 'type' | Argument> : never;
|
|
4
4
|
/** Children from top to bottom. */
|
|
@@ -17,8 +17,11 @@ export declare function text(value: string, options?: Options<LayoutTextNode, 'v
|
|
|
17
17
|
export declare function bound(key: string, options?: Options<LayoutTextNode, 'value' | 'bind'>): LayoutTextNode;
|
|
18
18
|
/** An SF Symbol. */
|
|
19
19
|
export declare function symbol(name: string, options?: Options<LayoutSymbolNode, 'name'>): LayoutSymbolNode;
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* An image of the widget extension's asset catalog, by its name, or a PNG that the app wrote with
|
|
22
|
+
* `writeImage`: `image({ file: 'badge.png' })`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function image(source: string | LayoutImageSource, options?: Options<LayoutImageNode, 'source'>): LayoutImageNode;
|
|
22
25
|
/** A shape from SVG path data `d`, drawn in a `box` of `[width, height]`. */
|
|
23
26
|
export declare function path(d: string, box: readonly [number, number], options?: Options<LayoutPathNode, 'd' | 'box'>): LayoutPathNode;
|
|
24
27
|
/** A progress bar or ring for the number value of `key`. */
|
|
@@ -29,4 +32,12 @@ export declare function gauge(key: string, options?: Options<LayoutGaugeNode, 'b
|
|
|
29
32
|
export declare function timerText(start: string, end: string, options?: Options<LayoutTimerTextNode, 'start' | 'end'>): LayoutTimerTextNode;
|
|
30
33
|
/** A button around `child`; a tap reports `actionId` to `onAction`. */
|
|
31
34
|
export declare function button(actionId: string, child: LayoutNode, options?: Options<LayoutButtonNode, 'actionId' | 'child'>): LayoutButtonNode;
|
|
35
|
+
/** A SwiftUI view that the app registers under `name` in LiveActivityCustomViews.swift; `props` are its inputs. */
|
|
36
|
+
export declare function custom(name: string, options?: Options<LayoutCustomNode, 'name'>): LayoutCustomNode;
|
|
37
|
+
/**
|
|
38
|
+
* A style member, `layout.background` or `layout.keyline` that reads the value of `key` on every render,
|
|
39
|
+
* so an update can change it: `{ color: bind('tone') }`. Only `color`, `background`, `tint`, `opacity`,
|
|
40
|
+
* `size`, `weight` and `cornerRadius` can be bound, and the props of a `custom` node.
|
|
41
|
+
*/
|
|
42
|
+
export declare function bind(key: string): LayoutBound;
|
|
32
43
|
export {};
|
package/dist-js/layout.js
CHANGED
|
@@ -35,9 +35,12 @@ export function bound(key, options) {
|
|
|
35
35
|
export function symbol(name, options) {
|
|
36
36
|
return { type: 'symbol', name, ...given(options) };
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
/**
|
|
39
|
+
* An image of the widget extension's asset catalog, by its name, or a PNG that the app wrote with
|
|
40
|
+
* `writeImage`: `image({ file: 'badge.png' })`.
|
|
41
|
+
*/
|
|
42
|
+
export function image(source, options) {
|
|
43
|
+
return { type: 'image', source: typeof source === 'string' ? { asset: source } : { ...source }, ...given(options) };
|
|
41
44
|
}
|
|
42
45
|
/** A shape from SVG path data `d`, drawn in a `box` of `[width, height]`. */
|
|
43
46
|
export function path(d, box, options) {
|
|
@@ -59,3 +62,15 @@ export function timerText(start, end, options) {
|
|
|
59
62
|
export function button(actionId, child, options) {
|
|
60
63
|
return { type: 'button', actionId, child, ...given(options) };
|
|
61
64
|
}
|
|
65
|
+
/** A SwiftUI view that the app registers under `name` in LiveActivityCustomViews.swift; `props` are its inputs. */
|
|
66
|
+
export function custom(name, options) {
|
|
67
|
+
return { type: 'custom', name, ...given(options) };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A style member, `layout.background` or `layout.keyline` that reads the value of `key` on every render,
|
|
71
|
+
* so an update can change it: `{ color: bind('tone') }`. Only `color`, `background`, `tint`, `opacity`,
|
|
72
|
+
* `size`, `weight` and `cornerRadius` can be bound, and the props of a `custom` node.
|
|
73
|
+
*/
|
|
74
|
+
export function bind(key) {
|
|
75
|
+
return { bind: key };
|
|
76
|
+
}
|
package/dist-js/types.d.ts
CHANGED
|
@@ -127,6 +127,17 @@ export type LayoutColor = ColorName | HexColor | {
|
|
|
127
127
|
readonly light: HexColor;
|
|
128
128
|
readonly dark: HexColor;
|
|
129
129
|
};
|
|
130
|
+
/**
|
|
131
|
+
* A value key in place of a literal, as `layout.bind(key)` writes it. The member reads the value on
|
|
132
|
+
* every render, so an update can change it. The value must be what the member takes as a literal: a
|
|
133
|
+
* color name or a hex color (not a light and dark pair), a weight name, or a number in the member's range.
|
|
134
|
+
*/
|
|
135
|
+
export interface LayoutBound {
|
|
136
|
+
readonly bind: string;
|
|
137
|
+
}
|
|
138
|
+
/** A literal, or a value key that an update can change. */
|
|
139
|
+
export type LayoutBindable<T> = T | LayoutBound;
|
|
140
|
+
type FontWeight = 'ultraLight' | 'thin' | 'light' | 'regular' | 'medium' | 'semibold' | 'bold' | 'heavy' | 'black';
|
|
130
141
|
type Anchor = 'center' | 'leading' | 'trailing' | 'top' | 'bottom' | 'topLeading' | 'topTrailing' | 'bottomLeading' | 'bottomTrailing';
|
|
131
142
|
/** At least one member. Sizes are points from 0 to 1024. */
|
|
132
143
|
export interface LayoutFrame {
|
|
@@ -138,12 +149,15 @@ export interface LayoutFrame {
|
|
|
138
149
|
readonly maxHeight?: number | 'infinity';
|
|
139
150
|
readonly alignment?: Anchor;
|
|
140
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* `weight`, `color`, `background`, `cornerRadius`, `opacity`, `tint` and `size` may be bound to a value
|
|
154
|
+
* with `layout.bind(key)`. The other members are fixed at start.
|
|
155
|
+
*/
|
|
141
156
|
interface StyleFields {
|
|
142
|
-
readonly weight?:
|
|
143
|
-
readonly design?: 'default' | 'rounded' | 'serif' | 'monospaced';
|
|
157
|
+
readonly weight?: LayoutBindable<FontWeight>;
|
|
144
158
|
readonly monospacedDigit?: boolean;
|
|
145
159
|
/** Foreground color. */
|
|
146
|
-
readonly color?: LayoutColor
|
|
160
|
+
readonly color?: LayoutBindable<LayoutColor>;
|
|
147
161
|
/** Integer from 1 to 10. */
|
|
148
162
|
readonly lineLimit?: number;
|
|
149
163
|
/** From 0.1 to 1. */
|
|
@@ -153,22 +167,34 @@ interface StyleFields {
|
|
|
153
167
|
/** Points from 0 to 64: one number for every edge, or `[top, leading, bottom, trailing]`. */
|
|
154
168
|
readonly padding?: number | readonly [number, number, number, number];
|
|
155
169
|
readonly frame?: LayoutFrame;
|
|
156
|
-
readonly background?: LayoutColor
|
|
170
|
+
readonly background?: LayoutBindable<LayoutColor>;
|
|
157
171
|
/** Points from 0 to 64. */
|
|
158
|
-
readonly cornerRadius?: number
|
|
172
|
+
readonly cornerRadius?: LayoutBindable<number>;
|
|
159
173
|
/** From 0 to 1. */
|
|
160
|
-
readonly opacity?: number
|
|
174
|
+
readonly opacity?: LayoutBindable<number>;
|
|
161
175
|
/** Tint of buttons, progress views and gauges. */
|
|
162
|
-
readonly tint?: LayoutColor
|
|
176
|
+
readonly tint?: LayoutBindable<LayoutColor>;
|
|
163
177
|
readonly buttonStyle?: 'automatic' | 'bordered' | 'borderedProminent' | 'plain';
|
|
164
178
|
}
|
|
165
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* At least one member. `font`, a system text style, and `size`, points from 6 to 96, exclude each other.
|
|
181
|
+
* `fontFamily`, the PostScript or family name of a font that the widget extension bundles (`setup --font`),
|
|
182
|
+
* and `design`, a design of the system font, exclude each other too.
|
|
183
|
+
*/
|
|
166
184
|
export type LayoutStyle = StyleFields & ({
|
|
167
185
|
readonly font?: 'largeTitle' | 'title' | 'title2' | 'title3' | 'headline' | 'subheadline' | 'body' | 'callout' | 'footnote' | 'caption' | 'caption2';
|
|
168
186
|
readonly size?: never;
|
|
169
187
|
} | {
|
|
170
|
-
readonly size?: number
|
|
188
|
+
readonly size?: LayoutBindable<number>;
|
|
171
189
|
readonly font?: never;
|
|
190
|
+
}) & ({
|
|
191
|
+
readonly design?: 'default' | 'rounded' | 'serif' | 'monospaced';
|
|
192
|
+
readonly fontFamily?: never;
|
|
193
|
+
}
|
|
194
|
+
/** 1 to 64 ASCII letters, digits, spaces, `.`, `_` and `-`, starting with a letter or digit. */
|
|
195
|
+
| {
|
|
196
|
+
readonly fontFamily?: string;
|
|
197
|
+
readonly design?: never;
|
|
172
198
|
});
|
|
173
199
|
/** Members every node may carry. A condition names a value key; `if` and `unless` exclude each other. */
|
|
174
200
|
type NodeFields = {
|
|
@@ -229,12 +255,20 @@ export type LayoutSymbolNode = NodeFields & {
|
|
|
229
255
|
/** Key of a number value: the symbol's variable value, from 0 to 1. */
|
|
230
256
|
readonly variableBind?: string;
|
|
231
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* `asset`: an image in the widget extension's asset catalog. `file`: a PNG that the app wrote with
|
|
260
|
+
* `writeImage(file, png)`. A name is 1 to 64 ASCII letters, digits, `.`, `_` and `-`, starting with a letter or digit.
|
|
261
|
+
*/
|
|
262
|
+
export type LayoutImageSource = {
|
|
263
|
+
readonly asset: string;
|
|
264
|
+
readonly file?: never;
|
|
265
|
+
} | {
|
|
266
|
+
readonly file: string;
|
|
267
|
+
readonly asset?: never;
|
|
268
|
+
};
|
|
232
269
|
export type LayoutImageNode = NodeFields & {
|
|
233
270
|
readonly type: 'image';
|
|
234
|
-
|
|
235
|
-
readonly source: {
|
|
236
|
-
readonly asset: string;
|
|
237
|
-
};
|
|
271
|
+
readonly source: LayoutImageSource;
|
|
238
272
|
readonly resizable?: boolean;
|
|
239
273
|
readonly contentMode?: 'fit' | 'fill';
|
|
240
274
|
};
|
|
@@ -279,7 +313,24 @@ export type LayoutButtonNode = NodeFields & {
|
|
|
279
313
|
readonly actionId: string;
|
|
280
314
|
readonly child: LayoutNode;
|
|
281
315
|
};
|
|
282
|
-
|
|
316
|
+
/**
|
|
317
|
+
* A SwiftUI view that the app registers under `name` in LiveActivityCustomViews.swift of its widget extension.
|
|
318
|
+
* A name without a view draws nothing and is reported in `degradedFeatures` as `layout.custom.<name>`; Android
|
|
319
|
+
* shows no custom view (`layout.custom`).
|
|
320
|
+
*/
|
|
321
|
+
export type LayoutCustomNode = NodeFields & {
|
|
322
|
+
readonly type: 'custom';
|
|
323
|
+
/** 1 to 64 ASCII letters, digits, `.`, `_` and `-`, starting with a letter or digit. */
|
|
324
|
+
readonly name: string;
|
|
325
|
+
/**
|
|
326
|
+
* 1 to 16 inputs of the view under value-key names: text of at most 200 code points, a number, a boolean, or
|
|
327
|
+
* `layout.bind(key)` for a value that each update can change.
|
|
328
|
+
*/
|
|
329
|
+
readonly props?: {
|
|
330
|
+
readonly [name: string]: LayoutBindable<LayoutValue>;
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
export type LayoutNode = LayoutVStackNode | LayoutHStackNode | LayoutZStackNode | LayoutSpacerNode | LayoutDividerNode | LayoutTextNode | LayoutSymbolNode | LayoutImageNode | LayoutPathNode | LayoutProgressNode | LayoutGaugeNode | LayoutTimerTextNode | LayoutButtonNode | LayoutCustomNode;
|
|
283
334
|
/** At least one region, each of at most 12 nodes. */
|
|
284
335
|
export interface LayoutIslandExpanded {
|
|
285
336
|
readonly leading?: LayoutNode;
|
|
@@ -303,9 +354,9 @@ export interface Layout {
|
|
|
303
354
|
readonly lockScreen: LayoutNode;
|
|
304
355
|
readonly island?: LayoutIsland;
|
|
305
356
|
/** Tint behind the lock screen presentation. */
|
|
306
|
-
readonly background?: LayoutColor
|
|
357
|
+
readonly background?: LayoutBindable<LayoutColor>;
|
|
307
358
|
/** Tint of the Dynamic Island keyline. */
|
|
308
|
-
readonly keyline?: LayoutColor
|
|
359
|
+
readonly keyline?: LayoutBindable<LayoutColor>;
|
|
309
360
|
}
|
|
310
361
|
export interface LayoutAndroidOptions {
|
|
311
362
|
/** Lock screen visibility of the notification. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tauri-plugin-live-activity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Tauri 2 plugin for iOS Live Activities (ActivityKit and Dynamic Island) and Android Live Updates with ongoing notification fallback",
|
|
5
5
|
"author": "1eedaegon",
|
|
6
6
|
"type": "module",
|