Catch error when sending dbus notification fails

This commit is contained in:
miruka 2021-01-13 11:23:38 -04:00
parent 98b6a7b74e
commit 01adc71646

View File

@ -7,6 +7,7 @@ import os
import re import re
import sys import sys
import time import time
import traceback
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
from typing import Any, DefaultDict, Dict, List, Optional, Tuple, Union from typing import Any, DefaultDict, Dict, List, Optional, Tuple, Union
@ -136,7 +137,8 @@ class Backend:
self.mxc_events: DefaultDict[str, List[Event]] = DefaultDict(list) self.mxc_events: DefaultDict[str, List[Event]] = DefaultDict(list)
self.notification_avatar_cache: Dict[str, Path] = {} # {mxc: path} self.notification_avatar_cache: Dict[str, Path] = {} # {mxc: path}
self.notifications_working: bool = True
def __repr__(self) -> str: def __repr__(self) -> str:
@ -561,11 +563,19 @@ class Backend:
self, title: str, body: str = "", image: Union[Path, str] = "", self, title: str, body: str = "", image: Union[Path, str] = "",
) -> None: ) -> None:
# XXX: images on windows must be .ICO # XXX: images on windows must be .ICO
plyer.notification.notify(
title = title, try:
message = body, plyer.notification.notify(
app_name = __app_name__, title = title,
app_icon = str(image), message = body,
timeout = 10, app_name = __app_name__,
toast = False, app_icon = str(image),
) timeout = 10,
toast = False,
)
self.notifications_working = True
except Exception: # noqa
if self.notifications_working:
trace = traceback.format_exc().rstrip()
log.error("Sending desktop notification failed\n%s", trace)
self.notifications_working = False