Skip to content

Commit

Permalink
Devices widget: label recently-connected devices as "NEW"
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethrrosen committed Jul 6, 2024
1 parent 7fb21f3 commit 4333b8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion qui/devices/actionable_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from gi.repository import Gtk, GdkPixbuf, GLib # isort:skip

from . import backend
import time


def load_icon(icon_name: str, backup_name: str, size: int = 24):
Expand Down Expand Up @@ -393,6 +394,11 @@ def __init__(self, device: backend.Device, variant: str = 'dark'):
self.device = device
self.variant = variant

# add NEW! label for new devices for 10 minutes on 1st view
self._new_device_label_timout = 10 * 60
# reduce NEW! label timeout to 2 minutes after 1st view
self._new_device_label_afterview = 2 * 60

self.get_style_context().add_class('main_device_item')

# the part that is common to all devices
Expand All @@ -401,7 +407,12 @@ def __init__(self, device: backend.Device, variant: str = 'dark'):
self.device_icon.set_valign(Gtk.Align.CENTER)

self.device_label = Gtk.Label(xalign=0)
self.device_label.set_markup(device.name)

label_markup = device.name
if device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120:
label_markup += ' <span foreground="red"><b>NEW!</b></span>'
self.device_label.set_markup(label_markup)

if self.device.attachments:
self.device_label.get_style_context().add_class("dev_attached")

Expand Down
2 changes: 2 additions & 0 deletions qui/devices/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def __init__(self, dev: qubesadmin.devices.DeviceInfo,
self._dev: qubesadmin.devices.DeviceInfo = dev
self.__hash = hash(dev)
self._port: str = ''
# Monotonic connection timestamp only for new devices
self.connection_timestamp: None

self._dev_name: str = getattr(dev, 'description', 'unknown')
if dev.devclass == 'block' and 'size' in dev.data:
Expand Down
2 changes: 2 additions & 0 deletions qui/devices/device_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Set, List, Dict
import asyncio
import sys
import time

import importlib.resources

Expand Down Expand Up @@ -130,6 +131,7 @@ def device_list_update(self, vm, _event, **_kwargs):

for dev_name, dev in changed_devices.items():
if dev_name not in self.devices:
dev.connection_timestamp = time.monotonic()
self.devices[dev_name] = dev
self.emit_notification(
_("Device available"),
Expand Down

0 comments on commit 4333b8f

Please sign in to comment.