From 44805c69398592c5856c4ebc71dca9709dadd537 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:33:34 +0200 Subject: [PATCH] Automatically get steam branch for translations --- css_utils.py | 4 ++++ main.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/css_utils.py b/css_utils.py index 59882c6..9067182 100644 --- a/css_utils.py +++ b/css_utils.py @@ -99,6 +99,10 @@ def get_steam_path() -> str: else: return f"{get_user_home()}/.steam/steam" +def is_steam_beta_active() -> bool: + beta_path = os.path.join(get_steam_path(), "package", "beta") + return os.path.exists(beta_path) + def create_steam_symlink() -> Result: return create_symlink(get_theme_path(), os.path.join(get_steam_path(), "steamui", "themes_custom")) diff --git a/main.py b/main.py index f09f58a..e9e9492 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ sys.path.append(os.path.dirname(__file__)) -from css_utils import Log, create_steam_symlink, Result, get_theme_path, store_read as util_store_read, store_write as util_store_write, store_or_file_config +from css_utils import Log, create_steam_symlink, Result, get_theme_path, store_read as util_store_read, store_write as util_store_write, store_or_file_config, is_steam_beta_active from css_inject import ALL_INJECTS, initialize_class_mappings from css_theme import CSS_LOADER_VER from css_remoteinstall import install @@ -34,7 +34,13 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): return setting = util_store_read("beta_translations") - css_translations_url = "https://api.deckthemes.com/beta.json" if (setting == "1" or setting == "true") else "https://api.deckthemes.com/stable.json" + + if ((len(setting.strip()) < 0 or setting == "-1" or setting == "auto") and is_steam_beta_active()) or (setting == "1" or setting == "true"): + css_translations_url = "https://api.deckthemes.com/beta.json" + else: + css_translations_url = "https://api.deckthemes.com/stable.json" + + Log(f"Fetching CSS mappings from {css_translations_url}") try: async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False), timeout=aiohttp.ClientTimeout(total=2)) as session: