Commit c966da3f authored by jy1263's avatar jy1263

Cleaned up code.

Moved dragndrop to section.library.js.
Also made the actual extraction process a function so the code doesn't double up for both the normal upload method and drag and drop.
parent bbd7d71c
const DOMLibrarySongsList = document.querySelector(".song-row-library .song-list");
//The Extraction Process
function ExtractionProcess(filePath){
//Basic .zip detection so the console doesnt throw a flurry of errors complaining it can't unzip.
if (filePath.endsWith('.zip')){
let fileName = path.basename(filePath)
srxdControl.extractBackup(filePath, fileName).then(function(extractResults) {
if(extractResults) {
installBackup(extractResults);
setTimeout(function() {
RefreshLibrary();
}, 200);
}
else {
console.error("Backup could not be loaded!");
}
});
}
else {console.error('Not a zip!');}
}
//Upload Manually
function InstallBackupManually() {
dialog.showOpenDialog({ title: "Open Backup", properties: ['openFile'], filters: [{"name": "Backup Archive", "extensions": ["zip"]}] }).then(result => {
if(!result.canceled) {
let filePath = result.filePaths[0];
let fileName = path.basename(filePath);
srxdControl.extractBackup(filePath, fileName).then(function(extractResults) {
if(extractResults) {
installBackup(extractResults);
setTimeout(function() {
RefreshLibrary();
}, 200);
} else {
console.error("Backup could not be loaded!");
}
});
ExtractionProcess(filePath);
}
});
}
//Drag and Drop
document.ondragover = document.ondrop = (dragndrop) => {
dragndrop.preventDefault();
}
document.body.ondrop = (ev) => {
let filePath = (ev.dataTransfer.files[0].path)
ev.preventDefault()
ExtractionProcess(filePath);
}
function RefreshLibrary() {
// Clear current songs
let installElement = DOMLibrarySongsList.firstElementChild;
......
......@@ -165,23 +165,3 @@ function BuildSongDOM(songItem) {
return songContainer;
}
document.ondragover = document.ondrop = (dragndrop) => {
dragndrop.preventDefault()
}
document.body.ondrop = (ev) => {
console.log("File dragged: " + ev.dataTransfer.files[0].path)
let filePath = (ev.dataTransfer.files[0].path)
let fileName = path.basename(filePath)
ev.preventDefault()
srxdControl.extractBackup(filePath, fileName).then(function(extractResults) {
if(extractResults) {
installBackup(extractResults);
setTimeout(function() {
RefreshLibrary();
}, 200);
} else {
console.error("Backup could not be loaded!");
}
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment