Skip to content

Commit

Permalink
save audio now done in main window to prevent worker window opening o…
Browse files Browse the repository at this point in the history
…n Mac
  • Loading branch information
Mattk70 committed Mar 8, 2024
1 parent 2a1bab6 commit bf658d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 15 additions & 0 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 1 addition & 8 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}

Expand Down

0 comments on commit bf658d4

Please sign in to comment.