Skip to content

Commit

Permalink
Merge pull request #59 from joserebelo/save-file
Browse files Browse the repository at this point in the history
Use Android.saveFile if available
  • Loading branch information
gfwilliams committed Mar 18, 2024
2 parents 0222d3c + 1928c36 commit 2603ca6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/customize.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ const Util = {
Util.domModal.classList.remove("active");
},
saveFile : function saveFile(filename, mimeType, dataAsString) {
if (typeof Android !== "undefined" && typeof Android.saveFile === 'function') {
// Recent Gadgetbridge version that provides the saveFile interface
Android.saveFile(filename, mimeType, btoa(dataAsString));
return;
}

let a = document.createElement("a");
// Blob downloads don't work under Gadgetbridge
//let file = new Blob([dataAsString], {type: mimeType});
Expand Down
6 changes: 6 additions & 0 deletions lib/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ const Util = {
Util.domModal.classList.remove("active");
},
saveFile : function saveFile(filename, mimeType, dataAsString) {
if (typeof Android !== "undefined" && typeof Android.saveFile === 'function') {
// Recent Gadgetbridge version that provides the saveFile interface
Android.saveFile(filename, mimeType, btoa(dataAsString));
return;
}

let a = document.createElement("a");
// Blob downloads don't work under Gadgetbridge
//let file = new Blob([dataAsString], {type: mimeType});
Expand Down

0 comments on commit 2603ca6

Please sign in to comment.