@@ -66,7 +66,7 @@ def flatten_categories(categories: dict, parents=[]):
6666merge_categories (categories , user_notif_categories )
6767enabled_categories = set (flatten_categories (categories ))
6868
69- if enabled_categories :
69+ if notifier is not None and enabled_categories :
7070 logger .debug (
7171 "Notifications enabled for categories: "
7272 f"{ ', ' .join (sorted (enabled_categories ))} "
@@ -92,10 +92,13 @@ def notify_loop():
9292notif_action_interface = config ['general' ]['notif_actions' ]['primary_interface' ].get (
9393 confuse .Choice (['button' , 'click' ], default = 'button' )
9494)
95- logger .debug (
96- "Notif actions enabled for categories: "
97- f"{ ', ' .join (sorted (enabled_notif_action_categories ))} "
98- )
95+ if notifier is not None :
96+ logger .debug (
97+ "Notif actions enabled for categories: "
98+ f"{ ', ' .join (sorted (enabled_notif_action_categories ))} "
99+ )
100+ else :
101+ logger .warning ("Notifier is not initialized!" )
99102
100103
101104def notify (
@@ -108,6 +111,8 @@ def notify(
108111):
109112 if stdout :
110113 print (body )
114+ if notifier is None :
115+ return
111116 if category not in enabled_categories :
112117 return
113118 if actions and category in enabled_notif_action_categories :
@@ -119,9 +124,13 @@ def notify(
119124 else :
120125 on_clicked = None
121126 actions = ()
122- notif_task = notifier .send (
123- title , body , icon = "" , on_clicked = on_clicked , buttons = actions
124- )
127+ try :
128+ notif_task = notifier .send (
129+ title , body , icon = "" , on_clicked = on_clicked , buttons = actions
130+ )
131+ except Exception :
132+ logger .error ("Error when creating notification" , exc_info = True )
133+ return
125134 fut = asyncio .run_coroutine_threadsafe (notif_task , notif_loop )
126135 try :
127136 # wait for the notification to be _sent_
0 commit comments