Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devices widget: label recently-connected devices as "NEW" #207

Merged
merged 8 commits into from
Jul 18, 2024
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