From 4333b8f37d483d2a15f014dd41aa6b0e234cfd10 Mon Sep 17 00:00:00 2001 From: ooops Date: Sat, 6 Jul 2024 01:06:14 -0400 Subject: [PATCH 1/7] Devices widget: label recently-connected devices as "NEW" fixes: https://github.com/QubesOS/qubes-issues/issues/8543 --- qui/devices/actionable_widgets.py | 13 ++++++++++++- qui/devices/backend.py | 2 ++ qui/devices/device_widget.py | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 34c69f0e..3185d438 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -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): @@ -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 @@ -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 += ' NEW!' + self.device_label.set_markup(label_markup) + if self.device.attachments: self.device_label.get_style_context().add_class("dev_attached") diff --git a/qui/devices/backend.py b/qui/devices/backend.py index 1dfaacd9..565029a4 100644 --- a/qui/devices/backend.py +++ b/qui/devices/backend.py @@ -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: diff --git a/qui/devices/device_widget.py b/qui/devices/device_widget.py index 386b282d..44d0fd9a 100644 --- a/qui/devices/device_widget.py +++ b/qui/devices/device_widget.py @@ -20,6 +20,7 @@ from typing import Set, List, Dict import asyncio import sys +import time import importlib.resources @@ -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"), From 8a7062bb168b99b074723fb22fe9ffb76f25da1b Mon Sep 17 00:00:00 2001 From: ooops Date: Sat, 6 Jul 2024 01:06:14 -0400 Subject: [PATCH 2/7] Devices widget: label recently-connected devices as "NEW" fixes: https://github.com/QubesOS/qubes-issues/issues/8543 --- qui/devices/actionable_widgets.py | 13 ++++++++++++- qui/devices/backend.py | 2 ++ qui/devices/device_widget.py | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 34c69f0e..3185d438 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -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): @@ -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 @@ -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 += ' NEW!' + self.device_label.set_markup(label_markup) + if self.device.attachments: self.device_label.get_style_context().add_class("dev_attached") diff --git a/qui/devices/backend.py b/qui/devices/backend.py index 1dfaacd9..565029a4 100644 --- a/qui/devices/backend.py +++ b/qui/devices/backend.py @@ -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: diff --git a/qui/devices/device_widget.py b/qui/devices/device_widget.py index 386b282d..44d0fd9a 100644 --- a/qui/devices/device_widget.py +++ b/qui/devices/device_widget.py @@ -20,6 +20,7 @@ from typing import Set, List, Dict import asyncio import sys +import time import importlib.resources @@ -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"), From 4dd8327fd183004c6cc264ec33a295d6bf31d97e Mon Sep 17 00:00:00 2001 From: ooops Date: Mon, 8 Jul 2024 09:45:09 -0400 Subject: [PATCH 3/7] Fixing Pylint error and initial value for connection_timestamp --- qui/devices/actionable_widgets.py | 3 ++- qui/devices/backend.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 3185d438..6a875c9d 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -409,7 +409,8 @@ def __init__(self, device: backend.Device, variant: str = 'dark'): self.device_label = Gtk.Label(xalign=0) label_markup = device.name - if device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120: + if (device.connection_timestamp and + int(time.monotonic() - device.connection_timestamp) < 120): label_markup += ' NEW!' self.device_label.set_markup(label_markup) diff --git a/qui/devices/backend.py b/qui/devices/backend.py index 565029a4..449f7d21 100644 --- a/qui/devices/backend.py +++ b/qui/devices/backend.py @@ -101,7 +101,7 @@ def __init__(self, dev: qubesadmin.devices.DeviceInfo, self.__hash = hash(dev) self._port: str = '' # Monotonic connection timestamp only for new devices - self.connection_timestamp: None + self.connection_timestamp: float = None self._dev_name: str = getattr(dev, 'description', 'unknown') if dev.devclass == 'block' and 'size' in dev.data: From aede58454a76ee80843f0aa2f854893d077d326c Mon Sep 17 00:00:00 2001 From: ooops Date: Mon, 8 Jul 2024 12:21:28 -0400 Subject: [PATCH 4/7] Update actionable_widgets.py Fixes Pylint trailing whitespace --- qui/devices/actionable_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 6a875c9d..f5a7dd61 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -409,7 +409,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'): self.device_label = Gtk.Label(xalign=0) label_markup = device.name - if (device.connection_timestamp and + if (device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120): label_markup += ' NEW!' self.device_label.set_markup(label_markup) From d1b521c322ca6dcc993486dc38f25a3377fabfb1 Mon Sep 17 00:00:00 2001 From: kennethrrosen Date: Tue, 9 Jul 2024 11:07:16 -0400 Subject: [PATCH 5/7] Change color and punctuation Removes exclamation mark and changes text color from red to blue --- qui/devices/actionable_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index f5a7dd61..1eb46ff9 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -411,7 +411,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'): label_markup = device.name if (device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120): - label_markup += ' NEW!' + label_markup += ' NEW' self.device_label.set_markup(label_markup) if self.device.attachments: From 6668f4d4a682435b32c9c2007a33db01fd12e693 Mon Sep 17 00:00:00 2001 From: kennethrrosen Date: Tue, 9 Jul 2024 11:16:34 -0400 Subject: [PATCH 6/7] Update color from blue to #99bfff Following Qubes Visual Style Guide https://www.qubes-os.org/doc/visual-style-guide/ --- qui/devices/actionable_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 1eb46ff9..9c04fa81 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -411,7 +411,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'): label_markup = device.name if (device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120): - label_markup += ' NEW' + label_markup += ' NEW' self.device_label.set_markup(label_markup) if self.device.attachments: From 35de1246454fc5900cbc9ff5458a95e635cf7abc Mon Sep 17 00:00:00 2001 From: kennethrrosen Date: Tue, 9 Jul 2024 11:19:11 -0400 Subject: [PATCH 7/7] Change color from #99bfff to #63a0ff --- qui/devices/actionable_widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qui/devices/actionable_widgets.py b/qui/devices/actionable_widgets.py index 9c04fa81..266bd8a1 100644 --- a/qui/devices/actionable_widgets.py +++ b/qui/devices/actionable_widgets.py @@ -411,7 +411,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'): label_markup = device.name if (device.connection_timestamp and int(time.monotonic() - device.connection_timestamp) < 120): - label_markup += ' NEW' + label_markup += ' NEW' self.device_label.set_markup(label_markup) if self.device.attachments: