From aaf3b789be236c434a61ee5169f19a0c1eda49a0 Mon Sep 17 00:00:00 2001 From: Rocky the Protogen Date: Sun, 15 Sep 2024 18:27:33 -0400 Subject: [PATCH] Yippee --- .../FileSystemAccessAPI/fsa-api.js | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 extensions/RockytheProtogen/FileSystemAccessAPI/fsa-api.js diff --git a/extensions/RockytheProtogen/FileSystemAccessAPI/fsa-api.js b/extensions/RockytheProtogen/FileSystemAccessAPI/fsa-api.js new file mode 100644 index 0000000000..0dff55342d --- /dev/null +++ b/extensions/RockytheProtogen/FileSystemAccessAPI/fsa-api.js @@ -0,0 +1,85 @@ +(function(Scratch) { + 'use strict'; + + if (!Scratch.extensions.unsandboxed) {throw new Error('File System Access API must run unsandboxed');} + + class rtpfsaapi { + getInfo() { + return { + id: 'rtpfsaapi', + name: 'File System Access API', + blocks: [ + { + opcode: 'filepicker', + blockType: 'reporter', + text: 'window.showOpenFilePicker\([json]\)', + arguments: { + json: { + type: 'string' + } + } + }, + { + opcode: 'filesavepicker', + blockType: 'reporter', + text: 'window.showSaveFilePicker\([json]\)', + arguments: { + json: { + type: 'string' + } + } + }, + { + opcode: 'folderpicker', + blockType: 'reporter', + text: 'window.showDirectoryPicker\([json]\)', + arguments: { + json: { + type: 'string' + } + } + }, + { + opcode: 'getFile', + blockType: 'reporter', + text: '[handle]\.getFile\(\)', + arguments: { + handle: { + acceptReporters: true, + } +} +} + ] + }; + } + filepicker(args) { + try { + return window.showOpenFilePicker(JSON.parse(args.json)); + } catch (err) { + return err; + } + } + filesavepicker(args) { + try { + return window.showSaveFilePicker(JSON.parse(args.json)); + } catch (err) { + return err; + } + } + folderpicker(args) { + try { + return window.showDirectoryPicker(JSON.parse(args.json)); + } catch (err) { + return err; + } + } + getFile(args) { + try { + let handle;[handle] = args.handle;return handle.getFile() + } catch (err) { + return err; + } + } + } + Scratch.extensions.register(new rtpfsaapi()); + })(Scratch);