From 2f8197eb97920fdc3477ac681a34194a950fadbe Mon Sep 17 00:00:00 2001 From: VAIO73 <50487331+Vaso73@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:23:37 +0200 Subject: [PATCH] fix: add icons to notification digests --- AppImage/scripts/notification_manager.py | 23 ++++++++++++++----- .../tests/test_notification_runtime_i18n.py | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/AppImage/scripts/notification_manager.py b/AppImage/scripts/notification_manager.py index 5fc67fac..b304a06a 100644 --- a/AppImage/scripts/notification_manager.py +++ b/AppImage/scripts/notification_manager.py @@ -41,7 +41,8 @@ if BASE_DIR not in sys.path: from notification_channels import create_channel, CHANNEL_TYPES from notification_templates import ( render_template, format_with_ai, format_with_ai_full, enrich_with_emojis, TEMPLATES, - EVENT_GROUPS, get_event_types_by_group, get_default_enabled_events, runtime_message, + EVENT_GROUPS, CATEGORY_EMOJI, EVENT_EMOJI, get_event_types_by_group, + get_default_enabled_events, runtime_message, ) from notification_events import ( JournalWatcher, TaskWatcher, PollingCollector, NotificationEvent, @@ -1699,6 +1700,9 @@ class NotificationManager: 'digest.title', language, hostname=host, timestamp=now.strftime('%Y-%m-%d %H:%M'), ) + rich_format = self._config.get(f'{ch_name}.rich_format', 'false') == 'true' + if rich_format: + summary_title = f'📋 {summary_title}' try: conn = sqlite3.connect(str(DB_PATH), timeout=10) @@ -1738,7 +1742,7 @@ class NotificationManager: ) return - summary_body = self._compose_digest_body(rows) + summary_body = self._compose_digest_body(rows, use_icons=rich_format) result: dict = {'success': False, 'error': ''} try: @@ -1782,7 +1786,7 @@ class NotificationManager: print(f"[NotificationManager] digest cleanup failed for " f"{ch_name}: {e}") - def _compose_digest_body(self, rows: list) -> str: + def _compose_digest_body(self, rows: list, use_icons: bool = False) -> str: """Render a grouped summary body. rows is a list of (id, event_type, event_group, ts, title, body) tuples ordered by timestamp ASC. @@ -1797,11 +1801,17 @@ class NotificationManager: lines = [runtime_message('digest.lead', language, count=len(rows))] for group, items in groups.items(): group_label = runtime_message(f'digest.groups.{group}', language) or group.title() - lines.append(f"{group_label}: {len(items)}") + group_icon = CATEGORY_EMOJI.get(group, '') if use_icons else '' + group_prefix = f'{group_icon} ' if group_icon else '' + lines.append(f"{group_prefix}{group_label}: {len(items)}") for ts, ev_type, title in items[:8]: hhmm = datetime.fromtimestamp(ts).strftime('%H:%M') short_title = title.split(': ', 1)[-1] if ': ' in title else title - lines.append(f" • {hhmm} {short_title}") + event_icon = ( + EVENT_EMOJI.get(ev_type) or CATEGORY_EMOJI.get(group, '') + ) if use_icons else '' + event_prefix = f'{event_icon} ' if event_icon else '' + lines.append(f" • {event_prefix}{hhmm} {short_title}") if len(items) > 8: lines.append(runtime_message('digest.more', language, count=len(items) - 8)) lines.append('') @@ -1939,7 +1949,8 @@ class NotificationManager: summary_title = runtime_message( 'digest.quietTitle', language, hostname=host, count=len(rows), ) - summary_body = self._compose_digest_body(rows) + use_icons = self._config.get(f'{ch_name}.rich_format', 'false') == 'true' + summary_body = self._compose_digest_body(rows, use_icons=use_icons) result: dict = {'success': False, 'error': ''} try: diff --git a/AppImage/scripts/tests/test_notification_runtime_i18n.py b/AppImage/scripts/tests/test_notification_runtime_i18n.py index 114a829b..89bd81fc 100644 --- a/AppImage/scripts/tests/test_notification_runtime_i18n.py +++ b/AppImage/scripts/tests/test_notification_runtime_i18n.py @@ -286,6 +286,9 @@ class RuntimeCatalogTests(unittest.TestCase): digest = manager._compose_digest_body(rows) self.assertIn("udalostí INFO zoskupených podľa kategórie", digest) self.assertIn("Zdroje", digest) + rich_digest = manager._compose_digest_body(rows, use_icons=True) + self.assertIn("📊 Zdroje: 1", rich_digest) + self.assertIn("• 🔥 01:00 Vysoké využitie CPU", rich_digest) title, body, caption = manager._build_test_message(False, False, "groq / sk") self.assertEqual(title, "Test ProxMenux") self.assertIn("Vitajte", body)