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.
This commit is contained in:
goon-foss 2026-08-24 14:27:06 +02:00
parent b7a8911441
commit dad4bbf0ab
2 changed files with 27 additions and 3 deletions

View file

@ -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!;

View file

@ -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;
}