v check fix
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
class Tables {
|
class Tables {
|
||||||
|
static const String appConfig = 'app_config';
|
||||||
static const String attachments = 'attachments';
|
static const String attachments = 'attachments';
|
||||||
static const String brands = 'brands';
|
static const String brands = 'brands';
|
||||||
static const String campaigns = 'campaigns';
|
static const String campaigns = 'campaigns';
|
||||||
|
|||||||
@@ -1,67 +1,94 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'dart:io' show Platform;
|
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
class VersionCheckService {
|
class VersionCheckService {
|
||||||
final _supabase = Supabase.instance.client;
|
|
||||||
|
|
||||||
/// Controlla se l'app corrente deve essere bloccata o aggiornata.
|
|
||||||
/// Ritorna il link di download se l'aggiornamento è obbligatorio, altrimenti null.
|
|
||||||
Future<String?> checkForceUpdate() async {
|
Future<String?> checkForceUpdate() async {
|
||||||
try {
|
try {
|
||||||
// 1. Determiniamo la piattaforma corrente
|
// 1. Capiamo su che piattaforma sta girando l'app in questo istante
|
||||||
String platformKey = 'web';
|
String currentPlatform = _getCurrentPlatform();
|
||||||
if (!kIsWeb) {
|
|
||||||
if (Platform.isAndroid) platformKey = 'android';
|
// 2. Recuperiamo SOLO la riga corrispondente alla nostra piattaforma
|
||||||
if (Platform.isWindows) platformKey = 'windows';
|
final dbResponse = await Supabase.instance.client
|
||||||
|
.from('app_config')
|
||||||
|
.select('min_version, download_url')
|
||||||
|
.eq('platform', currentPlatform)
|
||||||
|
.maybeSingle(); // Usiamo maybeSingle così se non c'è la riga non crasha
|
||||||
|
|
||||||
|
if (dbResponse == null) {
|
||||||
|
return null; // Nessuna regola per questa piattaforma
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Recuperiamo la configurazione minima da Supabase
|
String minVersionFromDb = dbResponse['min_version'] as String;
|
||||||
final data = await _supabase
|
String downloadUrl = dbResponse['download_url'] as String;
|
||||||
.from('app_config')
|
|
||||||
.select()
|
|
||||||
.eq('platform', platformKey)
|
|
||||||
.maybeSingle();
|
|
||||||
|
|
||||||
if (data == null) return null;
|
// 3. Recuperiamo la versione locale di Flutter
|
||||||
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
|
String localVersionRaw = packageInfo.version;
|
||||||
|
|
||||||
final String minVersion = data['min_version'];
|
// 🥷 TRUCCO 1: Pulizia totale dai build number (+37) o tag "v"
|
||||||
final String downloadUrl = data['download_url'];
|
String cleanLocal = localVersionRaw
|
||||||
|
.split('+')
|
||||||
|
.first
|
||||||
|
.replaceAll('v', '')
|
||||||
|
.trim();
|
||||||
|
String cleanDb = minVersionFromDb
|
||||||
|
.split('+')
|
||||||
|
.first
|
||||||
|
.replaceAll('v', '')
|
||||||
|
.trim();
|
||||||
|
|
||||||
// 3. Recuperiamo la versione attuale dell'app dal pubspec.yaml
|
// 🥷 TRUCCO 2: Confronto Semantico Reale
|
||||||
final packageInfo = await PackageInfo.fromPlatform();
|
if (_isVersionLower(current: cleanLocal, minimum: cleanDb)) {
|
||||||
final String currentVersion = packageInfo.version;
|
// Ritorna il link VERO per questa specifica piattaforma preso dal CSV!
|
||||||
|
return downloadUrl;
|
||||||
// 4. Confronto matematico semantico (es. 1.2.3 vs 1.1.9)
|
|
||||||
if (_isVersionLower(currentVersion, minVersion)) {
|
|
||||||
return downloadUrl; // Aggiornamento obbligatorio richiesto!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Errore controllo versione: $e');
|
debugPrint("Errore durante il check versione: $e");
|
||||||
return null; // In caso di errore non blocchiamo l'utente
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isVersionLower(String current, String min) {
|
// Helper ninja per mappare le piattaforme in base alle stringhe del tuo DB
|
||||||
|
String _getCurrentPlatform() {
|
||||||
|
if (kIsWeb) return 'web';
|
||||||
|
if (Platform.isAndroid) return 'android';
|
||||||
|
if (Platform.isIOS) return 'ios';
|
||||||
|
if (Platform.isWindows) return 'windows';
|
||||||
|
if (Platform.isMacOS) return 'macos';
|
||||||
|
if (Platform.isLinux) return 'linux';
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Il motore matematico (resta invariato)
|
||||||
|
bool _isVersionLower({required String current, required String minimum}) {
|
||||||
|
if (current == minimum) return false;
|
||||||
|
|
||||||
List<int> currentParts = current
|
List<int> currentParts = current
|
||||||
.split('.')
|
.split('.')
|
||||||
.map((e) => int.tryParse(e) ?? 0)
|
.map((e) => int.tryParse(e) ?? 0)
|
||||||
.toList();
|
.toList();
|
||||||
List<int> minParts = min
|
List<int> minParts = minimum
|
||||||
.split('.')
|
.split('.')
|
||||||
.map((e) => int.tryParse(e) ?? 0)
|
.map((e) => int.tryParse(e) ?? 0)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
while (currentParts.length < 3) {
|
||||||
int currentPart = currentParts.length > i ? currentParts[i] : 0;
|
currentParts.add(0);
|
||||||
int minPart = minParts.length > i ? minParts[i] : 0;
|
|
||||||
|
|
||||||
if (currentPart < minPart) return true;
|
|
||||||
if (currentPart > minPart) return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
while (minParts.length < 3) {
|
||||||
|
minParts.add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentParts[0] != minParts[0]) {
|
||||||
|
return currentParts[0] < minParts[0];
|
||||||
|
}
|
||||||
|
if (currentParts[1] != minParts[1]) {
|
||||||
|
return currentParts[1] < minParts[1];
|
||||||
|
}
|
||||||
|
return currentParts[2] < minParts[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,9 +352,7 @@ class _GlobalUpdateCheckerState extends State<GlobalUpdateChecker>
|
|||||||
|
|
||||||
// Riapriamo il rubinetto di Supabase
|
// Riapriamo il rubinetto di Supabase
|
||||||
_versionSubscription = GetIt.I<SupabaseClient>()
|
_versionSubscription = GetIt.I<SupabaseClient>()
|
||||||
.from(
|
.from('app_config') // <-- Sostituisci col nome reale della tua tabella
|
||||||
'app_versions',
|
|
||||||
) // <-- Sostituisci col nome reale della tua tabella
|
|
||||||
.stream(primaryKey: ['id'])
|
.stream(primaryKey: ['id'])
|
||||||
.listen((_) {
|
.listen((_) {
|
||||||
_checkVersion();
|
_checkVersion();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: flux
|
name: flux
|
||||||
description: "Gestione attività negozio di telefonia"
|
description: "Gestione attività negozio di telefonia"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 1.1.18+36
|
version: 1.1.20+38
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.11.3
|
sdk: ^3.11.3
|
||||||
|
|||||||
Reference in New Issue
Block a user