From d7e1bf7f346ef87bf8ce5282d3a8c645adef01de Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:46:30 +0200 Subject: [PATCH 1/6] Log required manifest version from theme --- css_theme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 {} From a183bbdffa198339de0161649ca8d825c1d83c18 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 13 May 2024 22:31:46 +0200 Subject: [PATCH 2/6] Extra logging --- css_inject.py | 2 +- main.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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/main.py b/main.py index dec1d1c..d6a5179 100644 --- a/main.py +++ b/main.py @@ -46,8 +46,13 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False), timeout=aiohttp.ClientTimeout(total=2)) 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 +60,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) From a91115242639ad551bf43a2c66afb992f9b3fd45 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 24 May 2024 17:55:35 +0200 Subject: [PATCH 3/6] Force aiohttp to not use a dns cache --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d6a5179..234fe41 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,7 @@ 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(verify_ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) as session: async with session.get(css_translations_url) as response: if response.status == 200: text = await response.text() From a8bd8a093233d5e1c7f5a4956a1afe49facef996 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 24 May 2024 22:02:38 +0200 Subject: [PATCH 4/6] Only fetch translations if an internet connection is active --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 234fe41..f3fd58b 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,7 +50,7 @@ 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, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) as session: + async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) as session: async with session.get(css_translations_url) as response: if response.status == 200: text = await response.text() From 3294e6384c22c087ee97f915eb793538fdab57e1 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 24 May 2024 22:30:57 +0200 Subject: [PATCH 5/6] Extend timeout for fetch --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f3fd58b..f743171 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ 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(ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) 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() From 9d3c82940f40e339d7a806d48502849cb0f877a9 Mon Sep 17 00:00:00 2001 From: Beebles <102569435+beebls@users.noreply.github.com> Date: Sat, 25 May 2024 10:08:58 -0600 Subject: [PATCH 6/6] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 270bd5d..75619c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SDH-CssLoader", - "version": "2.1.1", + "version": "2.1.2", "description": "A css loader", "scripts": { "build": "shx rm -rf dist && rollup -c",