@livx.cc/native-kit 0.45.9 → 0.45.11

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.9",
3
+ "version": "0.45.11",
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",
@@ -72,6 +72,7 @@ export class WebAdapter implements NativeKitAdapter {
72
72
  haptics: 'vibrate' in navigator ? 'web' : 'none',
73
73
  share: 'share' in navigator ? 'web' : 'none',
74
74
  shareFiles: typeof n.canShare === 'function' ? 'web' : 'none', // navigator.canShare({files}) gates at call time
75
+ saveToPhotos: 'none', // a browser cannot write to the photo library — explicit, so a shell never inherits 'web'
75
76
  orientation: screen?.orientation ? 'web' : 'none', // Screen Orientation API (lock needs fullscreen)
76
77
  storage: 'web',
77
78
  secureStorage: 'none',
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, ShareResult } from './modules/share';
25
+ export type { SharePayload, ShareFile, ShareResult, SaveToPhotosResult } 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';
@@ -22,6 +22,15 @@ export interface ShareResult {
22
22
  activity?: string;
23
23
  }
24
24
 
25
+ /** What {@link ShareModule.saveToPhotos} resolves with. Never throws for a refusal: `saved:false` +
26
+ * `reason` — 'denied' (the person said no / Settings forbids it), 'unsupported' (not an image or video,
27
+ * or this shell/platform cannot write to the library: browsers, older native builds), 'failed'. */
28
+ export interface SaveToPhotosResult {
29
+ saved: boolean;
30
+ reason?: 'denied' | 'unsupported' | 'failed';
31
+ message?: string;
32
+ }
33
+
25
34
  export class ShareModule {
26
35
  constructor(private kit: NativeKit) {}
27
36
 
@@ -35,6 +44,22 @@ export class ShareModule {
35
44
  return this.kit.capability('shareFiles');
36
45
  }
37
46
 
47
+ /** Direct save into the photo library — 'native' only in a shell that has the handler. Absent on web
48
+ * (a browser cannot write to Photos) and on native builds that predate it: branch on this and fall
49
+ * back to {@link files} (whose sheet offers "Save Image/Video"). */
50
+ get saveToPhotosCapability() {
51
+ return this.kit.capability('saveToPhotos');
52
+ }
53
+
54
+ /** Save ONE image or video straight into Photos (iOS add-only access, Android MediaStore) — no share
55
+ * sheet. Resolves `{ saved:false, reason:'unsupported' }` without calling the shell when unavailable. */
56
+ async saveToPhotos(file: ShareFile): Promise<SaveToPhotosResult> {
57
+ await this.kit.ready().catch(() => {});
58
+ if (this.saveToPhotosCapability !== 'native') return { saved: false, reason: 'unsupported', message: 'saving to Photos is not available here' };
59
+ // No watchdog: the first call waits on the OS permission prompt.
60
+ return this.kit.invoke('share.saveToPhotos', file, { timeoutMs: 'none' });
61
+ }
62
+
38
63
  // Both resolve when the sheet is DISMISSED (not when it opens), so no watchdog: a person may take
39
64
  // their time picking a target, and a deadline could only false-timeout mid-interaction.
40
65
  share(payload: SharePayload): Promise<ShareResult | undefined> {