From 57676d612b227b2c555f812ea92466bb919ff35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Fri, 5 Jan 2024 17:31:09 +0100 Subject: [PATCH] fix: attempt at fixing CSV exports crashing aw-android --- src/views/Buckets.vue | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/views/Buckets.vue b/src/views/Buckets.vue index 3a87cc0d..5344bc1a 100644 --- a/src/views/Buckets.vue +++ b/src/views/Buckets.vue @@ -267,16 +267,25 @@ export default { ); }); const csv = Papa.unparse(data, { columns, header: true }); - const blob = new Blob([csv], { type: 'text/csv' }); - const url = URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; - link.download = `aw-events-export-${bucketId}-${new Date() + const filename = `aw-events-export-${bucketId}-${new Date() .toISOString() .substring(0, 10)}.csv`; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + + // Check if the Android interface is available + if (window.Android) { + // Send the CSV data to the Android code + window.Android.downloadCSV(csv, filename); + } else { + // Fall back to the original method + const blob = new Blob([csv], { type: 'text/csv' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = filename; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } }, }, };