@lingxia/types 0.9.0 → 0.10.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/dist/app/index.d.ts +52 -2
- package/dist/app/index.d.ts.map +1 -1
- package/dist/generated/i18n.d.ts +1 -1
- package/dist/generated/i18n.d.ts.map +1 -1
- package/dist/generated/i18n.js +18 -25
- package/dist/generated/i18n.js.map +1 -1
- package/dist/index.d.ts +191 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/media/index.d.ts +66 -7
- package/dist/media/index.d.ts.map +1 -1
- package/dist/system/index.d.ts +1 -5
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +1 -1
- package/dist/transfer/index.d.ts +65 -20
- package/dist/transfer/index.d.ts.map +1 -1
- package/dist/ui/index.d.ts +36 -49
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app/index.ts +57 -2
- package/src/generated/i18n.ts +18 -25
- package/src/index.ts +216 -15
- package/src/media/index.ts +75 -7
- package/src/system/index.ts +1 -6
- package/src/transfer/index.ts +80 -22
- package/src/ui/index.ts +42 -57
package/src/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ import type {
|
|
|
32
32
|
PageConfig,
|
|
33
33
|
PageInstance,
|
|
34
34
|
Surface,
|
|
35
|
+
SurfaceHandle,
|
|
35
36
|
} from './app';
|
|
36
37
|
|
|
37
38
|
import type {
|
|
@@ -65,8 +66,14 @@ import type {
|
|
|
65
66
|
} from './file';
|
|
66
67
|
|
|
67
68
|
import type {
|
|
69
|
+
AppDownloadOptions,
|
|
70
|
+
AppDownloadResult,
|
|
71
|
+
DownloadDestination,
|
|
68
72
|
DownloadOptions,
|
|
73
|
+
DownloadResultForDestination,
|
|
69
74
|
DownloadTask,
|
|
75
|
+
DownloadsDownloadOptions,
|
|
76
|
+
DownloadsDownloadResult,
|
|
70
77
|
UploadOptions,
|
|
71
78
|
UploadTask,
|
|
72
79
|
} from './transfer';
|
|
@@ -83,7 +90,6 @@ import type {
|
|
|
83
90
|
|
|
84
91
|
import type {
|
|
85
92
|
SystemSettingInfo,
|
|
86
|
-
OpenURLOptions,
|
|
87
93
|
} from './system';
|
|
88
94
|
|
|
89
95
|
import type { NavigateToLxAppOptions } from './navigator';
|
|
@@ -96,7 +102,7 @@ import type {
|
|
|
96
102
|
CompressImageOptions,
|
|
97
103
|
CompressImageResult,
|
|
98
104
|
CompressVideoOptions,
|
|
99
|
-
|
|
105
|
+
CompressVideoTask,
|
|
100
106
|
GetVideoInfoOptions,
|
|
101
107
|
VideoInfo,
|
|
102
108
|
ExtractVideoThumbnailOptions,
|
|
@@ -134,24 +140,213 @@ import type {
|
|
|
134
140
|
RemoveTabBarBadgeOptions,
|
|
135
141
|
SetTabBarStyleOptions,
|
|
136
142
|
SetTabBarItemOptions,
|
|
137
|
-
|
|
143
|
+
SurfaceEdge,
|
|
144
|
+
SurfaceFloatPosition,
|
|
145
|
+
OverlaySurfaceSize,
|
|
146
|
+
SurfaceContext,
|
|
138
147
|
CapsuleRect,
|
|
139
148
|
} from './ui';
|
|
140
149
|
|
|
141
|
-
|
|
150
|
+
interface WindowSurfaceSize {
|
|
151
|
+
/** Initial window width in logical pixels. */
|
|
152
|
+
width?: number;
|
|
153
|
+
/** Initial window height in logical pixels. */
|
|
154
|
+
height?: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Spec for {@link Lx.openSurface}. A discriminated union keyed by source so a
|
|
159
|
+
* page name and a declared surface id never collide (each is its own string
|
|
160
|
+
* space, separately type-checkable).
|
|
161
|
+
*
|
|
162
|
+
* - `{ page }` — one of this lxapp's own pages, by name, arranged as `as`
|
|
163
|
+
* (`aside` is a companion of the main; `float` is a popup; `window` is a bare
|
|
164
|
+
* desktop window, which rejects on mobile). `edge` applies to `aside`,
|
|
165
|
+
* `position` applies to `float`, and `size` is a Host-clamped hint. They are
|
|
166
|
+
* fixed at open (re-open to change).
|
|
167
|
+
*
|
|
168
|
+
* `aside` is **size-class adaptive**, not a fixed form: only on `medium` /
|
|
169
|
+
* `expanded` (room to sit alongside) does it dock and split beside the main at
|
|
170
|
+
* `edge` as a sidebar/split panel. On `compact` (phone, or a folded foldable)
|
|
171
|
+
* there is no room to dock, so the same surface presents **full-screen** —
|
|
172
|
+
* pushed over the main and dismissed by the host back affordance / edge swipe
|
|
173
|
+
* (a drill-in), never a docked panel. So one declaration reads as a side panel
|
|
174
|
+
* on large screens and a full-screen drill-in on small ones. For a destination
|
|
175
|
+
* that should stay switchable on phones, declare it `role: main` instead.
|
|
176
|
+
*
|
|
177
|
+
* `float` is a popup layered above the main at `position` (like a dialog); it
|
|
178
|
+
* takes no layout space. The SDK gives it **no chrome of its own — there is no
|
|
179
|
+
* built-in close button**: the lxapp owns the popup UI and dismisses it by
|
|
180
|
+
* calling `surface.close()` (or `.hide()`). A float sized to the full container
|
|
181
|
+
* (`size: { width: '100%', height: '100%' }`) presents immersively on mobile
|
|
182
|
+
* (system bars hidden) and is likewise chrome-less — draw your own close
|
|
183
|
+
* affordance. (iOS retains a silent left-edge swipe as a last-resort escape so a
|
|
184
|
+
* full-screen float can never trap the user; don't rely on it as the primary
|
|
185
|
+
* dismissal.)
|
|
186
|
+
* - `{ surface }` — a surface declared in `lingxia.yaml` `surfaces:`, by id
|
|
187
|
+
* (e.g. `'terminal'`, `'ai-assistant'`). Form, position, and startup data come
|
|
188
|
+
* from the declaration.
|
|
189
|
+
* - `{ url }` — an `http(s)://` or `lingxia://` url, shown in the in-app chromed
|
|
190
|
+
* browser (always with an address bar — never a chromeless embed). Without
|
|
191
|
+
* `as` it opens as a main browser tab (host chrome, no handle). With
|
|
192
|
+
* `as: 'aside'` it docks an `http(s)://` page beside the main as a single
|
|
193
|
+
* browser aside (its own chrome + close, returns a closable handle); `edge`
|
|
194
|
+
* defaults to `'right'` and `size` is a host-clamped preferred size. At most
|
|
195
|
+
* one browser aside per window — a new one replaces the existing one.
|
|
196
|
+
*/
|
|
197
|
+
export type OpenPageSurfaceSpec =
|
|
198
|
+
| {
|
|
199
|
+
page: string;
|
|
200
|
+
as: 'aside';
|
|
201
|
+
edge?: SurfaceEdge;
|
|
202
|
+
size?: OverlaySurfaceSize;
|
|
203
|
+
query?: Record<string, unknown>;
|
|
204
|
+
position?: never;
|
|
205
|
+
surface?: never;
|
|
206
|
+
url?: never;
|
|
207
|
+
}
|
|
208
|
+
| {
|
|
209
|
+
page: string;
|
|
210
|
+
/**
|
|
211
|
+
* A chrome-less popup above the main: the lxapp draws its own UI and close
|
|
212
|
+
* affordance — there is no SDK-provided close button (see
|
|
213
|
+
* {@link OpenPageSurfaceSpec}).
|
|
214
|
+
*/
|
|
215
|
+
as: 'float';
|
|
216
|
+
position?: SurfaceFloatPosition;
|
|
217
|
+
size?: OverlaySurfaceSize;
|
|
218
|
+
query?: Record<string, unknown>;
|
|
219
|
+
edge?: never;
|
|
220
|
+
surface?: never;
|
|
221
|
+
url?: never;
|
|
222
|
+
}
|
|
223
|
+
| {
|
|
224
|
+
page: string;
|
|
225
|
+
as: 'window';
|
|
226
|
+
size?: WindowSurfaceSize;
|
|
227
|
+
query?: Record<string, unknown>;
|
|
228
|
+
edge?: never;
|
|
229
|
+
position?: never;
|
|
230
|
+
surface?: never;
|
|
231
|
+
url?: never;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export interface OpenDeclaredSurfaceSpec {
|
|
235
|
+
surface: string;
|
|
236
|
+
page?: never;
|
|
237
|
+
url?: never;
|
|
238
|
+
as?: never;
|
|
239
|
+
edge?: never;
|
|
240
|
+
position?: never;
|
|
241
|
+
size?: never;
|
|
242
|
+
query?: never;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface OpenUrlTabSpec {
|
|
246
|
+
url: string;
|
|
247
|
+
as?: never;
|
|
248
|
+
page?: never;
|
|
249
|
+
surface?: never;
|
|
250
|
+
edge?: never;
|
|
251
|
+
position?: never;
|
|
252
|
+
size?: never;
|
|
253
|
+
query?: never;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface OpenUrlAsideSpec {
|
|
257
|
+
url: string;
|
|
258
|
+
as: 'aside';
|
|
259
|
+
edge?: SurfaceEdge;
|
|
260
|
+
size?: OverlaySurfaceSize;
|
|
261
|
+
page?: never;
|
|
262
|
+
surface?: never;
|
|
263
|
+
position?: never;
|
|
264
|
+
query?: never;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export type OpenSurfaceSpec =
|
|
268
|
+
| OpenPageSurfaceSpec
|
|
269
|
+
| OpenDeclaredSurfaceSpec
|
|
270
|
+
| OpenUrlTabSpec
|
|
271
|
+
| OpenUrlAsideSpec;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Runtime control of the menu-bar (macOS) / system-tray (Windows) status item.
|
|
275
|
+
* The tray is declared in `lingxia.yaml` (`tray:`); these update its dynamic
|
|
276
|
+
* content at runtime.
|
|
277
|
+
*
|
|
278
|
+
* **Desktop only.** Mobile platforms have no tray, so every method here is a
|
|
279
|
+
* no-op there (it never throws) — safe to call from portable code. For an
|
|
280
|
+
* app-icon badge that *is* cross-platform (including mobile), use
|
|
281
|
+
* {@link HostAppApi.setBadge}.
|
|
282
|
+
*/
|
|
283
|
+
export interface TrayMenuItem {
|
|
284
|
+
label: string;
|
|
285
|
+
/** Invoked when this item is clicked. */
|
|
286
|
+
onClick?: () => void;
|
|
287
|
+
enabled?: boolean;
|
|
288
|
+
checked?: boolean;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface TrayMenuSeparator {
|
|
292
|
+
separator: true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface TrayApi {
|
|
296
|
+
/** Replace the status-item icon (a resource path). */
|
|
297
|
+
setIcon(icon: string): void;
|
|
298
|
+
/** Set the text shown beside the icon (macOS). Pass `null`/empty to clear. */
|
|
299
|
+
setTitle(text: string | null): void;
|
|
300
|
+
/** Set the badge — e.g. an unread count. Pass `null`/empty to clear. */
|
|
301
|
+
setBadge(value: string | number | null): void;
|
|
142
302
|
/**
|
|
143
|
-
*
|
|
303
|
+
* Replace the right-click dropdown menu. There is no default menu — provide
|
|
304
|
+
* your own items (e.g. `{ label: 'Quit', onClick: () => lx.app.exit() }`).
|
|
144
305
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
306
|
+
* The menu is a snapshot: to change an item's `checked`/`enabled`/`label`
|
|
307
|
+
* state, call `setMenu` again with the full updated array. There is no
|
|
308
|
+
* per-item mutation API.
|
|
309
|
+
*/
|
|
310
|
+
setMenu(items: Array<TrayMenuItem | TrayMenuSeparator>): void;
|
|
311
|
+
/**
|
|
312
|
+
* Handle a left-click on the tray icon yourself. While a handler is
|
|
313
|
+
* registered the click runs only the handler — the tray's configured surface
|
|
314
|
+
* `action` is suppressed, so the click is fully yours (e.g. toggle a state and
|
|
315
|
+
* `setIcon`). Returns an unsubscribe function.
|
|
147
316
|
*/
|
|
148
|
-
|
|
317
|
+
onClick(handler: () => void): () => void;
|
|
318
|
+
/** Show the tray status item. */
|
|
319
|
+
show(): void;
|
|
320
|
+
/** Hide the tray status item (without removing the app). */
|
|
321
|
+
hide(): void;
|
|
149
322
|
}
|
|
150
323
|
|
|
151
324
|
export interface Lx {
|
|
152
325
|
env: LxEnv;
|
|
153
326
|
app: HostAppApi;
|
|
154
|
-
|
|
327
|
+
tray: TrayApi;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Open a surface.
|
|
331
|
+
*
|
|
332
|
+
* - `{ url }` without `as` opens a host browser tab and resolves to `null`.
|
|
333
|
+
* - `{ surface }` resolves to a host-managed handle with show/hide/close.
|
|
334
|
+
* - page surfaces and `{ url, as: 'aside' }` resolve to a full Surface handle.
|
|
335
|
+
*
|
|
336
|
+
* `as: 'window'` is desktop-only and rejects on mobile. See
|
|
337
|
+
* {@link OpenSurfaceSpec}.
|
|
338
|
+
*/
|
|
339
|
+
openSurface(spec: OpenUrlTabSpec): Promise<null>;
|
|
340
|
+
openSurface(spec: OpenDeclaredSurfaceSpec): Promise<SurfaceHandle>;
|
|
341
|
+
openSurface(spec: OpenPageSurfaceSpec | OpenUrlAsideSpec): Promise<Surface>;
|
|
342
|
+
openSurface(spec: OpenSurfaceSpec): Promise<Surface | SurfaceHandle | null>;
|
|
343
|
+
/** Hand a url off to the OS default browser (leaves the app). */
|
|
344
|
+
openExternal(url: string): void;
|
|
345
|
+
/**
|
|
346
|
+
* Subscribe to adaptive-context changes ({@link SurfaceContext}); the handler
|
|
347
|
+
* fires with the new context. Returns an unsubscribe function.
|
|
348
|
+
*/
|
|
349
|
+
onSurfaceContext(handler: (context: SurfaceContext) => void): () => void;
|
|
155
350
|
|
|
156
351
|
getDeviceInfo(): DeviceInfo;
|
|
157
352
|
getScreenInfo(): ScreenInfo;
|
|
@@ -180,7 +375,11 @@ export interface Lx {
|
|
|
180
375
|
* otherwise prefer `mode: 'auto'`.
|
|
181
376
|
*/
|
|
182
377
|
openFile(options: OpenFileOptions): void;
|
|
183
|
-
downloadFile(options:
|
|
378
|
+
downloadFile(options: DownloadsDownloadOptions): DownloadTask<DownloadsDownloadResult>;
|
|
379
|
+
downloadFile(options: AppDownloadOptions): DownloadTask<AppDownloadResult>;
|
|
380
|
+
downloadFile<TDestination extends DownloadDestination = 'app'>(
|
|
381
|
+
options: DownloadOptions<TDestination>,
|
|
382
|
+
): DownloadTask<DownloadResultForDestination<TDestination>>;
|
|
184
383
|
uploadFile(options: UploadOptions): UploadTask;
|
|
185
384
|
getFileManager(): FileManager;
|
|
186
385
|
|
|
@@ -193,13 +392,12 @@ export interface Lx {
|
|
|
193
392
|
|
|
194
393
|
getLxAppInfo(): LxAppInfo;
|
|
195
394
|
getSystemSetting(): SystemSettingInfo;
|
|
196
|
-
openURL(options: OpenURLOptions): void;
|
|
197
395
|
|
|
198
396
|
getUpdateManager(): UpdateManager;
|
|
199
397
|
|
|
200
398
|
getImageInfo(options: GetImageInfoOptions): Promise<ImageInfo>;
|
|
201
399
|
compressImage(options: CompressImageOptions): Promise<CompressImageResult>;
|
|
202
|
-
compressVideo(options: CompressVideoOptions):
|
|
400
|
+
compressVideo(options: CompressVideoOptions): CompressVideoTask;
|
|
203
401
|
getVideoInfo(options: GetVideoInfoOptions): Promise<VideoInfo>;
|
|
204
402
|
extractVideoThumbnail(options: ExtractVideoThumbnailOptions): Promise<ExtractVideoThumbnailResult>;
|
|
205
403
|
|
|
@@ -214,9 +412,12 @@ export interface Lx {
|
|
|
214
412
|
* - a sequence object for multi-item preview with `sources`, `startIndex`, and `advance`
|
|
215
413
|
*
|
|
216
414
|
* Returns a {@link PreviewMediaHandle} synchronously. Await `handle.completed`
|
|
217
|
-
* for the final session result (`reason`, `
|
|
218
|
-
*
|
|
219
|
-
*
|
|
415
|
+
* for the final session result (`reason`, `index`, `source` — the item the
|
|
416
|
+
* user was viewing when the preview closed). Subscribe to
|
|
417
|
+
* `handle.onChange(...)` / read `handle.current` to follow the viewed item
|
|
418
|
+
* live, and to `handle.presented` to learn when the first pixel hits the
|
|
419
|
+
* screen — useful for coordinating a hide of any overlay surface that was
|
|
420
|
+
* previously visible.
|
|
220
421
|
*
|
|
221
422
|
* `handle.completed` rejects with a cancellation error if `signal` is aborted;
|
|
222
423
|
* abort also requests the active native preview session to close immediately.
|
package/src/media/index.ts
CHANGED
|
@@ -73,6 +73,41 @@ export interface CompressVideoResult {
|
|
|
73
73
|
type: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
export interface CompressVideoProgressEvent {
|
|
77
|
+
/** Transcode progress in percent, `0`-`100`. */
|
|
78
|
+
progress: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface CompressVideoIteratorResult {
|
|
82
|
+
done: boolean;
|
|
83
|
+
value?: CompressVideoProgressEvent;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Handle returned by `lx.compressVideo`.
|
|
88
|
+
*
|
|
89
|
+
* Awaiting the task resolves with the final {@link CompressVideoResult}.
|
|
90
|
+
* Iterating it with `for await` yields {@link CompressVideoProgressEvent}s
|
|
91
|
+
* while the transcode runs.
|
|
92
|
+
*/
|
|
93
|
+
export interface CompressVideoTask
|
|
94
|
+
extends PromiseLike<CompressVideoResult>,
|
|
95
|
+
AsyncIterable<CompressVideoProgressEvent> {
|
|
96
|
+
next(): Promise<CompressVideoIteratorResult>;
|
|
97
|
+
/** Stops iteration only. Does not cancel the compression. */
|
|
98
|
+
return(): Promise<CompressVideoIteratorResult>;
|
|
99
|
+
catch<TResult = never>(
|
|
100
|
+
onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,
|
|
101
|
+
): Promise<CompressVideoResult | TResult>;
|
|
102
|
+
finally(onfinally?: (() => void) | null): Promise<CompressVideoResult>;
|
|
103
|
+
/**
|
|
104
|
+
* Cancels the transcode and deletes any partial output.
|
|
105
|
+
* The task promise rejects with an `AbortError` (`code: 'E_ABORT'`).
|
|
106
|
+
*/
|
|
107
|
+
cancel(): void;
|
|
108
|
+
wait(): Promise<CompressVideoResult>;
|
|
109
|
+
}
|
|
110
|
+
|
|
76
111
|
export interface GetVideoInfoOptions {
|
|
77
112
|
/**
|
|
78
113
|
* Video file path or `lx://` URI.
|
|
@@ -279,35 +314,68 @@ export type PreviewMediaOptions =
|
|
|
279
314
|
|
|
280
315
|
export type PreviewMediaCloseReason = 'manual' | 'completed' | 'interrupted' | 'error';
|
|
281
316
|
|
|
317
|
+
/**
|
|
318
|
+
* The item the user is (or was) looking at, handed back as the caller
|
|
319
|
+
* described it — `path` is returned verbatim, so it can be matched against
|
|
320
|
+
* the caller's own data without re-indexing an array.
|
|
321
|
+
*/
|
|
322
|
+
export interface PreviewMediaShownSource {
|
|
323
|
+
/** The path exactly as passed in the request. */
|
|
324
|
+
path: string;
|
|
325
|
+
/** Resolved media kind (after extension inference when `type` was omitted). */
|
|
326
|
+
type: 'image' | 'video';
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** One change-stream event / the `current` snapshot. */
|
|
330
|
+
export interface PreviewMediaChange {
|
|
331
|
+
index: number;
|
|
332
|
+
source: PreviewMediaShownSource;
|
|
333
|
+
}
|
|
334
|
+
|
|
282
335
|
export interface PreviewMediaResult {
|
|
283
336
|
/**
|
|
284
337
|
* Why the preview session finished.
|
|
285
338
|
*/
|
|
286
339
|
reason: PreviewMediaCloseReason;
|
|
287
340
|
/**
|
|
288
|
-
*
|
|
341
|
+
* Index of the item on screen when the session closed.
|
|
342
|
+
*/
|
|
343
|
+
index: number;
|
|
344
|
+
/**
|
|
345
|
+
* The item on screen when the session closed — "what the user just
|
|
346
|
+
* viewed/played", without mapping `index` back yourself.
|
|
289
347
|
*/
|
|
290
|
-
|
|
348
|
+
source: PreviewMediaShownSource;
|
|
291
349
|
}
|
|
292
350
|
|
|
293
351
|
/**
|
|
294
|
-
* Handle returned synchronously from `lx.previewMedia(...)
|
|
295
|
-
*
|
|
352
|
+
* Handle returned synchronously from `lx.previewMedia(...)` — synchronous so
|
|
353
|
+
* listeners can be attached before the first event fires:
|
|
296
354
|
*
|
|
297
355
|
* - `presented` resolves once the first pixel of the underlying media has
|
|
298
356
|
* been composited to screen. Use this to time the hide of an overlay
|
|
299
357
|
* surface above the preview so the swap is seamless. Never rejects;
|
|
300
358
|
* resolves with no value when the first frame is up. Safe to ignore.
|
|
301
|
-
* - `
|
|
302
|
-
*
|
|
303
|
-
*
|
|
359
|
+
* - `current` is a live `{ index, source }` snapshot of the item on screen,
|
|
360
|
+
* updated as the user swipes and as the session auto-advances.
|
|
361
|
+
* - `onChange(listener)` fires for every item change. Returns an
|
|
362
|
+
* unsubscribe function.
|
|
363
|
+
* - `completed` resolves `{ reason, index, source }` when the preview
|
|
364
|
+
* session ends (manual / auto / interrupted / error), or rejects on abort.
|
|
304
365
|
*
|
|
305
366
|
* If the call was aborted before any frame was presented, `presented` still
|
|
306
367
|
* resolves (with no value) once the abort takes effect — it never rejects,
|
|
307
368
|
* to keep fire-and-forget usage safe.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* const preview = lx.previewMedia({ sources, startIndex: 2 });
|
|
372
|
+
* preview.onChange(({ source }) => markAsViewed(source.path));
|
|
373
|
+
* const { reason, source } = await preview.completed;
|
|
308
374
|
*/
|
|
309
375
|
export interface PreviewMediaHandle {
|
|
310
376
|
readonly presented: Promise<void>;
|
|
377
|
+
readonly current: PreviewMediaChange;
|
|
378
|
+
onChange(listener: (change: PreviewMediaChange) => void): () => void;
|
|
311
379
|
readonly completed: Promise<PreviewMediaResult>;
|
|
312
380
|
}
|
|
313
381
|
|
package/src/system/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* System settings
|
|
2
|
+
* System settings.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export interface SystemSettingInfo {
|
|
@@ -7,8 +7,3 @@ export interface SystemSettingInfo {
|
|
|
7
7
|
locationEnabled: boolean;
|
|
8
8
|
wifiEnabled: boolean;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
export interface OpenURLOptions {
|
|
12
|
-
url: string;
|
|
13
|
-
target?: 'self' | 'external';
|
|
14
|
-
}
|
package/src/transfer/index.ts
CHANGED
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
* Transfer task APIs.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
declare const appDownloadPathBrand: unique symbol;
|
|
6
|
+
declare const systemDownloadsPathBrand: unique symbol;
|
|
7
|
+
|
|
8
|
+
export type DownloadDestination = 'app' | 'downloads';
|
|
9
|
+
|
|
10
|
+
/** Runtime-managed app download path, usually under `lx://userdata`. */
|
|
11
|
+
export type AppDownloadFilePath = string & {
|
|
12
|
+
readonly [appDownloadPathBrand]: 'app-download-file-path';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Native system Downloads path. Do not pass this to `FileManager`. */
|
|
16
|
+
export type SystemDownloadsPath = string & {
|
|
17
|
+
readonly [systemDownloadsPathBrand]: 'system-downloads-path';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface DownloadOptionsBase {
|
|
6
21
|
/** HTTP(S) source URL. */
|
|
7
22
|
url: string;
|
|
8
23
|
/**
|
|
@@ -12,35 +27,66 @@ export interface DownloadOptions {
|
|
|
12
27
|
headers?: Record<string, string>;
|
|
13
28
|
/** Request timeout in milliseconds. */
|
|
14
29
|
timeout?: number;
|
|
30
|
+
/** Optional abort signal. */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AppDownloadOptions extends DownloadOptionsBase {
|
|
15
35
|
/**
|
|
16
|
-
* Optional durable
|
|
17
|
-
*
|
|
18
|
-
* - Omit `filePath` to receive a temporary file in `tempFilePath`
|
|
19
|
-
* - Relative paths resolve under user data
|
|
20
|
-
* - `lx://` paths must target `lx://userdata`
|
|
36
|
+
* Optional app-owned durable output path.
|
|
21
37
|
*
|
|
38
|
+
* Omit `filePath` to receive a temporary result in `tempFilePath`. Relative
|
|
39
|
+
* paths resolve under user data. `lx://` paths must target `lx://userdata`;
|
|
22
40
|
* `lx://usercache` is not accepted here.
|
|
23
41
|
*/
|
|
24
42
|
filePath?: string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
43
|
+
/**
|
|
44
|
+
* App-owned output. Omit to use a temporary output unless `filePath` is set.
|
|
45
|
+
*/
|
|
46
|
+
destination?: 'app';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DownloadsDownloadOptions extends DownloadOptionsBase {
|
|
50
|
+
/**
|
|
51
|
+
* Optional filename hint for the system Downloads destination.
|
|
52
|
+
* This is not an app-owned FileManager path.
|
|
53
|
+
*/
|
|
54
|
+
filePath?: string;
|
|
55
|
+
/** Save into the user's system Downloads directory. */
|
|
56
|
+
destination: 'downloads';
|
|
27
57
|
}
|
|
28
58
|
|
|
29
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Download options.
|
|
61
|
+
*
|
|
62
|
+
* - `app`: app-owned temporary output, or durable `lx://userdata` output when
|
|
63
|
+
* `filePath` is set
|
|
64
|
+
* - `downloads`: user-visible system Downloads output, requiring
|
|
65
|
+
* `security.privileges: ["downloads"]` in `lxapp.json`
|
|
66
|
+
*
|
|
67
|
+
* Default: `app`.
|
|
68
|
+
*/
|
|
69
|
+
export type DownloadOptions<TDestination extends DownloadDestination = DownloadDestination> =
|
|
70
|
+
TDestination extends 'downloads' ? DownloadsDownloadOptions : AppDownloadOptions;
|
|
71
|
+
|
|
72
|
+
export type DownloadResultForDestination<TDestination extends DownloadDestination> =
|
|
73
|
+
TDestination extends 'downloads' ? DownloadsDownloadResult : AppDownloadResult;
|
|
74
|
+
|
|
75
|
+
export interface DownloadProgressEvent<TResult extends DownloadResult = DownloadResult> {
|
|
30
76
|
kind: 'progress' | 'paused' | 'resumed' | 'canceled' | 'completed';
|
|
31
77
|
downloadedBytes?: number;
|
|
32
78
|
totalBytes?: number;
|
|
33
79
|
/** Present only when the total size is known. */
|
|
34
80
|
progress?: number;
|
|
35
|
-
result?:
|
|
81
|
+
result?: TResult;
|
|
36
82
|
}
|
|
37
83
|
|
|
38
|
-
export interface DownloadIteratorResult {
|
|
84
|
+
export interface DownloadIteratorResult<TResult extends DownloadResult = DownloadResult> {
|
|
39
85
|
done: boolean;
|
|
40
|
-
value?: DownloadProgressEvent
|
|
86
|
+
value?: DownloadProgressEvent<TResult>;
|
|
41
87
|
}
|
|
42
88
|
|
|
43
|
-
export type
|
|
89
|
+
export type AppDownloadResult =
|
|
44
90
|
| {
|
|
45
91
|
/**
|
|
46
92
|
* Temporary result.
|
|
@@ -57,26 +103,38 @@ export type DownloadResult =
|
|
|
57
103
|
}
|
|
58
104
|
| {
|
|
59
105
|
/** Durable destination under `lx://userdata`. */
|
|
60
|
-
filePath:
|
|
106
|
+
filePath: AppDownloadFilePath;
|
|
61
107
|
tempFilePath?: never;
|
|
62
108
|
mimeType?: string;
|
|
63
109
|
size: number;
|
|
64
110
|
};
|
|
65
111
|
|
|
66
|
-
export interface
|
|
67
|
-
|
|
112
|
+
export interface DownloadsDownloadResult {
|
|
113
|
+
/** Native system Downloads path. Do not pass this to `FileManager`. */
|
|
114
|
+
filePath: SystemDownloadsPath;
|
|
115
|
+
tempFilePath?: never;
|
|
116
|
+
mimeType?: string;
|
|
117
|
+
size: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type DownloadResult = AppDownloadResult | DownloadsDownloadResult;
|
|
121
|
+
|
|
122
|
+
export interface DownloadTask<TDownloadResult extends DownloadResult = DownloadResult>
|
|
123
|
+
extends PromiseLike<TDownloadResult>,
|
|
124
|
+
AsyncIterable<DownloadProgressEvent<TDownloadResult>> {
|
|
125
|
+
next(): Promise<DownloadIteratorResult<TDownloadResult>>;
|
|
68
126
|
/** Stops iteration only. Does not cancel the underlying download task. */
|
|
69
|
-
return(): Promise<DownloadIteratorResult
|
|
70
|
-
catch<
|
|
71
|
-
onrejected?: ((reason: unknown) =>
|
|
72
|
-
): Promise<
|
|
73
|
-
finally(onfinally?: (() => void) | null): Promise<
|
|
127
|
+
return(): Promise<DownloadIteratorResult<TDownloadResult>>;
|
|
128
|
+
catch<TRejected = never>(
|
|
129
|
+
onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null,
|
|
130
|
+
): Promise<TDownloadResult | TRejected>;
|
|
131
|
+
finally(onfinally?: (() => void) | null): Promise<TDownloadResult>;
|
|
74
132
|
pause(): Promise<void>;
|
|
75
133
|
resume(): Promise<void>;
|
|
76
134
|
cancel(): Promise<void>;
|
|
77
135
|
/** Alias for cancel(), matching browser/mini-program abort naming. */
|
|
78
136
|
abort(): Promise<void>;
|
|
79
|
-
wait(): Promise<
|
|
137
|
+
wait(): Promise<TDownloadResult>;
|
|
80
138
|
}
|
|
81
139
|
|
|
82
140
|
export interface UploadOptions {
|