feat: add download modal with app summary and progress bar for APK download

This commit is contained in:
2026-06-14 09:52:18 -04:00
parent f48a5a5495
commit 5453a5d856
2 changed files with 95 additions and 1 deletions

View File

@@ -243,3 +243,61 @@ function closeUserMenu(e) {
document.removeEventListener('click', closeUserMenu);
}
}
function showDownloadModal() {
document.getElementById('downloadModal').style.display = 'flex';
document.getElementById('downloadProgressWrap').style.display = 'none';
document.getElementById('downloadConfirmBtn').disabled = false;
document.getElementById('downloadConfirmBtn').innerHTML = '<i class="fas fa-download"></i> Download APK';
document.getElementById('downloadProgressBar').style.width = '0%';
document.getElementById('downloadPercent').textContent = '0%';
}
function closeDownloadModal() {
document.getElementById('downloadModal').style.display = 'none';
}
function startDownload() {
const btn = document.getElementById('downloadConfirmBtn');
btn.disabled = true;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Downloading...';
document.getElementById('downloadProgressWrap').style.display = 'block';
document.getElementById('downloadModalFooter').style.display = 'none';
const xhr = new XMLHttpRequest();
xhr.open('GET', '/sysadmin.apk', true);
xhr.responseType = 'blob';
xhr.onprogress = function(e) {
if (e.lengthComputable) {
const pct = Math.round((e.loaded / e.total) * 100);
document.getElementById('downloadProgressBar').style.width = pct + '%';
document.getElementById('downloadPercent').textContent = pct + '%';
}
};
xhr.onload = function() {
if (xhr.status === 200) {
const url = URL.createObjectURL(xhr.response);
const a = document.createElement('a');
a.href = url;
a.download = 'sysadmin.apk';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
setTimeout(closeDownloadModal, 1000);
} else {
showToast('error', 'Download failed.');
closeDownloadModal();
}
};
xhr.onerror = function() {
showToast('error', 'Download failed.');
closeDownloadModal();
};
xhr.send();
}