diff --git a/bin/i3-companion b/bin/i3-companion index 5329605..2a7e48e 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -891,6 +891,7 @@ async def dunst_status_check(i3, event): signature="uusua{ss}", ) ) +@static(history=collections.defaultdict(list)) async def usbguard_notifications( i3, event, path, id, target_new, device_rule, rule_id, attributes ): @@ -899,23 +900,31 @@ async def usbguard_notifications( human = f"\"{attributes['name']}\" ({attributes['id']})" else: human = f"{attributes['id']}" + extra_args = {} if target_new == 0: action = "accepted" elif target_new == 1: action = "blocked" + extra_args["expire_timeout"] = 0 elif target_new == 2: action = "rejected" - await notify( + else: + return + nid = await notify( i3, app_icon="media-removable", summary=f"New {action} USB device", + replaces_id=usbguard_notifications.history.get(id, 0), body="\n".join( [ f"USB device {human} {action}", f"ID: {id}, Port: {attributes['via-port']}", ] ), + **extra_args, ) + if nid: + usbguard_notifications.history[id] = nid[0] @on(