aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/transfers.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transfers.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/transfers.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transfers.js b/packages/meshbay-hub/src/meshbay_hub/static/transfers.js
index 1ad1ec5..fa34c67 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/transfers.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/transfers.js
@@ -56,6 +56,9 @@ export class TransferStore {
error: it.error || '',
speed: this._speed(it),
percent: it.total ? Math.min(100, Math.round(it.done / it.total * 100)) : 0,
+ // Only for a file written into a folder the browser granted us: that is
+ // the one case where the page can read its own download back.
+ canOpen: it.status === 'done' && typeof it.open === 'function',
}));
}
@@ -79,10 +82,10 @@ export class TransferStore {
* `run` receives `{ signal, onProgress }`. It must poll `signal.aborted` — a
* cancel that only sets a flag nobody reads is a button that lies.
*/
- start({ kind, name, total = 0, transport = null, run }) {
+ start({ kind, name, total = 0, transport = null, run, open = null }) {
const item = {
id: _nextId++,
- kind, name, total, transport,
+ kind, name, total, transport, open,
done: 0,
status: 'running',
error: '',
@@ -128,6 +131,19 @@ export class TransferStore {
return item.id;
}
+ /**
+ * Hand a finished download to the browser to display.
+ *
+ * As close to "open it" as a web page gets: the bytes go to a new tab and the
+ * browser decides what to do with them. A page cannot start a desktop
+ * application, and cannot show a file manager — there is no API for either,
+ * in any browser, by design.
+ */
+ open(id) {
+ const item = this._items.find(it => it.id === id);
+ if (item && typeof item.open === 'function') return item.open();
+ }
+
cancel(id) {
const item = this._items.find(it => it.id === id);
if (!item || item.status !== 'running') return;