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(
DBusSignal(
interface="org.usbguard.Devices1",
member="DevicePresenceChanged",
signature="uuusa{ss}",
member="DevicePolicyApplied",
signature="uusua{ss}",
)
)
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"]:
human = f"\"{attributes['name']}\" ({attributes['id']})"
else:
human = f"{attributes['id']}"
if event_ == 1:
# Insertion
if target_new == 0:
action = "accepted"
elif target_new == 1:
action = "blocked"
elif target_new == 2:
action = "rejected"
await notify(
i3,
app_icon="media-removable",
summary="New USB device",
body=f"USB device {human} inserted\non port {attributes['via-port']}",
)
elif event_ == 3:
# Removal
await notify(
i3,
app_icon="media-removable",
summary="Removed USB device",
body=f"USB device {human} removed\nfrom port {attributes['via-port']}",
summary=f"New {action} USB device",
body="\n".join(
[
f"USB device {human} {action}",
f"ID: <tt>{id}</tt>",
f"Port: <tt>{attributes['via-port']}</tt>",
]
),
)