@livx.cc/native-kit 0.45.7 → 0.45.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/native-kit",
3
- "version": "0.45.7",
3
+ "version": "0.45.9",
4
4
  "description": "Isomorphic native-capabilities kit for PWAs — same API in browser and in an appwrap native shell. Zero dependencies.",
5
5
  "license": "MIT",
6
6
  "author": "Elya Livshitz",
@@ -144,11 +144,13 @@ export class WebAdapter implements NativeKitAdapter {
144
144
 
145
145
  case 'share.share':
146
146
  if (!navigator.share) throw new KitError('UNSUPPORTED', 'Web Share API unavailable');
147
- await navigator.share({ title: p.title, text: p.text, url: p.url }).catch((e: Error) => {
148
- if (e.name === 'AbortError') return; // user dismissed — not an error
149
- throw new KitError('NATIVE_ERROR', e.message);
150
- });
151
- return undefined as T;
147
+ return (await navigator.share({ title: p.title, text: p.text, url: p.url }).then(
148
+ () => ({ completed: true }),
149
+ (e: Error) => {
150
+ if (e.name === 'AbortError') return { completed: false }; // user dismissed — not an error
151
+ throw new KitError('NATIVE_ERROR', e.message);
152
+ }
153
+ )) as T;
152
154
 
153
155
  case 'share.files': {
154
156
  const files = ((p.files ?? []) as Array<{ name: string; mimeType: string; base64: string }>).map(
@@ -156,11 +158,13 @@ export class WebAdapter implements NativeKitAdapter {
156
158
  );
157
159
  const data: ShareData = { files, title: p.title, text: p.text };
158
160
  if (!navigator.canShare?.(data)) throw new KitError('UNSUPPORTED', 'Sharing files is unavailable here');
159
- await navigator.share(data).catch((e: Error) => {
160
- if (e.name === 'AbortError') return; // user dismissed
161
- throw new KitError('NATIVE_ERROR', e.message);
162
- });
163
- return undefined as T;
161
+ return (await navigator.share(data).then(
162
+ () => ({ completed: true }),
163
+ (e: Error) => {
164
+ if (e.name === 'AbortError') return { completed: false }; // user dismissed
165
+ throw new KitError('NATIVE_ERROR', e.message);
166
+ }
167
+ )) as T;
164
168
  }
165
169
 
166
170
  case 'storage.get':
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@ export type {
22
22
  Unsubscribe,
23
23
  } from './core/types';
24
24
  export type { ImpactStyle, NotifyType } from './modules/haptics';
25
- export type { SharePayload, ShareFile } from './modules/share';
25
+ export type { SharePayload, ShareFile, ShareResult } from './modules/share';
26
26
  export type { Orientation, OrientationLock } from './modules/screen';
27
27
  export type { KeyboardInfo } from './modules/keyboard';
28
28
  export type { FsDirectory, FsEncoding, FsEntry, PickedFile } from './modules/fs';
@@ -13,6 +13,15 @@ export interface ShareFile {
13
13
  base64: string;
14
14
  }
15
15
 
16
+ /** How a share sheet ended. `completed` is false when the person dismissed it. `activity` is the OS
17
+ * activity they picked when the platform reports one (iOS UIActivityType, e.g.
18
+ * `com.apple.UIKit.activity.SaveToCameraRoll`); web `navigator.share` and the Android chooser never
19
+ * name it. `undefined` from the call = a shell that predates this result (resolved on present). */
20
+ export interface ShareResult {
21
+ completed: boolean;
22
+ activity?: string;
23
+ }
24
+
16
25
  export class ShareModule {
17
26
  constructor(private kit: NativeKit) {}
18
27
 
@@ -26,12 +35,14 @@ export class ShareModule {
26
35
  return this.kit.capability('shareFiles');
27
36
  }
28
37
 
29
- share(payload: SharePayload): Promise<void> {
30
- return this.kit.invoke('share.share', payload);
38
+ // Both resolve when the sheet is DISMISSED (not when it opens), so no watchdog: a person may take
39
+ // their time picking a target, and a deadline could only false-timeout mid-interaction.
40
+ share(payload: SharePayload): Promise<ShareResult | undefined> {
41
+ return this.kit.invoke('share.share', payload, { timeoutMs: 'none' });
31
42
  }
32
43
 
33
44
  /** Share one or more files (iOS UIActivity / web `navigator.share({files})`). */
34
- files(files: ShareFile[], opts?: { title?: string; text?: string }): Promise<void> {
35
- return this.kit.invoke('share.files', { files, ...opts });
45
+ files(files: ShareFile[], opts?: { title?: string; text?: string }): Promise<ShareResult | undefined> {
46
+ return this.kit.invoke('share.files', { files, ...opts }, { timeoutMs: 'none' });
36
47
  }
37
48
  }