-
Notifications
You must be signed in to change notification settings - Fork 7
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
abef997
commit b753434
Showing
11 changed files
with
343 additions
and
6 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"> | ||
<external-path name="external_download" path="Download"/> | ||
</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
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,3 @@ | ||
class Configuration { | ||
static const bool enable_android_updater = true; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
lib/services/update_check/android_update_check_result.dart
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,19 @@ | ||
class AndroidUpdateCheckResult { | ||
String installedVersion; | ||
String newestVersion; | ||
DateTime updatedAt; | ||
String downloadUrl; | ||
String sha256Checksum; | ||
Map<String, dynamic>? changelog; | ||
|
||
AndroidUpdateCheckResult({ | ||
required this.installedVersion, | ||
required this.newestVersion, | ||
required this.updatedAt, | ||
required this.downloadUrl, | ||
required this.sha256Checksum, | ||
this.changelog, | ||
}); | ||
|
||
get updateAvailable => this.installedVersion != this.newestVersion; | ||
} |
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,35 @@ | ||
import 'dart:convert'; | ||
import 'package:greenpass_app/services/update_check/android_update_check_result.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:package_info/package_info.dart'; | ||
|
||
class UpdateCheck { | ||
static const String _currentVersionUrl = 'https://raw.githubusercontent.com/GreenPassApp/shared-data/main/current-app-version.json'; | ||
|
||
static AndroidUpdateCheckResult? androidUpdateCheckResult; | ||
static bool updateAvailable = androidUpdateCheckResult?.updateAvailable ?? false; | ||
|
||
static Future<void> initAppStart() async { | ||
try { | ||
Response res = await get(Uri.parse(_currentVersionUrl)); | ||
Map<String, dynamic> parsedJson = jsonDecode(res.body); | ||
Map<String, dynamic> androidVerInfo = parsedJson['android']; | ||
|
||
androidUpdateCheckResult = AndroidUpdateCheckResult( | ||
installedVersion: await _getVersionCode(), | ||
newestVersion: androidVerInfo['version'], | ||
updatedAt: DateTime.parse(androidVerInfo['updated_at']), | ||
downloadUrl: androidVerInfo['download']['url'], | ||
sha256Checksum: androidVerInfo['download']['sha256'], | ||
changelog: androidVerInfo.containsKey('changelog') ? androidVerInfo['changelog'] : null, | ||
); | ||
} catch (_) { | ||
return null; | ||
} | ||
} | ||
|
||
static Future<String> _getVersionCode() async { | ||
PackageInfo packageInfo = await PackageInfo.fromPlatform(); | ||
return packageInfo.version; | ||
} | ||
} |
Oops, something went wrong.