Skip to content

Commit

Permalink
Use Android.saveFile if available
Browse files Browse the repository at this point in the history
  • Loading branch information
joserebelo committed Mar 16, 2024
1 parent 0222d3c commit 1928c36
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 1928c36

Please sign in to comment.