Skip to content

Commit

Permalink
Make reinjection silent for live CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Sep 26, 2023
1 parent 41f6da7 commit dba368a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions css_browserhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
12 changes: 8 additions & 4 deletions css_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit dba368a

Please sign in to comment.