fix: add required permissions section to download modal, use direct download to avoid blob HTTPS warning
This commit is contained in:
@@ -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 = '<i class="fas fa-download"></i> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user