11import 'package:http/http.dart' ;
22import 'package:mxc_logic/mxc_logic.dart' ;
3+ import 'package:yaml/yaml.dart' ;
34import 'package:mxc_logic/src/data/api/client/web3_client.dart' ;
45import 'package:mxc_logic/src/domain/const/urls.dart' ;
56
@@ -11,22 +12,31 @@ class AppVersionRepository {
1112 final DatadashClient _web3Client;
1213 final Client _restClient;
1314
14- Future <bool > checkLatestVersion (
15- String appSecret,
16- String groupId,
17- String appVersion,
18- ) async {
15+ Future <bool > checkLatestVersion (String appVersion) async {
1916 final res = await _restClient.get (
20- Uri .parse (
21- Urls .getLatestVersion (appSecret, groupId),
22- ),
23- headers: {'accept' : 'application/json' },
17+ Uri .parse (Urls .latestVersionYaml),
18+ headers: {'accept' : 'text/plain' },
2419 );
2520
26- final app = AppVersion . fromJson (res.body);
27- final latestVersion = int . parse (app. version! );
28- final currentVersion = int . parse (appVersion);
21+ if (res.statusCode != 200 ) {
22+ throw Exception ( 'Failed to fetch version information' );
23+ }
2924
30- return latestVersion > currentVersion;
25+ final yamlDoc = loadYaml (res.body);
26+ final latestVersion = yamlDoc['version' ] as String ;
27+
28+ return _isNewVersionAvailable (latestVersion, appVersion);
29+ }
30+
31+ bool _isNewVersionAvailable (String latestVersion, String currentVersion) {
32+ final latest = latestVersion.split ('.' ).map (int .parse).toList ();
33+ final current = currentVersion.split ('.' ).map (int .parse).toList ();
34+
35+ for (int i = 0 ; i < 3 ; i++ ) {
36+ if (latest[i] > current[i]) return true ;
37+ if (latest[i] < current[i]) return false ;
38+ }
39+
40+ return false ;
3141 }
3242}
0 commit comments