i3-companion: display applied policy for usbguard notifications

This commit is contained in:
Vincent Bernat 2023-03-12 11:59:26 +01:00
parent ab391e9ebf
commit ba33d4499a

View file

@ -885,33 +885,35 @@ async def dunst_status_check(i3, event):
@on( @on(
DBusSignal( DBusSignal(
interface="org.usbguard.Devices1", interface="org.usbguard.Devices1",
member="DevicePresenceChanged", member="DevicePolicyApplied",
signature="uuusa{ss}", signature="uusua{ss}",
) )
) )
async def usbguard_notifications( async def usbguard_notifications(
i3, event, path, id, event_, target, device_rule, attributes i3, event, path, id, target_new, device_rule, rule_id, attributes
): ):
"""Display notifications related to Network Manager state.""" """Display notifications related when a USBGuard policy is applied."""
if attributes["name"]: if attributes["name"]:
human = f"\"{attributes['name']}\" ({attributes['id']})" human = f"\"{attributes['name']}\" ({attributes['id']})"
else: else:
human = f"{attributes['id']}" human = f"{attributes['id']}"
if event_ == 1: if target_new == 0:
# Insertion action = "accepted"
elif target_new == 1:
action = "blocked"
elif target_new == 2:
action = "rejected"
await notify( await notify(
i3, i3,
app_icon="media-removable", app_icon="media-removable",
summary="New USB device", summary=f"New {action} USB device",
body=f"USB device {human} inserted\non port {attributes['via-port']}", body="\n".join(
) [
elif event_ == 3: f"USB device {human} {action}",
# Removal f"ID: <tt>{id}</tt>",
await notify( f"Port: <tt>{attributes['via-port']}</tt>",
i3, ]
app_icon="media-removable", ),
summary="Removed USB device",
body=f"USB device {human} removed\nfrom port {attributes['via-port']}",
) )