JSON configs read(): Merge default and user data

This commit is contained in:
miruka 2019-07-21 09:24:11 -04:00
parent daa2c36af1
commit 3287888a5c

View File

@ -38,9 +38,11 @@ class JSONConfigFile(ConfigFile):
async def read(self) -> JsonData: async def read(self) -> JsonData:
try: try:
return json.loads(self.path.read_text()) data = json.loads(self.path.read_text())
except (json.JSONDecodeError, FileNotFoundError): except (json.JSONDecodeError, FileNotFoundError):
return await self.default_data() data = {}
return {**await self.default_data(), **data}
async def write(self, data: JsonData) -> None: async def write(self, data: JsonData) -> None:
@ -99,6 +101,8 @@ class UIState(JSONConfigFile):
async def default_data(self) -> JsonData: async def default_data(self) -> JsonData:
return { return {
"collapseAccounts": {},
"collapseCategories": {},
"page": "Pages/Default.qml", "page": "Pages/Default.qml",
"pageProperties": {}, "pageProperties": {},
"sidePaneManualWidth": None, "sidePaneManualWidth": None,