diff --git a/mobile/App.tsx b/mobile/App.tsx index 3dc79cb..254d8d9 100644 --- a/mobile/App.tsx +++ b/mobile/App.tsx @@ -32,7 +32,7 @@ import { OnboardingModal } from './src/components/OnboardingModal'; import { WhatsNewModal } from './src/components/WhatsNewModal'; import { ErrorBoundary } from './src/ErrorBoundary'; import { isAccepted as isAgeGateAccepted } from './src/lib/agegate'; -import { APP_VERSION } from './src/lib/appVersion'; +import { APP_VERSION, isNewerVersion } from './src/lib/appVersion'; import { DEFAULT_API_KEY, DEFAULT_BACKEND_URL } from './src/lib/backend'; import { getSettings as getLockSettings } from './src/lib/applock'; import { AppNavigator } from './src/navigation'; @@ -257,7 +257,7 @@ export default function App() { try { const out = await client.getServerVersion(); const bundled = APP_VERSION; - if (out.version && out.version !== bundled && out.apk_url) { + if (out.version && isNewerVersion(out.version, bundled) && out.apk_url) { // In-app installer dostępny → "Install" zamiast "Download" if (apkInstallerAvailable) { const pendingApkUrl = out.apk_url!; diff --git a/mobile/src/lib/appVersion.ts b/mobile/src/lib/appVersion.ts index 0a053ce..a2ca123 100644 --- a/mobile/src/lib/appVersion.ts +++ b/mobile/src/lib/appVersion.ts @@ -17,4 +17,28 @@ import Constants from 'expo-constants'; * też nie idzie do góry, więc consistency jest zachowana. */ export const APP_VERSION: string = - (Constants.expoConfig?.version as string | undefined) || '0.2.2'; + (Constants.expoConfig?.version as string | undefined) || '0.3.0'; + + +/** „0.3.0" → [0,3,0]. Człony nieliczbowe (np. „0.3.0-rc1") lecą na 0. */ +function versionParts(v: string): number[] { + return String(v || '').split('.').map((x) => parseInt(x, 10) || 0); +} + +/** + * Czy `candidate` jest NOWSZA niż `current`. + * + * Po co, skoro wcześniej wystarczyło `!==`: serwer trzyma numer najnowszego APK na + * sztywno, a przy wydaniu 0.3.0 nie został podbity od razu. Porównanie „różne" kazało + * wtedy KAŻDEMU użytkownikowi 0.3.0 zainstalować 0.2.2, czyli cofnąć się o wersję. + * Złapane na emulatorze przed publikacją. + */ +export function isNewerVersion(candidate: string, current: string): boolean { + const a = versionParts(candidate); + const b = versionParts(current); + for (let i = 0; i < Math.max(a.length, b.length); i++) { + const d = (a[i] ?? 0) - (b[i] ?? 0); + if (d !== 0) return d > 0; + } + return false; +}