From 242b9b2e3fca48289a466694ae1949bdc3d042c7 Mon Sep 17 00:00:00 2001 From: Michele Righi Date: Thu, 18 Jan 2024 00:24:32 +0100 Subject: [PATCH] update AppUpdater: + sistemato il controllo delle nuove versioni (prima controllava solo minor e major, ora controlla anche la patch version). --- .../lib/model/AppUpdater.dart | 30 ++++++++++++++----- app-mobile/flutter_application/pubspec.lock | 6 ++-- app-mobile/flutter_application/pubspec.yaml | 3 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app-mobile/flutter_application/lib/model/AppUpdater.dart b/app-mobile/flutter_application/lib/model/AppUpdater.dart index 7c1d0c6..0816182 100644 --- a/app-mobile/flutter_application/lib/model/AppUpdater.dart +++ b/app-mobile/flutter_application/lib/model/AppUpdater.dart @@ -16,17 +16,22 @@ class AppUpdater { try { Map json = jsonDecode(response.body); String tagName = json['tag_name']; - List repoVersion = tagName.replaceAll("v", "").split("."); + List segmentsRepoV = tagName.replaceAll("v", "").split("."); - int repoMajor = int.parse(repoVersion[0]); - int repoMinor = int.parse(repoVersion[1]); + List segmentsCurrV = currentVersion.split("."); - List splittedCurrentVersion = currentVersion.split("."); - int currentMajor = int.parse(splittedCurrentVersion[0]); - int currentMinor = int.parse(splittedCurrentVersion[1]); + for (int i = 0; + i < segmentsRepoV.length && i < segmentsCurrV.length; + i++) { + if (int.parse(segmentsRepoV[i]) > int.parse(segmentsCurrV[i])) { + newVersionPresent = true; + break; + } + } - newVersionPresent = currentMajor < repoMajor || - (currentMajor == repoMajor && currentMinor < repoMinor); + // test + print(newVersionPresent); + return (newVersionPresent, newVersion, newVersionDownloadURL); if (newVersionPresent) { newVersion = tagName; @@ -60,3 +65,12 @@ class AppUpdater { return (newVersionPresent, newVersion, newVersionDownloadURL); } } + +void main() { + AppUpdater.checkNewVersion("1.09.1"); + AppUpdater.checkNewVersion("1.09.1"); + AppUpdater.checkNewVersion("1.10.1"); + AppUpdater.checkNewVersion("1.10.0"); + AppUpdater.checkNewVersion("1.11.0"); + AppUpdater.checkNewVersion("2.9.0"); +} diff --git a/app-mobile/flutter_application/pubspec.lock b/app-mobile/flutter_application/pubspec.lock index 9221499..0b61b18 100644 --- a/app-mobile/flutter_application/pubspec.lock +++ b/app-mobile/flutter_application/pubspec.lock @@ -129,13 +129,13 @@ packages: source: sdk version: "0.0.0" http: - dependency: transitive + dependency: "direct main" description: name: http - sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139 + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba url: "https://pub.dev" source: hosted - version: "1.1.2" + version: "1.2.0" http_parser: dependency: transitive description: diff --git a/app-mobile/flutter_application/pubspec.yaml b/app-mobile/flutter_application/pubspec.yaml index c873ffa..708f2a4 100644 --- a/app-mobile/flutter_application/pubspec.yaml +++ b/app-mobile/flutter_application/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.11.0 +version: 1.10.1 environment: sdk: '>=3.0.6 <4.0.0' @@ -43,6 +43,7 @@ dependencies: file_picker: ^5.3.3 desktop_window: ^0.4.0 flutter_svg: ^2.0.9 + http: ^1.2.0 dev_dependencies: flutter_test: