tauri-plugin-live-activity 0.7.0 → 0.7.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 +1 -1
- package/README.md +1 -1
- package/dist-js/index.d.ts +6 -0
- package/dist-js/index.js +99 -2
- package/package.json +2 -2
package/README.ko.md
CHANGED
|
@@ -200,7 +200,7 @@ await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
|
200
200
|
|
|
201
201
|
시작 요청에 `scheduled: { at, alert }`를 주면 나중에 시작하고(iOS 26), `ios: { transient: true }`이면 일시적 액티비티가 됩니다(iOS 18). 레이아웃은 시작한 모습 그대로이고, 갱신마다 모든 값을 더 높은 revision으로 다시 보냅니다. 탭은
|
|
202
202
|
`onAction`으로, 푸시 토큰과 푸시된 내용은 `onPushToken`, `onPushToStartToken`, `onUpdated`로, 앱이 호출하지 않은
|
|
203
|
-
액티비티의 변화는 `onState`, `onStarted`, `onOpened`(Android: 액티비티의 알림으로 앱을 연
|
|
203
|
+
액티비티의 변화는 `onState`, `onStarted`, `onOpened`(Android: 액티비티의 알림으로 앱을 연 일. 앱을 실행시킨 열림도 페이지가 구독할 때까지 보관됩니다), `onPermissions`로 옵니다.
|
|
204
204
|
|
|
205
205
|
스냅샷에는 `relevance`(앱의 여러 액티비티 중 Dynamic Island가 무엇을 보일지 정하는 점수)와 `android`
|
|
206
206
|
콘텐츠(레이아웃 투영 대신 Android 방식 그대로 쓰는 알림: 구간이 있는 진행 막대, 지표, 칩 텍스트)를 넣을 수
|
package/README.md
CHANGED
|
@@ -203,7 +203,7 @@ A start may also carry `scheduled: { at, alert }` to begin later (iOS 26), and `
|
|
|
203
203
|
activity (iOS 18). The layout stays as it started; each update sends every value again, with a higher revision. Taps come to
|
|
204
204
|
`onAction`, push tokens and pushed content to `onPushToken`, `onPushToStartToken` and `onUpdated`, and what happens
|
|
205
205
|
to an activity outside the app's calls to `onState`, `onStarted`, `onOpened` (Android: the person opened the app from an
|
|
206
|
-
activity's notification) and `onPermissions`.
|
|
206
|
+
activity's notification; the opening that launched the app waits for the page) and `onPermissions`.
|
|
207
207
|
|
|
208
208
|
A snapshot may also carry a `relevance`, which decides which of the app's activities the Dynamic Island shows, and
|
|
209
209
|
an `android` content, the notification in Android's own terms (a segmented progress, metrics, the chip text) in
|
package/dist-js/index.d.ts
CHANGED
|
@@ -88,6 +88,12 @@ export declare function onState(handler: (event: StateEvent) => void): Promise<U
|
|
|
88
88
|
* Receive each opening of the app from the notification of an activity (Android): which activity the person
|
|
89
89
|
* opened it from, and by which action when it was one that opens a URL. The URL itself comes to the app as any deep
|
|
90
90
|
* link. iOS hands the URL to the app and reports nothing here.
|
|
91
|
+
*
|
|
92
|
+
* The opening that launched the app is reported before the page has loaded, so the plugin keeps every opening until
|
|
93
|
+
* a page has handed it to a handler, the newest 16. The handler first gets those that waited, oldest first, and
|
|
94
|
+
* then each one as it comes, each once: subscribe when the page starts. The handlers of a page share the openings;
|
|
95
|
+
* one that subscribes later gets what is handed over from then on. Rejects, subscribed to nothing, when the plugin
|
|
96
|
+
* does not answer the first question for what waits.
|
|
91
97
|
*/
|
|
92
98
|
export declare function onOpened(handler: (event: OpenedEvent) => void): Promise<UnlistenFn>;
|
|
93
99
|
/**
|
package/dist-js/index.js
CHANGED
|
@@ -156,13 +156,110 @@ export function onStarted(handler) {
|
|
|
156
156
|
export function onState(handler) {
|
|
157
157
|
return listen('live-activity://state', event => handler(event.payload));
|
|
158
158
|
}
|
|
159
|
+
/** The handlers of this page for openings. They share one subscription. */
|
|
160
|
+
const openingHandlers = new Set();
|
|
161
|
+
/** The page's subscription to the event that says an opening came, while the page has handlers. */
|
|
162
|
+
let openingEvents;
|
|
163
|
+
/** The questions of this page to the plugin, one after another, so that the openings keep their order. */
|
|
164
|
+
let openingTakes = Promise.resolve();
|
|
165
|
+
/** The number of the newest opening that this page has handed to its handlers. */
|
|
166
|
+
let openingsHanded = 0;
|
|
167
|
+
/** The number up to which this page has told the plugin to let the openings go. */
|
|
168
|
+
let openingsLetGo = 0;
|
|
169
|
+
/**
|
|
170
|
+
* Hands `opening` to `handler`. A handler that throws is reported, as the browser reports a listener that throws,
|
|
171
|
+
* and keeps the opening from nobody else.
|
|
172
|
+
*/
|
|
173
|
+
function hand(handler, opening) {
|
|
174
|
+
try {
|
|
175
|
+
handler(opening);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
const report = globalThis.reportError;
|
|
179
|
+
if (typeof report === 'function')
|
|
180
|
+
report(error);
|
|
181
|
+
else
|
|
182
|
+
console.error(error);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Asks the plugin for the openings that wait and hands each new one to the handlers there are, until none is left.
|
|
187
|
+
* Every question also says how far this page has handed them over, and the plugin lets those go. So an opening
|
|
188
|
+
* that no handler got stays with the plugin, for a handler that comes later or for the page that loads next.
|
|
189
|
+
*/
|
|
190
|
+
function takeOpenings() {
|
|
191
|
+
const taken = openingTakes.then(async () => {
|
|
192
|
+
let answered = false;
|
|
193
|
+
// With nobody to hand to, the plugin is only told what it may let go.
|
|
194
|
+
while (openingHandlers.size > 0 || openingsLetGo < openingsHanded) {
|
|
195
|
+
const handed = openingsHanded;
|
|
196
|
+
let waiting;
|
|
197
|
+
try {
|
|
198
|
+
waiting = await invoke('plugin:live-activity|openings', { taken: handed });
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
// Once the plugin has answered, a question that fails only leaves it for the next one to say what was
|
|
202
|
+
// handed over.
|
|
203
|
+
if (answered)
|
|
204
|
+
return;
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
answered = true;
|
|
208
|
+
openingsLetGo = Math.max(openingsLetGo, handed);
|
|
209
|
+
const first = waiting.through - waiting.openings.length + 1;
|
|
210
|
+
for (const [index, opening] of waiting.openings.entries()) {
|
|
211
|
+
// The plugin answers what comes after `handed`. One that this page has handed over is not handed again.
|
|
212
|
+
if (first + index <= openingsHanded)
|
|
213
|
+
continue;
|
|
214
|
+
if (openingHandlers.size === 0)
|
|
215
|
+
break;
|
|
216
|
+
// A handler that another one unsubscribed meanwhile is not called.
|
|
217
|
+
for (const handler of [...openingHandlers])
|
|
218
|
+
if (openingHandlers.has(handler))
|
|
219
|
+
hand(handler, opening);
|
|
220
|
+
openingsHanded = first + index;
|
|
221
|
+
}
|
|
222
|
+
if (openingsHanded === handed)
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
// A question that failed does not stop the next one: what it left still waits in the plugin.
|
|
227
|
+
openingTakes = taken.catch(() => undefined);
|
|
228
|
+
return taken;
|
|
229
|
+
}
|
|
159
230
|
/**
|
|
160
231
|
* Receive each opening of the app from the notification of an activity (Android): which activity the person
|
|
161
232
|
* opened it from, and by which action when it was one that opens a URL. The URL itself comes to the app as any deep
|
|
162
233
|
* link. iOS hands the URL to the app and reports nothing here.
|
|
234
|
+
*
|
|
235
|
+
* The opening that launched the app is reported before the page has loaded, so the plugin keeps every opening until
|
|
236
|
+
* a page has handed it to a handler, the newest 16. The handler first gets those that waited, oldest first, and
|
|
237
|
+
* then each one as it comes, each once: subscribe when the page starts. The handlers of a page share the openings;
|
|
238
|
+
* one that subscribes later gets what is handed over from then on. Rejects, subscribed to nothing, when the plugin
|
|
239
|
+
* does not answer the first question for what waits.
|
|
163
240
|
*/
|
|
164
|
-
export function onOpened(handler) {
|
|
165
|
-
|
|
241
|
+
export async function onOpened(handler) {
|
|
242
|
+
// A function may subscribe twice: each subscription is its own and ends alone.
|
|
243
|
+
const subscribed = (event) => handler(event);
|
|
244
|
+
const leave = () => {
|
|
245
|
+
if (!openingHandlers.delete(subscribed) || openingHandlers.size > 0)
|
|
246
|
+
return;
|
|
247
|
+
const events = openingEvents;
|
|
248
|
+
openingEvents = undefined;
|
|
249
|
+
void events?.then(unlisten => unlisten()).catch(() => undefined);
|
|
250
|
+
};
|
|
251
|
+
openingHandlers.add(subscribed);
|
|
252
|
+
try {
|
|
253
|
+
// The event says that an opening came. The plugin hands it over when it is asked.
|
|
254
|
+
openingEvents ??= listen('live-activity://opened', () => { void takeOpenings().catch(() => undefined); });
|
|
255
|
+
await openingEvents;
|
|
256
|
+
await takeOpenings();
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
leave();
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
return leave;
|
|
166
263
|
}
|
|
167
264
|
/**
|
|
168
265
|
* Receive the permissions after the person changed them in Settings (iOS): Live Activities turned on or off, or
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tauri-plugin-live-activity",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p examples/demo/tsconfig.json",
|
|
35
35
|
"test": "npm run build && npm run test:contracts && npm run test:api && npm run test:jsx && npm run test:react && npm run test:demo && npm run test:setup",
|
|
36
36
|
"test:contracts": "node --test --experimental-test-coverage \"--test-coverage-include=tools/validate-request.mjs\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 tests/requests.test.mjs tests/layout-requests.test.mjs tests/contract-sync.test.mjs tests/android-liveupdate.test.mjs tests/android-contents.test.mjs tests/ci.test.mjs tests/ci-cache.test.mjs tests/spec-coverage.test.mjs",
|
|
37
|
-
"test:api": "node --test --experimental-test-coverage \"--test-coverage-include=dist-js/*.js\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 tests/api.test.mjs",
|
|
37
|
+
"test:api": "node --test --experimental-test-coverage \"--test-coverage-include=dist-js/*.js\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 tests/api.test.mjs tests/api-reload.test.mjs",
|
|
38
38
|
"test:jsx": "node --experimental-strip-types --test --experimental-test-coverage \"--test-coverage-include=dist-js/jsx/*.js\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 tests/jsx.test.mjs",
|
|
39
39
|
"test:react": "node --test --experimental-test-coverage \"--test-coverage-include=dist-js/react/*.js\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 tests/react.test.mjs",
|
|
40
40
|
"test:demo": "node --experimental-strip-types --test --experimental-test-coverage \"--test-coverage-include=examples/demo/src/*.ts\" \"--test-coverage-exclude=examples/demo/tests/**\" --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 examples/demo/tests/self-test.test.mjs examples/demo/tests/ui-state.test.mjs examples/demo/tests/layouts.test.mjs examples/demo/tests/setup.test.mjs",
|