From ba40c5108d385d9d2ebb17696b66e4baed6b2cbf Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 14 Jul 2025 11:05:39 -0400 Subject: [PATCH] Add notification queue to PasswordManager --- src/password_manager/manager.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/password_manager/manager.py b/src/password_manager/manager.py index c003d5d..366245f 100644 --- a/src/password_manager/manager.py +++ b/src/password_manager/manager.py @@ -20,6 +20,8 @@ import shutil import time import builtins import threading +import queue +from dataclasses import dataclass from termcolor import colored from utils.color_scheme import color_text from utils.input_utils import timed_input @@ -96,6 +98,14 @@ from password_manager.config_manager import ConfigManager logger = logging.getLogger(__name__) +@dataclass +class Notification: + """Simple message container for UI notifications.""" + + message: str + level: str = "INFO" + + class PasswordManager: """ PasswordManager Class @@ -126,6 +136,7 @@ class PasswordManager: self.bip85: Optional[BIP85] = None self.nostr_client: Optional[NostrClient] = None self.config_manager: Optional[ConfigManager] = None + self.notifications: queue.Queue[Notification] = queue.Queue() # Track changes to trigger periodic Nostr sync self.is_dirty: bool = False @@ -216,6 +227,10 @@ class PasswordManager: """Record the current time as the last user activity.""" self.last_activity = time.time() + def notify(self, message: str, level: str = "INFO") -> None: + """Enqueue a notification for later retrieval.""" + self.notifications.put(Notification(message, level)) + def lock_vault(self) -> None: """Clear sensitive information from memory.""" if self.entry_manager is not None: @@ -1076,12 +1091,10 @@ class PasswordManager: ): healthy = self.nostr_client.check_relay_health(MIN_HEALTHY_RELAYS) if healthy < MIN_HEALTHY_RELAYS: - print( - colored( - f"Only {healthy} relay(s) responded with your latest event." - " Consider adding more relays via Settings.", - "yellow", - ) + self.notify( + f"Only {healthy} relay(s) responded with your latest event." + " Consider adding more relays via Settings.", + level="WARNING", ) except Exception as exc: logger.warning(f"Relay health check failed: {exc}")