From bf658d4de843ff2f319dae7f0325d541403e1dd6 Mon Sep 17 00:00:00 2001 From: Mattk70 Date: Fri, 8 Mar 2024 13:06:14 +0000 Subject: [PATCH] save audio now done in main window to prevent worker window opening on Mac --- js/ui.js | 15 +++++++++++++++ js/worker.js | 9 +-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/js/ui.js b/js/ui.js index 88f7a318..ddd632ce 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1651,6 +1651,9 @@ const setUpWorkerMessaging = () => { case "analysis-complete": {onAnalysisComplete(); break; } + case "audio-file-to-save": {onSaveAudio(args); + break; + } case "chart-data": {onChartData(args); break; } @@ -1866,6 +1869,18 @@ document.addEventListener('change', function (e) { } }) +// Save audio clip +function onSaveAudio({file: file, filename: filename}){ + const anchor = document.createElement('a'); + document.body.appendChild(anchor); + anchor.style = 'display: none'; + const url = window.URL.createObjectURL(file); + anchor.href = url; + anchor.download = filename; + anchor.click(); + window.URL.revokeObjectURL(url); +} + // Chart functions function getDateOfISOWeek(w) { diff --git a/js/worker.js b/js/worker.js index 4b827907..da3ca1be 100644 --- a/js/worker.js +++ b/js/worker.js @@ -1783,14 +1783,7 @@ const prepSummaryStatement = (included) => { fs.writeFile(p.join(folder, filename), buffer, () => { if (DEBUG) console.log('Audio file saved') }); } else { - const anchor = document.createElement('a'); - document.body.appendChild(anchor); - anchor.style = 'display: none'; - const url = window.URL.createObjectURL(thisBlob); - anchor.href = url; - anchor.download = filename; - anchor.click(); - window.URL.revokeObjectURL(url); + UI.postMessage({event:'audio-file-to-save', file: thisBlob, filename: filename}) } }