-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78a507a
commit 4ceff6e
Showing
7 changed files
with
169 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<files-path name="internal_apk_storage" path="ota_update/"/> | ||
</paths> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:ota_update/ota_update.dart'; | ||
|
||
import '../utils/update_manager.dart'; | ||
|
||
OverlayEntry updateDialog() { | ||
late OverlayEntry entry; | ||
entry = OverlayEntry( | ||
builder: (BuildContext context) { | ||
return UpdateDialog(entry: entry); | ||
} | ||
); | ||
|
||
return entry; | ||
} | ||
|
||
|
||
class UpdateDialog extends StatefulWidget { | ||
final OverlayEntry entry; | ||
|
||
UpdateDialog({required this.entry}); | ||
|
||
@override | ||
State<UpdateDialog> createState() => _UpdateDialog(entry: entry); | ||
} | ||
|
||
|
||
class _UpdateDialog extends State<UpdateDialog> with TickerProviderStateMixin { | ||
OverlayEntry? entry; | ||
late AlertDialog dialog; | ||
String title = 'Mise à jour disponible'; | ||
String content = 'Une nouvelle version de l\'application est disponible. Voulez-vous la télécharger ?'; | ||
|
||
_UpdateDialog({required this.entry}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
dialog = AlertDialog( | ||
title: Text(title), | ||
content: Text(content), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text('Non'), | ||
onPressed: () { | ||
entry?.remove(); | ||
}, | ||
), | ||
TextButton( | ||
child: const Text('Oui'), | ||
onPressed: () { | ||
var stream = installUpdate(); | ||
stream.then((stream) => { | ||
stream.listen( | ||
(OtaEvent event) { | ||
title = "Downloading..."; | ||
content = "${event.value}%"; | ||
setState(() {}); | ||
if (event.status != OtaStatus.DOWNLOADING) { | ||
entry?.remove(); | ||
} | ||
} | ||
) | ||
}); | ||
}, | ||
), | ||
], | ||
); | ||
|
||
return dialog; | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:ota_update/ota_update.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:package_info_plus/package_info_plus.dart'; | ||
|
||
Future<String> fetchLatestVersion() async { | ||
final response = await http.get( | ||
Uri.parse('https://api.github.com/repos/atomic-junky/CatsukaApp/releases/latest'), | ||
headers: {'Accept': 'application/vnd.github+json'}, | ||
); | ||
|
||
|
||
if (response.statusCode == 200) { | ||
final release = json.decode(response.body); | ||
return release['tag_name'].replaceFirst("v",""); | ||
} else { | ||
throw Exception('Failed to load release'); | ||
} | ||
} | ||
|
||
Future<bool> checkForUpdate() async { | ||
PackageInfo packageInfo = await PackageInfo.fromPlatform(); | ||
|
||
String latestVersion = await fetchLatestVersion(); | ||
String currentVersion = packageInfo.version; | ||
|
||
return latestVersion != currentVersion; | ||
} | ||
|
||
Future<Stream<OtaEvent>> installUpdate() async { | ||
String latestVersion = await fetchLatestVersion(); | ||
|
||
return OtaUpdate() | ||
.execute( | ||
'https://github.com/atomic-junky/CatsukaApp/releases/download/v$latestVersion/app-arm64-v8a-release.apk', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters