This commit is contained in:
@@ -47,21 +47,32 @@ 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;
|
||||
let apkUrl;
|
||||
|
||||
webPlatform.updates = {
|
||||
async checkUpdate() {
|
||||
try {
|
||||
const response = await fetch(YAML_URL);
|
||||
if (!response.ok) return { updateAvailable: false };
|
||||
if (!response.ok) {
|
||||
console.log('[UpdateCheck] Fetch failed:', response.status);
|
||||
return { updateAvailable: false };
|
||||
}
|
||||
const yaml = await response.text();
|
||||
|
||||
const versionMatch = yaml.match(/^version:\s*(.+)$/m);
|
||||
if (!versionMatch) return { updateAvailable: false };
|
||||
if (!versionMatch) {
|
||||
console.log('[UpdateCheck] No version found in YAML');
|
||||
return { updateAvailable: false };
|
||||
}
|
||||
const latestVersion = versionMatch[1].trim();
|
||||
|
||||
const pathMatch = yaml.match(/^path:\s*(.+)$/m);
|
||||
const apkFilename = pathMatch ? pathMatch[1].trim() : `DiscordClone-v${latestVersion}.apk`;
|
||||
apkUrl = `https://gitea.moyettes.com/Moyettes/DiscordClone/releases/download/latest/${apkFilename}`;
|
||||
|
||||
const { version: currentVersion } = await AppUpdater.getVersion();
|
||||
console.log('[UpdateCheck] Latest:', latestVersion, '| Current:', currentVersion);
|
||||
|
||||
const latest = latestVersion.split('.').map(Number);
|
||||
const current = currentVersion.split('.').map(Number);
|
||||
@@ -78,13 +89,15 @@ if (window.Capacitor?.isNativePlatform?.()) {
|
||||
if (l < c) break;
|
||||
}
|
||||
|
||||
return { updateAvailable, updateType, latestVersion, currentVersion, apkUrl: APK_URL };
|
||||
} catch {
|
||||
console.log('[UpdateCheck] Result:', updateAvailable ? updateType + ' update available' : 'up to date');
|
||||
return { updateAvailable, updateType, latestVersion, currentVersion, apkUrl };
|
||||
} catch (e) {
|
||||
console.log('[UpdateCheck] Error:', e.message);
|
||||
return { updateAvailable: false };
|
||||
}
|
||||
},
|
||||
async installUpdate() {
|
||||
await AppUpdater.downloadAndInstall({ url: APK_URL });
|
||||
await AppUpdater.downloadAndInstall({ url: apkUrl });
|
||||
},
|
||||
onDownloadProgress(callback) {
|
||||
AppUpdater.addListener('downloadProgress', callback);
|
||||
|
||||
Reference in New Issue
Block a user