From 4100ae56616c000f80a95a06946cd72c428df815 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 19 Feb 2023 13:16:27 +0100 Subject: [PATCH] Add an option to disable tray notifications --- gui.py | 16 ++++++++++++++++ settings.py | 3 +++ translate.py | 2 ++ 3 files changed, 21 insertions(+) diff --git a/gui.py b/gui.py index 88a512f..4a7765f 100644 --- a/gui.py +++ b/gui.py @@ -1042,6 +1042,9 @@ class TrayIcon: def notify( self, message: str, title: str | None = None, duration: float = 10 ) -> asyncio.Task[None] | None: + # do nothing if the user disabled notifications + if not self._manager._twitch.settings.tray_notifications: + return None if self.icon is not None: icon = self.icon @@ -1386,6 +1389,7 @@ class _SettingsVars(TypedDict): proxy: StringVar autostart: IntVar priority_only: IntVar + tray_notifications: IntVar class SettingsPanel: @@ -1400,6 +1404,7 @@ class SettingsPanel: "tray": IntVar(master, self._settings.autostart_tray), "autostart": IntVar(master, self._settings.autostart), "priority_only": IntVar(master, self._settings.priority_only), + "tray_notifications": IntVar(master, self._settings.tray_notifications), } master.rowconfigure(0, weight=1) master.columnconfigure(0, weight=1) @@ -1442,6 +1447,14 @@ class SettingsPanel: ttk.Checkbutton( checkboxes_frame, variable=self._vars["tray"], command=self.update_autostart ).grid(column=1, row=irow, sticky="w") + ttk.Label( + checkboxes_frame, text=_("gui", "settings", "general", "tray_notifications") + ).grid(column=0, row=(irow := irow + 1), sticky="e") + ttk.Checkbutton( + checkboxes_frame, + variable=self._vars["tray_notifications"], + command=self.update_notifications, + ).grid(column=1, row=irow, sticky="w") ttk.Label( checkboxes_frame, text=_("gui", "settings", "general", "priority_only") ).grid(column=0, row=(irow := irow + 1), sticky="e") @@ -1548,6 +1561,9 @@ class SettingsPanel: self._priority_list.selection_clear(0, "end") self._exclude_list.selection_clear(0, "end") + def update_notifications(self) -> None: + self._settings.tray_notifications = bool(self._vars["tray_notifications"]) + def update_autostart(self) -> None: enabled = bool(self._vars["autostart"].get()) tray = bool(self._vars["tray"].get()) diff --git a/settings.py b/settings.py index a49ad21..130ad98 100644 --- a/settings.py +++ b/settings.py @@ -19,6 +19,7 @@ class SettingsFile(TypedDict): priority: list[str] priority_only: bool autostart_tray: bool + tray_notifications: bool default_settings: SettingsFile = { @@ -29,6 +30,7 @@ default_settings: SettingsFile = { "priority_only": True, "autostart_tray": False, "language": DEFAULT_LANG, + "tray_notifications": True, } @@ -49,6 +51,7 @@ class Settings: priority: list[str] priority_only: bool autostart_tray: bool + tray_notifications: bool PASSTHROUGH = ("_settings", "_args", "_altered") diff --git a/translate.py b/translate.py index 80c2749..9a9d560 100644 --- a/translate.py +++ b/translate.py @@ -164,6 +164,7 @@ class GUISettingsGeneral(TypedDict): name: str autostart: str tray: str + tray_notifications: str priority_only: str proxy: str @@ -358,6 +359,7 @@ default_translation: Translation = { "name": "General", "autostart": "Autostart: ", "tray": "Autostart into tray: ", + "tray_notifications": "Tray notifications: ", "priority_only": "Priority Only: ", "proxy": "Proxy (requires restart):", },