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,29 +1334,45 @@ globalConsoleContainerEl
}; };
scope.exportItems = function exportItems(e) { scope.exportItems = function exportItems(e) {
fetchItems().then(function(items) { handleDownloadsPermission().then(() => {
var d = new Date(); fetchItems().then(function(items) {
var fileName = [ var d = new Date();
'web-maker-export', var fileName = [
d.getFullYear(), 'web-maker-export',
d.getMonth() + 1, d.getFullYear(),
d.getDate(), d.getMonth() + 1,
d.getHours(), d.getDate(),
d.getMinutes(), d.getHours(),
d.getSeconds() d.getMinutes(),
].join('-'); d.getSeconds()
fileName += '.json'; ].join('-');
var blob = new Blob([JSON.stringify(items, false, 2)], { fileName += '.json';
type: 'application/json;charset=UTF-8' var blob = new Blob([JSON.stringify(items, false, 2)], {
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');
a.href = window.URL.createObjectURL(blob);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
}
}
);
trackEvent('ui', 'exportBtnClicked');
}); });
var a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
trackEvent('ui', 'exportBtnClicked');
}); });
e.preventDefault(); e.preventDefault();
}; };