diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-06-21 10:18:50 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-06-21 13:14:19 +0200 |
commit | ef11117d7320cd40d1e87c35ce475cc6f5981be3 (patch) | |
tree | 4f0e8d12e2437c047c5df23746592276f58c315d | |
parent | 7a42513625dfdd83de00159e27dcdd0fb8a4a990 (diff) | |
download | qutebrowser-ef11117d7320cd40d1e87c35ce475cc6f5981be3.tar.gz qutebrowser-ef11117d7320cd40d1e87c35ce475cc6f5981be3.zip |
notification: Refactor selecting candidates
(cherry picked from commit 56a5a9340b50f77e7bd98e318d88fc059eee5fcc)
-rw-r--r-- | qutebrowser/browser/webengine/notification.py | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/qutebrowser/browser/webengine/notification.py b/qutebrowser/browser/webengine/notification.py index 39fce032a..5d3ab5a66 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) @@ -227,31 +227,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: @@ -270,6 +246,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 |