Kml parser utf-8 támogatás, induláskor minimum app verzió ellenőrzése
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
/// Az app fallback csomagneve, ha a konfigurációs táblában nincs
|
||||
/// (vagy még nem tölthető le) update_url.
|
||||
const _fallbackUpdateUrl =
|
||||
'https://play.google.com/store/apps/details?id=hu.app_dev.terepi_seged';
|
||||
|
||||
class VersionGateResult {
|
||||
final bool blocked;
|
||||
final String message;
|
||||
final String updateUrl;
|
||||
|
||||
const VersionGateResult({
|
||||
required this.blocked,
|
||||
this.message = '',
|
||||
this.updateUrl = '',
|
||||
});
|
||||
|
||||
static const allowed = VersionGateResult(blocked: false);
|
||||
}
|
||||
|
||||
/// App-indításkor lefutó minimum-build ellenőrzés.
|
||||
///
|
||||
/// FONTOS — az app offline-first: ha a lekérdezés BÁRMI okból nem
|
||||
/// teljesül (nincs net, időtúllépés, a tábla/kulcs még nem létezik,
|
||||
/// bármilyen váratlan hiba), az ellenőrzés MINDIG átenged (fail-open).
|
||||
/// Kizárólag akkor blokkol, ha a szervertől egyértelmű, jól formázott
|
||||
/// választ kapott, hogy a jelenlegi build a minimum alatt van.
|
||||
Future<VersionGateResult> checkVersionGate() async {
|
||||
try {
|
||||
final rows = await Supabase.instance.client
|
||||
.from('terepi_seged_app_config')
|
||||
.select('key, value')
|
||||
.inFilter('key', const [
|
||||
'min_build_number',
|
||||
'update_message',
|
||||
'update_url',
|
||||
]).timeout(const Duration(seconds: 4));
|
||||
|
||||
final config = {
|
||||
for (final r in rows) r['key'] as String: r['value'] as String,
|
||||
};
|
||||
|
||||
final minBuild = int.tryParse(config['min_build_number'] ?? '');
|
||||
if (minBuild == null) {
|
||||
// Nincs (érvényesen) beállítva minimum — nincs mit ellenőrizni.
|
||||
return VersionGateResult.allowed;
|
||||
}
|
||||
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
final currentBuild = int.tryParse(info.buildNumber);
|
||||
if (currentBuild == null) {
|
||||
// A saját build-számunkat sem sikerült megállapítani — ez a mi
|
||||
// hibánk, nem a felhasználóé; nem blokkolunk emiatt.
|
||||
return VersionGateResult.allowed;
|
||||
}
|
||||
|
||||
if (currentBuild < minBuild) {
|
||||
return VersionGateResult(
|
||||
blocked: true,
|
||||
message: config['update_message'] ??
|
||||
'Az alkalmazás egy régebbi verzióját használod, ami már nem '
|
||||
'kompatibilis a szerverrel. Kérjük, telepítsd a legfrissebb '
|
||||
'verziót a folytatáshoz.',
|
||||
updateUrl: config['update_url'] ?? _fallbackUpdateUrl,
|
||||
);
|
||||
}
|
||||
return VersionGateResult.allowed;
|
||||
} catch (_) {
|
||||
// Hálózati hiba, timeout, hiányzó tábla stb. → MINDIG átenged.
|
||||
return VersionGateResult.allowed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user