Do not log during minimize count down loop.

This commit is contained in:
2022-06-27 19:54:33 -04:00
parent 02ad8b38a8
commit 0de11e8e0e

View File

@@ -58,7 +58,7 @@ class AntiDriftDaemon(dbus.service.Object):
mainloop.run()
def window_is_blocked(config: Config) -> bool:
def window_is_blocked(config: Config, silent: bool = False) -> bool:
# These should be selectable in the future (not all at the same time)
blackblocks = config.blackblocks
whiteblocks = config.whiteblocks
@@ -69,19 +69,24 @@ def window_is_blocked(config: Config) -> bool:
for b in blackblocks:
for k in b.keywords:
if k in window.keywords:
xwindow.notify(f"{window.name[:30]} blocked by {b.name}.")
logging.warning(f"{window.name[:30]} blocked by {b.name}.")
if not silent:
xwindow.notify(f"{window.name[:30]} blocked by {b.name}.")
logging.warning(f"[red]{window.name[:50]}[/red] "
f"blocked by [red]{b.name}[/red].")
return True
if config.blackblocks_only:
logging.debug("All non-blacklisted windows are allowed.")
if not silent:
logging.debug("All non-blacklisted windows are allowed.")
return False
for w in whiteblocks:
for k in w.keywords:
if k in window.keywords:
logging.debug(f"[green]{window.name[:30]}[/green] "
f"allowed by [blue]{w.name}[/blue].")
if not silent:
logging.debug(f"[green]{window.name[:30]}[/green] "
f"allowed by [blue]{w.name}[/blue].")
return False
xwindow.notify(f"{window.name[:30]} not on any whitelist.")
if not silent:
xwindow.notify(f"{window.name[:30]} not on any whitelist.")
return True
@@ -90,7 +95,12 @@ def enforce(config: Config):
return
delay = config.minimize_delay
xwindow.notify(f"AntiDrift will minimize in {delay} seconds.")
time.sleep(config.minimize_delay)
timer, timer_step = 0.0, 0.5
while timer < config.minimize_delay:
time.sleep(timer_step)
timer += timer_step
if not window_is_blocked(config, True):
break
window = xwindow.XWindow()
if window_is_blocked(config):
window = xwindow.XWindow()