From 8f41a0cf28c76b92367647c6b453e1dde98082b6 Mon Sep 17 00:00:00 2001 From: Kat21 Date: Fri, 12 Jan 2024 14:53:11 -0600 Subject: [PATCH] Allow downloading files --- assets/icons.js | 4 ++-- pkgs/apps/FileManager.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/assets/icons.js b/assets/icons.js index b185d01..1865296 100644 --- a/assets/icons.js +++ b/assets/icons.js @@ -80,14 +80,14 @@ export default { package: '', back: '', - circleCheck: '', warning: '', circleExclamation: '', - refresh: '', + download: + '', }; diff --git a/pkgs/apps/FileManager.js b/pkgs/apps/FileManager.js index a347381..d3e348b 100644 --- a/pkgs/apps/FileManager.js +++ b/pkgs/apps/FileManager.js @@ -141,6 +141,29 @@ export default { html: L.icons.import, title: "Import file from your system", }, + { + onclick: async (_) => { + if (!selectedItem) return; + let i = await vfs.whatIs(selectedItem); + if (i === "dir") + return Root.Modal.alert("Cannot download folders at the moment."); + let text = await vfs.readFile(selectedItem); + + // boilerplate download code + var element = document.createElement("a"); + element.setAttribute( + "href", + "data:text/plain;charset=utf-8," + encodeURIComponent(text) + ); + element.setAttribute("download", selectedItem.split('/').pop()); + element.style.display = "none"; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + }, + html: L.icons.download, + title: "Download File", + }, { onclick: async (_) => { if (!selectedItem) return;