diff --git a/css_inject.py b/css_inject.py index b2d9003..4e82041 100644 --- a/css_inject.py +++ b/css_inject.py @@ -31,7 +31,7 @@ def initialize_class_mappings(): for y in data[uid][:-1]: CLASS_MAPPINGS[y] = latest_value - Log("Loaded css translations from local file") + Log(f"Loaded {len(CLASS_MAPPINGS)} css translations from local file") ALL_INJECTS = [] diff --git a/css_theme.py b/css_theme.py index a27d6e9..05d8250 100644 --- a/css_theme.py +++ b/css_theme.py @@ -64,7 +64,7 @@ def __init__(self, themePath : str, json : dict, configPath : str = None): self.tab_mappings = json["tabs"] if ("tabs" in json) else {} if (CSS_LOADER_VER < self.require): - raise Exception("A newer version of the CssLoader is required to load this theme") + raise Exception(f"A newer version of the CssLoader is required to load this theme (Read manifest version {self.require} but only up to {CSS_LOADER_VER} is supported)") self.dependencies = json["dependencies"] if "dependencies" in json else {} diff --git a/main.py b/main.py index 78a7344..4a0de03 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -import os, asyncio, sys, time, aiohttp, json +import os, asyncio, sys, time, aiohttp, json, socket from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer @@ -32,6 +32,13 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): if SUCCESSFUL_FETCH_THIS_RUN: return + + try: + socket.setdefaulttimeout(3) + socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53)) + except: + Log("No internet connection. Not fetching css translations") + return setting = util_store_read("beta_translations") @@ -43,11 +50,16 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): 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: + async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=30)) as session: async with session.get(css_translations_url) as response: if response.status == 200: + text = await response.text() + + if len(text.strip()) <= 0: + raise Exception("Empty response") + with open(css_translations_path, "w", encoding="utf-8") as fp: - fp.write(await response.text()) + fp.write(text) SUCCESSFUL_FETCH_THIS_RUN = True Log(f"Fetched css translations from server") @@ -55,9 +67,8 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): asyncio.get_running_loop().create_task(loader.reset(silent=True)) except Exception as ex: - Log(f"Failed to fetch css translations from server: {str(ex)}") + Log(f"Failed to fetch css translations from server [{type(ex).__name__}]: {str(ex)}") - async def every(__seconds: float, func, *args, **kwargs): while True: await func(*args, **kwargs) diff --git a/package.json b/package.json index ded1ab2..11e4cfc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "SDH-CssLoader", "type": "module", - "version": "2.1.1", + "version": "2.2.0", "description": "A css loader", "scripts": { "build": "shx rm -rf dist && rollup -c",