Skip to content

Commit

Permalink
Merge branch 'dev' into rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Jun 29, 2024
2 parents 9088f72 + 9d3c829 commit 97faf89
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion css_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
2 changes: 1 addition & 1 deletion css_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
21 changes: 16 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

Expand All @@ -43,21 +50,25 @@ 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")
initialize_class_mappings()
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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 97faf89

Please sign in to comment.