summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-06-21 10:18:50 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-06-21 12:26:40 +0200
commit110936a5e8744bfbb8ccb06d14457b920c24fc3e (patch)
tree788b779b463ccf0b223c720ba18945c76b9c56d3
parentdffb9f77beacfae1170a68ce4451449b5416c862 (diff)
downloadqutebrowser-110936a5e8744bfbb8ccb06d14457b920c24fc3e.tar.gz
qutebrowser-110936a5e8744bfbb8ccb06d14457b920c24fc3e.zip
notifications: Refactor selecting candidates
-rw-r--r--qutebrowser/browser/webengine/notification.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/qutebrowser/browser/webengine/notification.py b/qutebrowser/browser/webengine/notification.py
index 692a85376..444465bf2 100644
--- a/qutebrowser/browser/webengine/notification.py
+++ b/qutebrowser/browser/webengine/notification.py
@@ -48,7 +48,7 @@ import dataclasses
import itertools
import functools
import subprocess
-from typing import Any, List, Dict, Optional, Iterator, TYPE_CHECKING
+from typing import Any, List, Dict, Optional, Iterator, Type, TYPE_CHECKING
from PyQt5.QtCore import (Qt, QObject, QVariant, QMetaType, QByteArray, pyqtSlot,
pyqtSignal, QTimer, QProcess, QUrl)
@@ -229,31 +229,7 @@ class NotificationBridgePresenter(QObject):
message.error("Can't switch to qt notification presenter at runtime.")
setting = "auto"
- if setting in ["auto", "libnotify"]:
- candidates = [
- DBusNotificationAdapter,
- SystrayNotificationAdapter,
- MessagesNotificationAdapter,
- ]
- elif setting == "systray":
- candidates = [
- SystrayNotificationAdapter,
- DBusNotificationAdapter,
- MessagesNotificationAdapter,
- ]
- elif setting == "herbe":
- candidates = [
- HerbeNotificationAdapter,
- DBusNotificationAdapter,
- SystrayNotificationAdapter,
- MessagesNotificationAdapter,
- ]
- elif setting == "messages":
- candidates = [MessagesNotificationAdapter] # always succeeds
- else:
- raise utils.Unreachable(setting)
-
- for candidate in candidates:
+ for candidate in self._get_adapter_candidates(setting):
try:
self._adapter = candidate()
except Error as e:
@@ -272,6 +248,32 @@ class NotificationBridgePresenter(QObject):
self._adapter.error.connect(self._on_adapter_error)
self._adapter.clear_all.connect(self._on_adapter_clear_all)
+ def _get_adapter_candidates(
+ self,
+ setting: str,
+ ) -> List[Type[AbstractNotificationAdapter]]:
+ candidates: Dict[str, List[Type[AbstractNotificationAdapter]]] = {
+ "libnotify": [
+ DBusNotificationAdapter,
+ SystrayNotificationAdapter,
+ MessagesNotificationAdapter,
+ ],
+ "systray": [
+ SystrayNotificationAdapter,
+ DBusNotificationAdapter,
+ MessagesNotificationAdapter,
+ ],
+ "herbe": [
+ HerbeNotificationAdapter,
+ DBusNotificationAdapter,
+ SystrayNotificationAdapter,
+ MessagesNotificationAdapter,
+ ],
+ "messages": [MessagesNotificationAdapter], # always succeeds
+ }
+ candidates["auto"] = candidates["libnotify"]
+ return candidates[setting]
+
def install(self, profile: "QWebEngineProfile") -> None:
"""Set the profile to use this bridge as the presenter."""
# WORKAROUND for