From 79c49487e29427801eea13627b314090afa3e699 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sun, 30 Oct 2022 00:28:54 +0200 Subject: [PATCH] Improved version checking --- lib/base.dart | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/base.dart b/lib/base.dart index 34611e1..b6eb0f3 100644 --- a/lib/base.dart +++ b/lib/base.dart @@ -41,12 +41,30 @@ class _BaseState extends State with WidgetsBindingObserver { final PermissionHandlerPlatform permissionHandler = PermissionHandlerPlatform.instance; + bool updateExists(String appVersion, String gitHubVersion) { + final List appVersionSplit = List.from(appVersion.split('.').map((e) => int.parse(e))); + final List gitHubVersionSplit = List.from(gitHubVersion.split('.').map((e) => int.parse(e))); + + if (gitHubVersionSplit[0] > appVersionSplit[0]) { + return true; + } + else if (gitHubVersionSplit[0] == appVersionSplit[0] && gitHubVersionSplit[1] > appVersionSplit[1]) { + return true; + } + else if (gitHubVersionSplit[0] == appVersionSplit[0] && gitHubVersionSplit[1] == appVersionSplit[1] && gitHubVersionSplit[2] > appVersionSplit[2]) { + return true; + } + else { + return false; + } + } + Future checkInstallationSource() async { Source installationSource = await StoreChecker.getSource; if (installationSource != Source.IS_INSTALLED_FROM_PLAY_STORE) { final result = await checkAppUpdatesGitHub(); if (result['result'] == 'success') { - if (result['body'].tagName != widget.appConfigProvider.getAppInfo!.version) { + if (updateExists(widget.appConfigProvider.getAppInfo!.version, result['body'].tagName)) { return result['body']; } }