diff --git a/public/assets/js/main.js b/public/assets/js/main.js index 4699df1..4b61295 100644 --- a/public/assets/js/main.js +++ b/public/assets/js/main.js @@ -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 = ' 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 = ' 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(); +} diff --git a/views/layouts/main.php b/views/layouts/main.php index 4c02d6a..3501fd5 100755 --- a/views/layouts/main.php +++ b/views/layouts/main.php @@ -78,7 +78,7 @@ if (!isset($user) || $user === null) {
+ The Android companion app lets you manage your servers on the go: +
+