Skip to content

Commit

Permalink
Split off settings in different file
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Sep 15, 2024
1 parent 239efa8 commit 19e0b51
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
7 changes: 3 additions & 4 deletions css_mappings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os, asyncio, aiohttp
from css_loader import get_loader_instance
from css_utils import Log, store_read, is_steam_beta_active, get_theme_path
from css_utils import Log, get_theme_path
from css_settings import setting_beta_mappings
from css_inject import initialize_class_mappings
from css_browserhook import ON_WEBSOCKET_CONNECT

Expand All @@ -13,9 +14,7 @@ async def __fetch_class_mappings(css_translations_path : str):
if SUCCESSFUL_FETCH_THIS_RUN:
return

setting = store_read("beta_translations")

if ((len(setting.strip()) <= 0 or setting == "-1" or setting == "auto") and is_steam_beta_active()) or (setting == "1" or setting == "true"):
if setting_beta_mappings():
css_translations_url = "https://api.deckthemes.com/beta.json"
else:
css_translations_url = "https://api.deckthemes.com/stable.json"
Expand Down
5 changes: 3 additions & 2 deletions css_remoteinstall.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio, json, tempfile, os, aiohttp, zipfile, shutil
from css_utils import Result, Log, get_theme_path, store_or_file_config
from css_utils import Result, Log, get_theme_path
from css_settings import setting_install_dependencies
from css_theme import CSS_LOADER_VER, Theme

async def run(command : str) -> str:
Expand Down Expand Up @@ -57,7 +58,7 @@ async def install(id : str, base_url : str, local_themes : list) -> Result:

tempDir.cleanup()

if not store_or_file_config("no_deps_install"):
if setting_install_dependencies():
for x in data["dependencies"]:
if x["name"] in local_themes:
continue
Expand Down
29 changes: 29 additions & 0 deletions css_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from css_utils import get_theme_path, store_write, store_read, is_steam_beta_active

def store_or_file_config(key : str) -> bool:
if os.path.exists(os.path.join(get_theme_path(), key.upper())):
return True

read = store_read(key)
return read == "True" or read == "1"

def setting_beta_mappings() -> bool:
setting = store_read("beta_translations")

return ((len(setting.strip()) <= 0 or setting == "-1" or setting == "auto") and is_steam_beta_active()) or (setting == "1" or setting == "true")

def setting_redirect_logs() -> bool:
return not store_or_file_config("no_redirect_logs")

def setting_watch_files() -> bool:
return store_or_file_config("watch")

def set_setting_watch_files(watch : bool):
store_write("watch", "1" if watch else "0")

def setting_run_server() -> bool:
return store_or_file_config("server")

def setting_install_dependencies() -> bool:
return not store_or_file_config("no_deps_install")
9 changes: 1 addition & 8 deletions css_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,4 @@ def save_mappings(val: str, version: str):

file_location = os.path.join(path, f"{version}.{branch_str}.json")
with open(file_location, 'w') as fp:
fp.write(val)

def store_or_file_config(key : str) -> bool:
if os.path.exists(os.path.join(get_theme_path(), key.upper())):
return True

read = store_read(key)
return read == "True" or read == "1"
fp.write(val)
13 changes: 7 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

sys.path.append(os.path.dirname(__file__))

from css_utils import Log, create_steam_symlink, Result, get_theme_path, save_mappings as util_save_mappings, store_read as util_store_read, store_write as util_store_write, store_or_file_config, is_steam_beta_active
from css_utils import Log, create_steam_symlink, Result, get_theme_path, save_mappings as util_save_mappings, store_read as util_store_read, store_write as util_store_write, is_steam_beta_active
from css_inject import ALL_INJECTS, initialize_class_mappings
from css_theme import CSS_LOADER_VER
from css_remoteinstall import install
from css_settings import setting_redirect_logs, setting_watch_files, set_setting_watch_files, setting_run_server

from css_server import start_server
from css_browserhook import initialize
Expand All @@ -21,7 +22,7 @@
GOOGLE_PING_COUNT = 0

try:
if not store_or_file_config("no_redirect_logs"):
if setting_redirect_logs():
import decky_plugin
except:
pass
Expand Down Expand Up @@ -75,7 +76,7 @@ async def toggle_watch_state(self, enable : bool = True, only_this_session : boo
self.observer.start()

if not only_this_session:
util_store_write("watch", "1")
set_setting_watch_files(True)

return Result(True).to_dict()
elif self.observer != None and not enable:
Expand All @@ -84,7 +85,7 @@ async def toggle_watch_state(self, enable : bool = True, only_this_session : boo
self.observer = None

if not only_this_session:
util_store_write("watch", "0")
set_setting_watch_files(False)

return Result(True).to_dict()

Expand Down Expand Up @@ -177,14 +178,14 @@ async def _main(self):
self.loader = get_loader_instance()
await self.loader.load(False)

if (store_or_file_config("watch")):
if (setting_watch_files()):
await self.toggle_watch_state(self)
else:
Log("Not observing themes folder for file changes")

Log(f"Initialized css loader. Found {len(self.loader.themes)} themes. Total {len(ALL_INJECTS)} injects, {len([x for x in ALL_INJECTS if x.enabled])} injected")

if (ALWAYS_RUN_SERVER or store_or_file_config("server")):
if (ALWAYS_RUN_SERVER or setting_run_server()):
await self.enable_server(self)

start_fetch_translations()
Expand Down

0 comments on commit 19e0b51

Please sign in to comment.