Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.1.2 #118

Merged
merged 6 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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",
Expand Down
Loading