i3-companion: keep notifications for blocked devices forever

This commit is contained in:
Vincent Bernat 2023-04-07 20:46:52 +02:00
parent ce697c174b
commit 7985f12d5d

View file

@ -891,6 +891,7 @@ async def dunst_status_check(i3, event):
signature="uusua{ss}", signature="uusua{ss}",
) )
) )
@static(history=collections.defaultdict(list))
async def usbguard_notifications( async def usbguard_notifications(
i3, event, path, id, target_new, device_rule, rule_id, attributes 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']})" human = f"\"{attributes['name']}\" ({attributes['id']})"
else: else:
human = f"{attributes['id']}" human = f"{attributes['id']}"
extra_args = {}
if target_new == 0: if target_new == 0:
action = "accepted" action = "accepted"
elif target_new == 1: elif target_new == 1:
action = "blocked" action = "blocked"
extra_args["expire_timeout"] = 0
elif target_new == 2: elif target_new == 2:
action = "rejected" action = "rejected"
await notify( else:
return
nid = await notify(
i3, i3,
app_icon="media-removable", app_icon="media-removable",
summary=f"New {action} USB device", summary=f"New {action} USB device",
replaces_id=usbguard_notifications.history.get(id, 0),
body="\n".join( body="\n".join(
[ [
f"USB device {human} {action}", f"USB device {human} {action}",
f"ID: <tt>{id}</tt>, Port: <tt>{attributes['via-port']}</tt>", f"ID: <tt>{id}</tt>, Port: <tt>{attributes['via-port']}</tt>",
] ]
), ),
**extra_args,
) )
if nid:
usbguard_notifications.history[id] = nid[0]
@on( @on(