From dba368aa1a42a6e5f3218156c65fb5af35edc9a8 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 26 Sep 2023 21:36:24 +0200 Subject: [PATCH] Make reinjection silent for live CSS --- css_browserhook.py | 4 ++-- css_loader.py | 12 ++++++++---- main.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/css_browserhook.py b/css_browserhook.py index 5c16d60..c945536 100644 --- a/css_browserhook.py +++ b/css_browserhook.py @@ -472,8 +472,8 @@ async def remove(tab_name : str, css_id : str) -> Result: return Result(True) -async def commit_all(): - await asyncio.gather(*[x.commit_css_transaction() for x in HOOK.connected_tabs]) +async def commit_all(remove_all_first : bool = False): + await asyncio.gather(*[x.commit_css_transaction(remove_all_first=remove_all_first) for x in HOOK.connected_tabs]) async def remove_all(): await asyncio.gather(*[x.remove_all_css() for x in HOOK.connected_tabs]) \ No newline at end of file diff --git a/css_loader.py b/css_loader.py index 4730fc7..6c0b8be 100644 --- a/css_loader.py +++ b/css_loader.py @@ -107,12 +107,16 @@ async def set_component_of_theme_patch(self, themeName : str, patchName : str, c await commit_all() return Result(True) - async def reset(self) -> dict: + async def reset(self, silent : bool = False) -> dict: await self.lock() try: - await remove_all() - await self.load() - await commit_all() + if silent: + await self.load() + await commit_all(remove_all_first=True) + else: + await remove_all() + await self.load() + await commit_all() except Exception as e: await self.unlock() Result(False, str(e)) diff --git a/main.py b/main.py index f978b5c..207848e 100644 --- a/main.py +++ b/main.py @@ -42,7 +42,7 @@ def on_modified(self, event): if ((self.last + self.delay) < time.time() and not self.loader.busy): self.last = time.time() Log("Reloading themes due to FS event") - self.loop.create_task(self.loader.reset()) + self.loop.create_task(self.loader.reset(silent=True)) class Plugin: