1
0
mirror of git://f0xx.org/ac/ac-be-hub synced 2026-07-29 04:18:53 +03:00
Files
ac-be-hub/assets/hub-downloads.js
Anton Afanasyeu 0042bb9870 feat(hub): add Downloads and Documentation landing pages
Wire hub-downloads.js for stable OTA APK resolution, expand nav i18n, and add
Session Studio download slot for alpha hub FR.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-10 15:36:48 +02:00

68 lines
1.8 KiB
JavaScript

(function () {
'use strict';
function setStatus(msg) {
var el = document.getElementById('hub-download-apk-status');
if (el) {
el.textContent = msg;
}
}
function resolveStableApkUrl() {
return fetch('/v0/ota/channel/stable.json', { cache: 'no-store' })
.then(function (r) {
if (!r.ok) {
throw new Error('stable channel HTTP ' + r.status);
}
return r.json();
})
.then(function (channel) {
var manifestUrl = channel && channel.manifestUrl;
if (!manifestUrl) {
throw new Error('stable.json missing manifestUrl');
}
return fetch(manifestUrl, { cache: 'no-store' }).then(function (r) {
if (!r.ok) {
throw new Error('manifest HTTP ' + r.status);
}
return r.json();
});
})
.then(function (manifest) {
var url = manifest && (manifest.apkUrl || manifest.bundleUrl);
if (!url) {
throw new Error('manifest missing apkUrl');
}
return url;
});
}
function wireApkButton() {
var btn = document.getElementById('hub-download-apk');
if (!btn) {
return;
}
btn.addEventListener('click', function () {
btn.disabled = true;
setStatus('Resolving stable OTA channel…');
resolveStableApkUrl()
.then(function (url) {
setStatus('Downloading…');
window.location.href = url;
})
.catch(function (err) {
setStatus('APK unavailable — run builder OTA publish (stable). ' + (err.message || err));
})
.finally(function () {
btn.disabled = false;
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', wireApkButton);
} else {
wireApkButton();
}
})();