sliftutils 1.2.17 → 1.2.18

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/index.d.ts CHANGED
@@ -1336,7 +1336,7 @@ declare module "sliftutils/storage/fileSystemPointer" {
1336
1336
  export declare function getFileSystemPointer(config: {
1337
1337
  pointer: FileSystemPointer;
1338
1338
  }): Promise<{
1339
- onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle>;
1339
+ onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle | undefined>;
1340
1340
  } | undefined>;
1341
1341
 
1342
1342
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.2.17",
3
+ "version": "1.2.18",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -8,7 +8,7 @@ import { TransactionStorage } from "./TransactionStorage";
8
8
  import { PendingStorage } from "./PendingStorage";
9
9
  import { isDefined } from "../misc/types";
10
10
  import { PrivateFileSystemStorage } from "./PrivateFileSystemStorage";
11
- import { isInChromeExtension } from "../misc/environment";
11
+ import { isInChromeExtension, isInChromeExtensionBackground } from "../misc/environment";
12
12
  import { CBORStorage } from "./CBORStorage";
13
13
 
14
14
  export class DiskCollection<T> implements IStorageSync<T> {
@@ -27,7 +27,7 @@ export class DiskCollection<T> implements IStorageSync<T> {
27
27
  public transactionStorage: TransactionStorage | undefined;
28
28
  async initStorage(): Promise<IStorage<T>> {
29
29
  // If a Chrome extension, just return null.
30
- if (isInChromeExtension()) return null as any;
30
+ if (isInChromeExtensionBackground()) return null as any;
31
31
  let curCollection: IStorageRaw;
32
32
  if (this.config?.noPrompt && !isNode()) {
33
33
  curCollection = await new PrivateFileSystemStorage(`collections/${this.collectionName}`);
@@ -7,5 +7,5 @@ export declare function deleteFileSystemPointer(pointer: FileSystemPointer): Pro
7
7
  export declare function getFileSystemPointer(config: {
8
8
  pointer: FileSystemPointer;
9
9
  }): Promise<{
10
- onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle>;
10
+ onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle | undefined>;
11
11
  } | undefined>;
@@ -63,7 +63,7 @@ export async function getFileSystemPointer(config: {
63
63
  // IMPORTANT! In some circumstances user activation is not required (with multiple tabs,
64
64
  // and potentially with https://developer.chrome.com/blog/persistent-permissions-for-the-file-system-access-api),
65
65
  // so... trying to call onUserActivation immmediately is a good idea (although it might throw).
66
- onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle>
66
+ onUserActivation(modeOverride?: "read" | "readwrite"): Promise<FileSystemFileHandle | FileSystemDirectoryHandle | undefined>
67
67
  } | undefined
68
68
  > {
69
69
  const handle = await read(config.pointer);
@@ -71,10 +71,14 @@ export async function getFileSystemPointer(config: {
71
71
  let mode = config.pointer.split("_").at(-1);
72
72
  return {
73
73
  async onUserActivation(modeOverride) {
74
- let testMode = await (handle as any).queryPermission({ mode: mode });
75
- if (testMode !== mode) {
76
- await (handle as any).requestPermission({ mode: modeOverride ?? mode });
74
+ let requestedMode = modeOverride ?? mode;
75
+ let permission = await (handle as any).queryPermission({ mode: requestedMode });
76
+ if (permission !== "granted") {
77
+ permission = await (handle as any).requestPermission({ mode: requestedMode });
77
78
  }
79
+ // If the user denied (or otherwise didn't grant) the request, treat the
80
+ // stored pointer as unusable so callers can fall back to showDirectoryPicker.
81
+ if (permission !== "granted") return undefined;
78
82
  return handle;
79
83
  }
80
84
  };