Skip to content

Commit

Permalink
Merge pull request #83 from suchmememanyskill/dev
Browse files Browse the repository at this point in the history
Add standalone/decky check, as well as priority themes.
  • Loading branch information
suchmememanyskill authored May 28, 2023
2 parents e5419ab + d4f7bc1 commit da37264
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions css_tab_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ async def connect(self, skip_if_connected : bool = False) -> Result:
self.tab = await injector.get_tab_lambda(lambda x : _match_tab(x, self.tab_names_regex, self.tab_url_parts))
Log(f"Connected to tab {self.get_name()}")
except Exception as e:
if (str(e) == "Tab not found by lambda"):
return Result(False, str(e), False)

return Result(False, f"{str(e)} ({self.tab_names_regex})")

return Result(True)
Expand Down
8 changes: 8 additions & 0 deletions css_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def __init__(self, themePath : str, json : dict, configPath : str = None):
self.bundled = self.configPath != self.themePath
self.enabled = False
self.json = json
self.priority_mod = 0

try:
if (os.path.join(themePath, "PRIORITY")):
with open(os.path.join(themePath, "PRIORITY")) as fp:
self.priority_mod = int(fp.readline().strip())
except:
pass

if (json is None):
if not os.path.exists(os.path.join(themePath, "theme.css")):
Expand Down
3 changes: 2 additions & 1 deletion css_themepatchcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def generate(self) -> Result:
except Exception as e:
return Result(False, str(e))

self.inject.css = f":root {{ {self.css_variable}: url({join('/themes_custom/', self.value.replace(' ', '%20'))}) }}"
path = join('/themes_custom/', self.value.replace(' ', '%20').replace('\\', '/'))
self.inject.css = f":root {{ {self.css_variable}: url({path}) }}"
return Result(True)

async def generate_and_reinject(self) -> Result:
Expand Down
4 changes: 2 additions & 2 deletions css_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def Log(text : str):
Logger.info(f"[CSS_Loader] {text}")

class Result:
def __init__(self, success : bool, message : str = "Success"):
def __init__(self, success : bool, message : str = "Success", log : bool = True):
self.success = success
self.message = message

if not self.success:
if log and not self.success:
Log(f"Result failed! {message}")

def raise_on_failure(self):
Expand Down
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from css_server import start_server

ALWAYS_RUN_SERVER = False
IS_STANDALONE = False

try:
if not store_or_file_config("no_redirect_logs"):
Expand Down Expand Up @@ -45,6 +46,9 @@ def on_modified(self, event):


class Plugin:
async def is_standalone(self) -> bool:
return IS_STANDALONE

async def dummy_function(self) -> bool:
return True

Expand Down Expand Up @@ -396,6 +400,8 @@ async def _load(self):
async def _set_theme_score(self, theme : Theme):
if theme.name not in self.scores:
self.scores[theme.name] = 0

self.scores[theme.name] += theme.priority_mod

for x in theme.dependencies:
dependency = await self._get_theme(self, x)
Expand Down Expand Up @@ -460,6 +466,7 @@ async def _main(self):

if __name__ == '__main__':
ALWAYS_RUN_SERVER = True
IS_STANDALONE = True
import logging

logging.basicConfig(
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": "1.6.1",
"version": "1.6.2",
"description": "A css loader",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
Expand Down

0 comments on commit da37264

Please sign in to comment.