From dad4bbf0ab0ff03ad635d7a195375c639a365051 Mon Sep 17 00:00:00 2001 From: goon-foss Date: Mon, 24 Aug 2026 14:27:06 +0200 Subject: [PATCH] fix(mobile): nie namawiaj na instalacje STARSZEJ wersji Apka porownywala wersje z serwerem przez `!==`, a nie "nowsza niz moja". Serwer trzyma numer najnowszego APK na sztywno w `app/main.py`, wiec w momencie, gdy aplikacja wyprzedza serwer, KAZDY uzytkownik nowej wersji dostawal monit "Update available" z propozycja zejscia w dol. Zlapane na emulatorze przy weryfikacji 0.3.0: swiezo zainstalowana 0.3.0 kazala zainstalowac 0.2.2. Bez tej weryfikacji poszloby to do ludzi. Wspolny `isNewerVersion` w `src/lib/appVersion.ts`, uzywany teraz i przez monit o APK, i przez bramkowanie wpisow w changelogu (byla tam druga kopia tej samej logiki). Sprawdzone na przypadkach granicznych, w tym 0.3.10 wobec 0.3.9 i pusta odpowiedz serwera. --- mobile/App.tsx | 4 ++-- mobile/src/lib/appVersion.ts | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) 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; +}