Skip to content

Commit

Permalink
file save dialog take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
joric committed Aug 20, 2024
1 parent 952c484 commit 93e531f
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions js/qle.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,26 +830,10 @@ function get_char_code(id, x, y) {
}
});

async function saveToFile(data, filename) {
const fileHandle = await window.showSaveFilePicker({
suggestedName: filename,
types: [{
description: '.png files',
accept: {'image/png': ['.png']},
}],
});
const writableStream = await fileHandle.createWritable();
await writableStream.write(data);
await writableStream.close();
}

$('#download').on('click', function(e) {
var id = get_current_canvas_id();
var canvas = document.getElementById(id);
var ctx = canvas.getContext('2d');
var filename = id + '.png';
canvas.toBlob(blob=>{
saveToFile(blob, filename);
document.getElementById(id).toBlob(blob=>{
showSaveFilePicker({suggestedName: id+'.png'}).then(f=>f.createWritable()).then(f=>(t=f).write(blob)).then(f=>t.close());
});
});

Expand Down

0 comments on commit 93e531f

Please sign in to comment.