From 5ad933c3beb4335cc4afd7e818325ad9a8a2d619 Mon Sep 17 00:00:00 2001 From: Deko Date: Thu, 25 Apr 2024 23:03:53 +0200 Subject: [PATCH] check version on start --- main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.py b/main.py index 4271019..6be9ca0 100644 --- a/main.py +++ b/main.py @@ -5,8 +5,12 @@ import asyncio from enum import auto from enum import StrEnum +import importlib.metadata +import json import os from random import Random +from urllib.error import HTTPError +import urllib.request from adb_shell.exceptions import TcpTimeoutException import google_play_scraper @@ -340,6 +344,28 @@ async def check_phone_preconditions(adb_instance: ADB): await adb_instance.start_tft_app() +async def check_version(): + """ + Checks the remote version against the local version and prints out a warning if remote is newer. + """ + local_version = importlib.metadata.version("Alune") + try: + with urllib.request.urlopen( + "https://api.github.com/repos/TeamFightTacticsBots/Alune/releases/latest" + ) as remote_release: + remote_version = json.loads(remote_release.read().decode("utf-8"))["tag_name"].replace("v", "") + if helpers.is_version_string_newer(remote_version, local_version): + logger.warning( + "A newer version is available. " + "You can download it at https://github.com/TeamFightTacticsBots/Alune/releases/latest" + ) + return + except HTTPError: + logger.debug("Remote is not reachable, assuming local is newer.") + + logger.info("You are running the latest version.") + + async def main(): """ Main method, loads ADB connection, checks if the phone is ready to be used and @@ -350,6 +376,8 @@ async def main(): os.mkdir(logs_path) logger.add(logs_path + "/{time}.log", level="DEBUG", retention=10) + await check_version() + adb_instance = ADB() await adb_instance.load() if not adb_instance.is_connected():