1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-14 02:26:20 +02:00

ask for save location when exporting creations. fixes #200

This commit is contained in:
Kushagra Gour
2017-10-26 10:37:32 +05:30
parent 18484fdfcb
commit e0546ad7c6

View File

@ -1334,6 +1334,7 @@ globalConsoleContainerEl
}; };
scope.exportItems = function exportItems(e) { scope.exportItems = function exportItems(e) {
handleDownloadsPermission().then(() => {
fetchItems().then(function(items) { fetchItems().then(function(items) {
var d = new Date(); var d = new Date();
var fileName = [ var fileName = [
@ -1349,6 +1350,16 @@ globalConsoleContainerEl
var blob = new Blob([JSON.stringify(items, false, 2)], { var blob = new Blob([JSON.stringify(items, false, 2)], {
type: 'application/json;charset=UTF-8' type: 'application/json;charset=UTF-8'
}); });
chrome.downloads.download(
{
url: window.URL.createObjectURL(blob),
filename: fileName,
saveAs: true
},
function() {
// If there was an error, just download the file using ANCHOR method.
if (chrome.runtime.lastError) {
var a = document.createElement('a'); var a = document.createElement('a');
a.href = window.URL.createObjectURL(blob); a.href = window.URL.createObjectURL(blob);
a.download = fileName; a.download = fileName;
@ -1356,8 +1367,13 @@ globalConsoleContainerEl
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
a.remove(); a.remove();
}
}
);
trackEvent('ui', 'exportBtnClicked'); trackEvent('ui', 'exportBtnClicked');
}); });
});
e.preventDefault(); e.preventDefault();
}; };