From 0df1365f8b9baa05220ceb992cd19b079fc09ec1 Mon Sep 17 00:00:00 2001 From: Deko Date: Wed, 21 Aug 2024 20:01:02 +0200 Subject: [PATCH] do not exit on minor version mismatch --- alune/helpers.py | 20 ++++++++++++++------ main.py | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/alune/helpers.py b/alune/helpers.py index 21588e5..59c2131 100644 --- a/alune/helpers.py +++ b/alune/helpers.py @@ -57,24 +57,32 @@ def get_resource_path(relative_path: str | None = None): return str(path) -def is_version_string_newer(version_one: str, version_two: str): +def is_version_string_newer(version_one: str, version_two: str, ignore_minor_mismatch: bool = False): """ Checks if version_one is newer than version_two. Args: - version_one: The semantic version string to check - version_two: The semantic version string to check against + version_one: The semantic version string to check. + version_two: The semantic version string to check against. + ignore_minor_mismatch: Optional, whether to ignore that the minor version mismatches. Defaults to false. Returns: Whether version_one is newer than version_two. """ version_one_parts = version_one.split(".") version_two_parts = version_two.split(".") + version_part_amount = min(len(version_one_parts), len(version_two_parts)) - for i in range(min(len(version_one_parts), len(version_two_parts))): + for i in range(version_part_amount): try: - if int(version_one_parts[i]) > int(version_two_parts[i]): - return True + if int(version_one_parts[i]) <= int(version_two_parts[i]): + continue + + if ignore_minor_mismatch and i == version_part_amount - 1: + logger.warning("There is a newer minor version of TFT available. Please update as soon as possible.") + return False + + return True except ValueError: logger.warning( f"We could not check version {version_one} against {version_two}. " diff --git a/main.py b/main.py index 17ba0f5..8b1d082 100644 --- a/main.py +++ b/main.py @@ -418,8 +418,8 @@ async def check_phone_preconditions(adb_instance: ADB): ) play_store_version = installed_version - if helpers.is_version_string_newer(play_store_version, installed_version): - raise_and_exit("A new version of the TFT app is available. Please update to not be locked in queue.") + if helpers.is_version_string_newer(play_store_version, installed_version, ignore_minor_mismatch=True): + raise_and_exit("A new major version of the TFT app is available. An update is required.") logger.debug("Checking if TFT is active") if not await adb_instance.is_tft_active():