mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
* introducing pyscript.fs namespace/module * Added proper rejection when showDirectoryPicker is not supported * Improved exports to make explicit import in 3rd party modules easier * implemented `fs.unmount(path)`: * verified that RAM gets freed * allowed to mount different handlers within the same path through different `id` as that's the Web best way to do so
32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
import { idb, getFileSystemDirectoryHandle } from "./fs.js";
|
|
|
|
export default {
|
|
// allow pyterminal checks to bootstrap
|
|
is_pyterminal: () => false,
|
|
|
|
/**
|
|
* 'Sleep' for the given number of seconds. Used to implement Python's time.sleep in Worker threads.
|
|
* @param {number} seconds The number of seconds to sleep.
|
|
*/
|
|
sleep(seconds) {
|
|
return new Promise(($) => setTimeout($, seconds * 1000));
|
|
},
|
|
|
|
/**
|
|
* Ask a user action via dialog and returns the directory handler once granted.
|
|
* @param {string} uid
|
|
* @param {{id?:string, mode?:"read"|"readwrite", hint?:"desktop"|"documents"|"downloads"|"music"|"pictures"|"videos"}} options
|
|
* @returns {boolean}
|
|
*/
|
|
async storeFSHandler(uid, options = {}) {
|
|
if (await idb.has(uid)) return true;
|
|
return getFileSystemDirectoryHandle(options).then(
|
|
async (handler) => {
|
|
await idb.set(uid, handler);
|
|
return true;
|
|
},
|
|
() => false,
|
|
);
|
|
},
|
|
};
|