Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a971204b80 |
@@ -78,13 +78,35 @@ class _ServersScreenState extends State<ServersScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (go == true) {
|
if (go != true || !mounted) return;
|
||||||
final ok = await UpdateService(widget.api.baseUrl).apply(info);
|
|
||||||
if (mounted && !ok) {
|
final progress = ValueNotifier<double?>(0);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showDialog(
|
||||||
const SnackBar(content: Text('Impossible d\'ouvrir le téléchargement.')),
|
context: context,
|
||||||
);
|
barrierDismissible: false,
|
||||||
}
|
builder: (_) => AlertDialog(
|
||||||
|
title: const Text('Téléchargement…'),
|
||||||
|
content: ValueListenableBuilder<double?>(
|
||||||
|
valueListenable: progress,
|
||||||
|
builder: (_, p, __) => Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
LinearProgressIndicator(value: p),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text(p == null ? '' : '${(p * 100).round()} %'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final ok = await UpdateService(widget.api.baseUrl)
|
||||||
|
.apply(info, onProgress: (p) => progress.value = p);
|
||||||
|
if (mounted) Navigator.of(context, rootNavigator: true).pop(); // ferme la progression
|
||||||
|
if (mounted && !ok) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Mise à jour impossible.')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:open_filex/open_filex.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
/// Vérifie s'il existe une version plus récente (API `/version`) et, si oui,
|
/// Détecte une version plus récente (`/version`) et l'installe **in-app** :
|
||||||
/// ouvre l'URL de l'APK (le navigateur télécharge, l'utilisateur installe —
|
/// télécharge l'APK dans le stockage de l'app puis lance l'installeur système
|
||||||
/// robuste, sans dépendance de packaging fragile).
|
/// (un seul tap « Installer »). Fallback navigateur si l'install directe échoue.
|
||||||
class UpdateService {
|
class UpdateService {
|
||||||
UpdateService(this._baseUrl);
|
UpdateService(this._baseUrl);
|
||||||
final Future<String> _baseUrl;
|
final Future<String> _baseUrl;
|
||||||
@@ -31,7 +34,39 @@ class UpdateService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> apply(UpdateInfo info) async {
|
/// Télécharge l'APK puis lance l'installeur. `onProgress` : 0.0 → 1.0
|
||||||
|
/// (ou null si la taille est inconnue). Renvoie true si l'installeur s'ouvre.
|
||||||
|
Future<bool> apply(UpdateInfo info, {void Function(double?)? onProgress}) async {
|
||||||
|
try {
|
||||||
|
final dir = await getExternalStorageDirectory() ?? await getTemporaryDirectory();
|
||||||
|
final file = File('${dir.path}/gamemanager-update.apk');
|
||||||
|
|
||||||
|
final req = http.Request('GET', Uri.parse(info.apkUrl));
|
||||||
|
final resp = await req.send().timeout(const Duration(seconds: 30));
|
||||||
|
if (resp.statusCode != 200) return _fallback(info);
|
||||||
|
|
||||||
|
final total = resp.contentLength ?? 0;
|
||||||
|
var received = 0;
|
||||||
|
final sink = file.openWrite();
|
||||||
|
await for (final chunk in resp.stream) {
|
||||||
|
sink.add(chunk);
|
||||||
|
received += chunk.length;
|
||||||
|
onProgress?.call(total > 0 ? received / total : null);
|
||||||
|
}
|
||||||
|
await sink.close();
|
||||||
|
|
||||||
|
final result = await OpenFilex.open(
|
||||||
|
file.path,
|
||||||
|
type: 'application/vnd.android.package-archive',
|
||||||
|
);
|
||||||
|
if (result.type == ResultType.done) return true;
|
||||||
|
return _fallback(info); // l'installeur n'a pas pris → navigateur
|
||||||
|
} catch (_) {
|
||||||
|
return _fallback(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _fallback(UpdateInfo info) async {
|
||||||
final uri = Uri.parse(info.apkUrl);
|
final uri = Uri.parse(info.apkUrl);
|
||||||
if (!await canLaunchUrl(uri)) return false;
|
if (!await canLaunchUrl(uri)) return false;
|
||||||
return launchUrl(uri, mode: LaunchMode.externalApplication);
|
return launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ dependencies:
|
|||||||
shared_preferences: ^2.3.2
|
shared_preferences: ^2.3.2
|
||||||
package_info_plus: ^8.1.1
|
package_info_plus: ^8.1.1
|
||||||
url_launcher: ^6.3.1
|
url_launcher: ^6.3.1
|
||||||
|
path_provider: ^2.1.4
|
||||||
|
open_filex: ^4.5.0
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|||||||
+13
-5
@@ -62,14 +62,22 @@ if "signingConfigs {" not in s:
|
|||||||
r"(\n\s*buildTypes\s*\{)",
|
r"(\n\s*buildTypes\s*\{)",
|
||||||
'\n signingConfigs {\n'
|
'\n signingConfigs {\n'
|
||||||
' release {\n'
|
' release {\n'
|
||||||
' keyAlias keystoreProperties["keyAlias"]\n'
|
' keyAlias = keystoreProperties["keyAlias"]\n'
|
||||||
' keyPassword keystoreProperties["keyPassword"]\n'
|
' keyPassword = keystoreProperties["keyPassword"]\n'
|
||||||
' storeFile file(keystoreProperties["storeFile"])\n'
|
' storeFile = file(keystoreProperties["storeFile"])\n'
|
||||||
' storePassword keystoreProperties["storePassword"]\n'
|
' storePassword = keystoreProperties["storePassword"]\n'
|
||||||
' }\n }\n\\1',
|
' }\n }\n\\1',
|
||||||
s,
|
s,
|
||||||
count=1,
|
count=1,
|
||||||
)
|
)
|
||||||
|
# Flutter 3.24 génère `signingConfig = signingConfigs.debug` (AVEC `=`). On gère
|
||||||
|
# les deux formes pour ne jamais laisser le build release signé en clé debug
|
||||||
|
# (sinon signature différente à chaque run CI → « conflit » à l'install de MAJ).
|
||||||
|
before = s
|
||||||
|
s = s.replace("signingConfig = signingConfigs.debug", "signingConfig = signingConfigs.release")
|
||||||
s = s.replace("signingConfig signingConfigs.debug", "signingConfig signingConfigs.release")
|
s = s.replace("signingConfig signingConfigs.debug", "signingConfig signingConfigs.release")
|
||||||
|
if s == before:
|
||||||
|
raise SystemExit("patch_android: ERREUR — ligne 'signingConfig ... debug' introuvable, "
|
||||||
|
"signature release NON appliquée (build annulé)")
|
||||||
open(gr, "w").write(s)
|
open(gr, "w").write(s)
|
||||||
print("patch_android: OK")
|
print("patch_android: OK (signature release appliquee)")
|
||||||
|
|||||||
Reference in New Issue
Block a user