summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/platform.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/platform.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/platform.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
index 994f558..372b666 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
@@ -176,13 +176,32 @@ export async function apiFetch(url, init) {
* in `downloads.js`. Adding a native writer must not remove the three that
* already work.
*/
-export async function nativeSave(suggestedName, size) {
+export async function nativeSave(suggestedName, { auto = true } = {}) {
if (!bridge || !bridge.saveFile) return null;
- return bridge.saveFile(suggestedName, size);
+ const sink = await bridge.saveFile(suggestedName, { auto });
+ if (!sink) return null;
+ // The shape every caller already expects from a download target: a `writable`
+ // with write/close/abort, and the name it was actually given on disk.
+ return {
+ name: sink.name,
+ writable: {
+ write: (bytes) => sink.write(bytes),
+ close: () => sink.close(),
+ abort: () => sink.abort(),
+ },
+ };
}
+/** Where downloads go on a desktop build. Null in a browser. */
+export const folder = {
+ available: Boolean(bridge && bridge.folder),
+ async choose() { return bridge && bridge.folder ? bridge.folder.choose() : null; },
+ async get() { return bridge && bridge.folder ? bridge.folder.get() : null; },
+ async forget() { return bridge && bridge.folder ? bridge.folder.forget() : false; },
+};
+
export default { isNative, hubBase, capabilities, secrets, nativeSave,
- apiFetch, device, bridgeMessage };
+ apiFetch, device, bridgeMessage, folder };
// Also a global, because `transport.js` is loaded as a classic script — it
// predates the module graph and exposes `MeshBayTransport` the same way. The
@@ -191,5 +210,5 @@ export default { isNative, hubBase, capabilities, secrets, nativeSave,
if (typeof window !== 'undefined') {
window.MeshBayPlatform = { isNative, hubBase, capabilities, secrets,
nativeSave, apiFetch, device,
- bridgeMessage };
+ bridgeMessage, folder };
}