Skip to content

Commit

Permalink
Merge pull request #112 from DeckThemes/dev
Browse files Browse the repository at this point in the history
Merge Dev into Profile-Uploading
  • Loading branch information
beebls authored Mar 3, 2024
2 parents 3b54ec7 + 0097f83 commit 6b6fa0f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
12 changes: 12 additions & 0 deletions css_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from css_theme import Theme, CSS_LOADER_VER
from css_themepatch import ThemePatch
from css_browserhook import remove_all, commit_all
from css_remoteinstall import upload

from asyncio import sleep
from os import listdir, path, mkdir
Expand Down Expand Up @@ -171,6 +172,17 @@ async def generate_preset_theme_from_theme_names(self, name : str, themeNames :
except Exception as e:
return Result(False, str(e))

async def upload_theme(self, name : str, base_url : str, bearer_token : str) -> Result:
theme = await self._get_theme(name)

if theme is None:
return Result(False, f"Could not find theme {name}")

try:
return await upload(theme, base_url, bearer_token)
except Exception as e:
return Result(False, str(e))

async def _enable_theme(self, theme : Theme, set_deps : bool = True, set_deps_value : bool = True, ignore_dependencies : list = []) -> Result:
if theme is None:
return Result(False)
Expand Down
32 changes: 29 additions & 3 deletions css_remoteinstall.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio, json, tempfile, os, aiohttp, zipfile
import asyncio, json, tempfile, os, aiohttp, zipfile, shutil
from css_utils import Result, Log, get_theme_path, store_or_file_config
from css_theme import CSS_LOADER_VER
from css_theme import CSS_LOADER_VER, Theme

async def run(command : str) -> str:
proc = await asyncio.create_subprocess_shell(command,
Expand Down Expand Up @@ -64,4 +64,30 @@ async def install(id : str, base_url : str, local_themes : list) -> Result:

await install(x["id"], base_url, local_themes)

return Result(True)
return Result(True)

async def upload(theme : Theme, base_url : str, bearer_token : str) -> Result:
if not base_url.endswith("/"):
base_url = base_url + "/"

url = f"{base_url}blobs"

with tempfile.TemporaryDirectory() as tmp:
themePath = os.path.join(tmp, "theme.zip")
print(themePath[:-4])
print(theme.themePath)
shutil.make_archive(themePath[:-4], 'zip', theme.themePath)

with open(themePath, "rb") as file:
async with aiohttp.ClientSession(headers={"User-Agent": f"SDH-CSSLoader/{CSS_LOADER_VER}", "Authorization": f"Bearer {bearer_token}"}, connector=aiohttp.TCPConnector(verify_ssl=False)) as session:
try:
mp = aiohttp.FormData()
mp.add_field("file", file)
async with session.post(url, data=mp) as resp:
if resp.status != 200:
raise Exception(f"Invalid status code {resp.status}")

data = await resp.json()
return Result(True, data)
except Exception as e:
return Result(False, str(e))
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ async def get_last_load_errors(self):
return {
"fails": self.loader.last_load_errors
}

async def upload_theme(self, name : str, base_url : str, bearer_token : str) -> dict:
return (await self.loader.upload_theme(name, base_url, bearer_token)).to_dict()

async def _main(self):
global Initialized
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.0.5",
"version": "2.0.6",
"description": "A css loader",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function ThemeSettingsModal({
<>
<Focusable className="CSSLoader_ThemeSettingsModal_Header">
<div className="CSSLoader_ThemeSettingsModal_TitleContainer">
<span className="CSSLoader_ThemeSettingsModal_Title">{themeData.name}</span>
<span className="CSSLoader_ThemeSettingsModal_Title">{themeData.display_name}</span>
<span className="CSSLoader_ThemeSettingsModal_Subtitle">
{themeData.version} | {themeData.author}
</span>
Expand Down
17 changes: 16 additions & 1 deletion src/deckyPatches/NavControllerFinder.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import { Module, findModuleChild } from "decky-frontend-lib";

export const NavController = findModuleChild((m: Module) => m?.CFocusNavNode);
export const NavController = findModuleChild((m: Module) => {
if (typeof m !== "object") return undefined;

// Pre Chromium-109
if (m?.CFocusNavNode) {
return m.CFocusNavNode;
}

for (let prop in m) {
if (m[prop]?.prototype?.FindNextFocusableChildInDirection) {
return m[prop];
}
}

return undefined;
});

0 comments on commit 6b6fa0f

Please sign in to comment.