Skip to content

Commit

Permalink
check version on start
Browse files Browse the repository at this point in the history
  • Loading branch information
Deko committed Apr 25, 2024
1 parent eea2322 commit 5ad933c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit 5ad933c

Please sign in to comment.