Skip to content

Commit

Permalink
Add backend fetch_class_mappings function
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Apr 7, 2024
1 parent d2bef29 commit 45137b7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ async def get_last_load_errors(self):
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 fetch_class_mappings(self):
await self._fetch_class_mappings(self)
return Result(True).to_dict()

async def _fetch_class_mappings(self, run_in_bg : bool = False):
global SUCCESSFUL_FETCH_THIS_RUN

SUCCESSFUL_FETCH_THIS_RUN = False
css_translations_path = os.path.join(get_theme_path(), "css_translations.json")
if run_in_bg:
asyncio.get_event_loop().create_task(every(60, fetch_class_mappings, css_translations_path, self.loader))
else:
await fetch_class_mappings(css_translations_path, self.loader)

async def _main(self):
global Initialized
if Initialized:
Expand Down Expand Up @@ -208,8 +222,7 @@ async def _main(self):
if (ALWAYS_RUN_SERVER or store_or_file_config("server")):
await self.enable_server(self)

css_translations_path = os.path.join(get_theme_path(), "css_translations.json")
asyncio.get_event_loop().create_task(every(60, fetch_class_mappings, css_translations_path, self.loader))
await self._fetch_class_mappings(self, True)
await initialize()

if __name__ == '__main__':
Expand Down

0 comments on commit 45137b7

Please sign in to comment.