- commit
- 8b7117ed5c007e2a215539791a6eb9fe96f08ff9
- parent
- 1e458587b4cac2242530ac5cd6a280684feee510
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-02-12 18:05
refactor on_add_notification
Diffstat
| M | notification_hub.py | 25 | ++++++++----------------- |
1 files changed, 8 insertions, 17 deletions
diff --git a/notification_hub.py b/notification_hub.py
@@ -59,18 +59,6 @@ def clear_thread(item, key): 59 59 indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE) 60 60 61 6162 -1 def format_label(params):63 -1 desktop_entry = params['hints'].get('desktop-entry')64 -1 _app_name = params['app_name'] or desktop_entry65 -1 if _app_name:66 -1 if params['summary'] != _app_name:67 -1 return '%s: %s' % (_app_name, params['summary'])68 -1 else:69 -1 return '%s: %s' % (_app_name, params['body'][:40])70 -1 else:71 -1 return params['summary']72 -173 -174 62 def matches_rule(params, rule): 75 63 for key, pattern in rule.items(): 76 64 if key == 'hints': @@ -86,9 +74,12 @@ def on_add_notification(params, id): 86 74 if any(matches_rule(params, rule) for rule in IGNORE): 87 75 return 88 7689 -1 label = format_label(params)90 -1 key = params['hints'].get('desktop-entry', params['app_name'])91 -1 thread = threads.get(key)-1 77 app_name = params['hints'].get('desktop-entry', params['app_name']) -1 78 thread = threads.get(app_name) -1 79 if params['summary'] == app_name: -1 80 label = f'{app_name}: {params["body"][:40]}' -1 81 else: -1 82 label = f'{app_name}: {params["summary"]}' 92 83 93 84 if thread: 94 85 if params['replaces_id'] in thread['ids']: @@ -97,12 +88,12 @@ def on_add_notification(params, id): 97 88 thread['menuitem'].set_label(label) 98 89 else: 99 90 item = Gtk.MenuItem(label=label)100 -1 item.connect('activate', clear_thread, key)-1 91 item.connect('activate', clear_thread, app_name) 101 92 menu.append(item) 102 93 menu.show_all() 103 94 indicator.set_status(AppIndicator3.IndicatorStatus.ATTENTION) 104 95105 -1 threads[key] = {-1 96 threads[app_name] = { 106 97 'menuitem': item, 107 98 'ids': {id}, 108 99 }