feat: Implement foundational UI styling, shared components, and web platform structure.
All checks were successful
Build and Release / build-and-release (push) Successful in 14m40s
All checks were successful
Build and Release / build-and-release (push) Successful in 14m40s
This commit is contained in:
@@ -44,4 +44,53 @@ const webPlatform = {
|
||||
},
|
||||
};
|
||||
|
||||
// Detect Android/Capacitor and enable native APK updates
|
||||
if (window.Capacitor?.isNativePlatform?.()) {
|
||||
const YAML_URL = 'https://gitea.moyettes.com/Moyettes/DiscordClone/releases/download/latest/latest-android.yml';
|
||||
const APK_URL = 'https://gitea.moyettes.com/Moyettes/DiscordClone/releases/download/latest/app-release.apk';
|
||||
const AppUpdater = window.Capacitor.Plugins.AppUpdater;
|
||||
|
||||
webPlatform.updates = {
|
||||
async checkUpdate() {
|
||||
try {
|
||||
const response = await fetch(YAML_URL);
|
||||
if (!response.ok) return { updateAvailable: false };
|
||||
const yaml = await response.text();
|
||||
|
||||
const versionMatch = yaml.match(/^version:\s*(.+)$/m);
|
||||
if (!versionMatch) return { updateAvailable: false };
|
||||
const latestVersion = versionMatch[1].trim();
|
||||
|
||||
const { version: currentVersion } = await AppUpdater.getVersion();
|
||||
|
||||
const latest = latestVersion.split('.').map(Number);
|
||||
const current = currentVersion.split('.').map(Number);
|
||||
let updateAvailable = false;
|
||||
let updateType = 'patch';
|
||||
for (let i = 0; i < Math.max(latest.length, current.length); i++) {
|
||||
const l = latest[i] || 0;
|
||||
const c = current[i] || 0;
|
||||
if (l > c) {
|
||||
updateAvailable = true;
|
||||
updateType = i === 0 ? 'major' : i === 1 ? 'minor' : 'patch';
|
||||
break;
|
||||
}
|
||||
if (l < c) break;
|
||||
}
|
||||
|
||||
return { updateAvailable, updateType, latestVersion, currentVersion, apkUrl: APK_URL };
|
||||
} catch {
|
||||
return { updateAvailable: false };
|
||||
}
|
||||
},
|
||||
async installUpdate() {
|
||||
await AppUpdater.downloadAndInstall({ url: APK_URL });
|
||||
},
|
||||
onDownloadProgress(callback) {
|
||||
AppUpdater.addListener('downloadProgress', callback);
|
||||
},
|
||||
};
|
||||
webPlatform.features.hasNativeUpdates = true;
|
||||
}
|
||||
|
||||
export default webPlatform;
|
||||
|
||||
Reference in New Issue
Block a user