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);
|
||||
|
||||
@@ -27,14 +27,14 @@ export function UpdateProvider({ children }) {
|
||||
return (
|
||||
<UpdateContext.Provider value={state}>
|
||||
{children}
|
||||
{state && (state.updateType === 'major' || state.updateType === 'minor') && (
|
||||
<ForcedUpdateModal latestVersion={state.latestVersion} />
|
||||
{state && (state.updateType === 'major' || state.updateType === 'minor' || !features.hasWindowControls) && (
|
||||
<ForcedUpdateModal updateType={state.updateType} latestVersion={state.latestVersion} />
|
||||
)}
|
||||
</UpdateContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function ForcedUpdateModal({ latestVersion }) {
|
||||
function ForcedUpdateModal({ updateType, latestVersion }) {
|
||||
const { links, updates } = usePlatform();
|
||||
const [downloading, setDownloading] = useState(false);
|
||||
const [progress, setProgress] = useState(0);
|
||||
@@ -62,12 +62,17 @@ function ForcedUpdateModal({ latestVersion }) {
|
||||
}
|
||||
};
|
||||
|
||||
const isPatch = updateType === 'patch';
|
||||
|
||||
return (
|
||||
<div className="forced-update-overlay">
|
||||
<div className="forced-update-modal">
|
||||
<h2>Update Required</h2>
|
||||
<h2>{isPatch ? 'Update Available' : 'Update Required'}</h2>
|
||||
<p>
|
||||
A new version (v{latestVersion}) is available. This update is required to continue using the app.
|
||||
{isPatch
|
||||
? `A new version (v${latestVersion}) is available.`
|
||||
: `A new version (v${latestVersion}) is available. This update is required to continue using the app.`
|
||||
}
|
||||
</p>
|
||||
{downloading ? (
|
||||
<div className="update-progress">
|
||||
|
||||
Reference in New Issue
Block a user