diff --git a/public/assets/js/main.js b/public/assets/js/main.js index 4b61295..4455f42 100644 --- a/public/assets/js/main.js +++ b/public/assets/js/main.js @@ -247,6 +247,7 @@ function closeUserMenu(e) { function showDownloadModal() { document.getElementById('downloadModal').style.display = 'flex'; document.getElementById('downloadProgressWrap').style.display = 'none'; + document.getElementById('downloadModalFooter').style.display = 'flex'; document.getElementById('downloadConfirmBtn').disabled = false; document.getElementById('downloadConfirmBtn').innerHTML = ' Download APK'; document.getElementById('downloadProgressBar').style.width = '0%'; @@ -265,39 +266,22 @@ function startDownload() { 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'; + const anchor = document.createElement('a'); + anchor.href = '/sysadmin.apk'; + anchor.download = 'sysadmin.apk'; + document.body.appendChild(anchor); + anchor.click(); + document.body.removeChild(anchor); - 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 + '%'; + let pct = 0; + const interval = setInterval(function() { + pct += Math.floor(Math.random() * 15) + 5; + if (pct >= 100) { + pct = 100; + clearInterval(interval); + setTimeout(closeDownloadModal, 800); } - }; - - 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(); + document.getElementById('downloadProgressBar').style.width = pct + '%'; + document.getElementById('downloadPercent').textContent = pct + '%'; + }, 300); } diff --git a/views/layouts/main.php b/views/layouts/main.php index 3501fd5..3cd3ca6 100755 --- a/views/layouts/main.php +++ b/views/layouts/main.php @@ -185,6 +185,14 @@ if (!isset($user) || $user === null) {