Fix default theme retrieval mess

This commit is contained in:
miruka 2020-03-14 17:33:13 -04:00
parent cc3bb3c4fd
commit f507523af6

View File

@ -10,6 +10,8 @@ from typing import TYPE_CHECKING, Any, ClassVar, Dict, Optional
import aiofiles import aiofiles
import pyotherside
from .theme_parser import convert_to_qml from .theme_parser import convert_to_qml
from .utils import atomic_write, dict_update_recursive from .utils import atomic_write, dict_update_recursive
@ -279,18 +281,21 @@ class Theme(DataFile):
@property @property
def path(self) -> Path: def path(self) -> Path:
data_dir = Path(self.backend.appdirs.user_data_dir) data_dir = Path(self.backend.appdirs.user_data_dir)
user_path = data_dir / "themes" / self.filename return data_dir / "themes" / self.filename
if not user_path.exists():
return Path("src") / "themes" / self.filename
return user_path
async def default_data(self) -> str: async def default_data(self) -> str:
async with aiofiles.open("../themes/Midnight.qpl") as file: path = f"src/themes/{self.filename}"
return await file.read()
try:
byte_content = pyotherside.qrc_get_file_contents(path)
except ValueError:
# App was compiled without QRC
async with aiofiles.open(path) as file:
return await file.read()
else:
return byte_content.decode()
async def read(self) -> str: async def read(self) -> str: