sliftutils 0.19.0 → 0.21.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/index.d.ts +1 -0
- package/package.json +1 -1
- package/render-utils/InputLabel.tsx +1 -1
- package/storage/FileFolderAPI.d.ts +1 -0
- package/storage/FileFolderAPI.tsx +50 -5
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -200,7 +200,7 @@ export class InputLabel extends preact.Component<InputLabelProps> {
|
|
|
200
200
|
}
|
|
201
201
|
return (
|
|
202
202
|
<label onClick={onClick} className={
|
|
203
|
-
css.hbox(
|
|
203
|
+
css.hbox(5).relative
|
|
204
204
|
+ " trigger-hover "
|
|
205
205
|
+ props.outerClass
|
|
206
206
|
+ (props.flavor === "large" && css.fontSize(18, "soft"))
|
|
@@ -46,7 +46,14 @@ let displayData = observable({
|
|
|
46
46
|
ui: undefined as undefined | preact.ComponentChildren,
|
|
47
47
|
}, undefined, { deep: false });
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
let fileAPIKey = "";
|
|
50
|
+
function getFileAPIKey() {
|
|
51
|
+
if (!fileAPIKey) throw new Error("Must call setFileAPIKey before using file system. Just pass any key. This prevents reusing the file system api that other development apps might be using.");
|
|
52
|
+
return fileAPIKey;
|
|
53
|
+
}
|
|
54
|
+
export function setFileAPIKey(key: string) {
|
|
55
|
+
fileAPIKey = key;
|
|
56
|
+
}
|
|
50
57
|
|
|
51
58
|
@observer
|
|
52
59
|
class DirectoryPrompter extends preact.Component {
|
|
@@ -206,7 +213,7 @@ export const getDirectoryHandle = lazy(async function getDirectoryHandle(): Prom
|
|
|
206
213
|
|
|
207
214
|
let handle: DirectoryWrapper | undefined;
|
|
208
215
|
|
|
209
|
-
|
|
216
|
+
const storedId = localStorage.getItem(getFileAPIKey());
|
|
210
217
|
if (storedId) {
|
|
211
218
|
let doneLoad = false;
|
|
212
219
|
setTimeout(() => {
|
|
@@ -216,7 +223,45 @@ export const getDirectoryHandle = lazy(async function getDirectoryHandle(): Prom
|
|
|
216
223
|
}, 500);
|
|
217
224
|
try {
|
|
218
225
|
handle = await tryToLoadPointer(storedId);
|
|
219
|
-
} catch {
|
|
226
|
+
} catch (e) {
|
|
227
|
+
console.error(e);
|
|
228
|
+
// Check if the error is due to user activation being required
|
|
229
|
+
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
230
|
+
if (errorMessage.includes("user activation") || errorMessage.includes("User activation")) {
|
|
231
|
+
doneLoad = true;
|
|
232
|
+
// Show UI to get user to click and retry
|
|
233
|
+
let retryCallback: (success: boolean) => void;
|
|
234
|
+
let retryPromise = new Promise<boolean>(resolve => {
|
|
235
|
+
retryCallback = resolve;
|
|
236
|
+
});
|
|
237
|
+
displayData.ui = (
|
|
238
|
+
<button
|
|
239
|
+
className={css.fontSize(40).pad2(80, 40)}
|
|
240
|
+
onClick={async () => {
|
|
241
|
+
displayData.ui = "Loading...";
|
|
242
|
+
try {
|
|
243
|
+
const retryHandle = await tryToLoadPointer(storedId);
|
|
244
|
+
if (retryHandle) {
|
|
245
|
+
handle = retryHandle;
|
|
246
|
+
retryCallback(true);
|
|
247
|
+
} else {
|
|
248
|
+
retryCallback(false);
|
|
249
|
+
}
|
|
250
|
+
} catch (retryError) {
|
|
251
|
+
console.error("Retry failed:", retryError);
|
|
252
|
+
retryCallback(false);
|
|
253
|
+
}
|
|
254
|
+
}}
|
|
255
|
+
>
|
|
256
|
+
Click to restore file system access
|
|
257
|
+
</button>
|
|
258
|
+
);
|
|
259
|
+
const success = await retryPromise;
|
|
260
|
+
if (handle) {
|
|
261
|
+
return handle;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
220
265
|
doneLoad = true;
|
|
221
266
|
if (handle) {
|
|
222
267
|
return handle;
|
|
@@ -234,7 +279,7 @@ export const getDirectoryHandle = lazy(async function getDirectoryHandle(): Prom
|
|
|
234
279
|
const handle = await window.showDirectoryPicker();
|
|
235
280
|
await handle.requestPermission({ mode: "readwrite" });
|
|
236
281
|
let storedId = await storeFileSystemPointer({ mode: "readwrite", handle });
|
|
237
|
-
localStorage.setItem(
|
|
282
|
+
localStorage.setItem(getFileAPIKey(), storedId);
|
|
238
283
|
fileCallback(handle as any);
|
|
239
284
|
}}
|
|
240
285
|
>
|
|
@@ -265,7 +310,7 @@ export const getFileStorage = lazy(async function getFileStorage(): Promise<File
|
|
|
265
310
|
return wrapHandle(handle);
|
|
266
311
|
});
|
|
267
312
|
export function resetStorageLocation() {
|
|
268
|
-
localStorage.removeItem(
|
|
313
|
+
localStorage.removeItem(getFileAPIKey());
|
|
269
314
|
window.location.reload();
|
|
270
315
|
}
|
|
271
316
|
|