Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Android.saveFile if available #59

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear to me why we have both customize.js and interface.js, so I updated both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Customise is for when an app is about to be uploaded, and interface is for when it's already loaded.

I know there's bags of overlap now, but initially they were quite separate (customise didn't used to have anything in it to get data from the watch)

// 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
Loading