From d302782073d3a94ec59e52870aee4b528f7b1e79 Mon Sep 17 00:00:00 2001 From: Layerex Date: Wed, 28 Sep 2022 11:07:52 +0300 Subject: [PATCH 1/3] Add support for disabling notifications with enviroment variable --- README.md | 4 ++++ gnome-pass-search-provider.py | 35 +++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0491902..095b2fa 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ user: username pin: 123456 ``` +## Disabling notifications + +Set `DISABLE_NOTIFICATIONS` environment variable. + To copy the pin start the search with `:pin` and for the username with `:user`. # Alternative password providers diff --git a/gnome-pass-search-provider.py b/gnome-pass-search-provider.py index ad4f44c..91db79e 100755 --- a/gnome-pass-search-provider.py +++ b/gnome-pass-search-provider.py @@ -67,6 +67,8 @@ class SearchPassService(dbus.service.Object): self.password_executable = getenv("PASSWORD_EXECUTABLE") or "pass" self.password_mode = getenv("PASSWORD_MODE") or "pass" self.clipboard_executable = getenv("CLIPBOARD_EXECUTABLE") or "wl-copy" + self.disable_notifications = getenv("DISABLE_NOTIFICATIONS") + self.disable_notifications = self.disable_notifications and self.disable_notifications != "0" @dbus.service.method(in_signature="sasu", **sbn) def ActivateResult(self, id, terms, timestamp): @@ -220,22 +222,23 @@ class SearchPassService(dbus.service.Object): self.notify("Failed to copy password or field!", body=str(e), error=True) def notify(self, message, body="", error=False): - try: - self.session_bus.get_object( - "org.freedesktop.Notifications", "/org/freedesktop/Notifications" - ).Notify( - "Pass", - 0, - "dialog-password", - message, - body, - "", - {"transient": False if error else True}, - 0 if error else 3000, - dbus_interface="org.freedesktop.Notifications", - ) - except dbus.DBusException as err: - print(f"Error {err} while trying to display {message}.") + if not self.disable_notifications: + try: + self.session_bus.get_object( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications" + ).Notify( + "Pass", + 0, + "dialog-password", + message, + body, + "", + {"transient": False if error else True}, + 0 if error else 3000, + dbus_interface="org.freedesktop.Notifications", + ) + except dbus.DBusException as err: + print(f"Error {err} while trying to display {message}.") if __name__ == "__main__": From 62b63dc3e1a91eae333492681b28b9870bf7f45f Mon Sep 17 00:00:00 2001 From: Layerex Date: Wed, 28 Sep 2022 11:16:45 +0300 Subject: [PATCH 2/3] Don't disable error notifications with environment variable --- gnome-pass-search-provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnome-pass-search-provider.py b/gnome-pass-search-provider.py index 91db79e..da41802 100755 --- a/gnome-pass-search-provider.py +++ b/gnome-pass-search-provider.py @@ -222,7 +222,7 @@ class SearchPassService(dbus.service.Object): self.notify("Failed to copy password or field!", body=str(e), error=True) def notify(self, message, body="", error=False): - if not self.disable_notifications: + if error or not self.disable_notifications: try: self.session_bus.get_object( "org.freedesktop.Notifications", "/org/freedesktop/Notifications" From e98543973a3b48be0f998de6cfad08ec9d186a05 Mon Sep 17 00:00:00 2001 From: Jonathan Lestrelin Date: Fri, 30 Sep 2022 11:41:00 +0200 Subject: [PATCH 3/3] Require DISABLE_NOTIFICATIONS to be set to True, update README. --- README.md | 6 +++--- gnome-pass-search-provider.py | 38 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 095b2fa..0b4177d 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,11 @@ user: username pin: 123456 ``` +To copy the pin start the search with `:pin` and for the username with `:user`. + ## Disabling notifications -Set `DISABLE_NOTIFICATIONS` environment variable. - -To copy the pin start the search with `:pin` and for the username with `:user`. +Set the `DISABLE_NOTIFICATIONS` environment variable to `True`. # Alternative password providers diff --git a/gnome-pass-search-provider.py b/gnome-pass-search-provider.py index da41802..2cdad9c 100755 --- a/gnome-pass-search-provider.py +++ b/gnome-pass-search-provider.py @@ -67,8 +67,7 @@ class SearchPassService(dbus.service.Object): self.password_executable = getenv("PASSWORD_EXECUTABLE") or "pass" self.password_mode = getenv("PASSWORD_MODE") or "pass" self.clipboard_executable = getenv("CLIPBOARD_EXECUTABLE") or "wl-copy" - self.disable_notifications = getenv("DISABLE_NOTIFICATIONS") - self.disable_notifications = self.disable_notifications and self.disable_notifications != "0" + self.disable_notifications = getenv("DISABLE_NOTIFICATIONS").lower() == "true" or False @dbus.service.method(in_signature="sasu", **sbn) def ActivateResult(self, id, terms, timestamp): @@ -222,23 +221,24 @@ class SearchPassService(dbus.service.Object): self.notify("Failed to copy password or field!", body=str(e), error=True) def notify(self, message, body="", error=False): - if error or not self.disable_notifications: - try: - self.session_bus.get_object( - "org.freedesktop.Notifications", "/org/freedesktop/Notifications" - ).Notify( - "Pass", - 0, - "dialog-password", - message, - body, - "", - {"transient": False if error else True}, - 0 if error else 3000, - dbus_interface="org.freedesktop.Notifications", - ) - except dbus.DBusException as err: - print(f"Error {err} while trying to display {message}.") + if not error and self.disable_notifications: + return + try: + self.session_bus.get_object( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications" + ).Notify( + "Pass", + 0, + "dialog-password", + message, + body, + "", + {"transient": False if error else True}, + 0 if error else 3000, + dbus_interface="org.freedesktop.Notifications", + ) + except dbus.DBusException as err: + print(f"Error {err} while trying to display {message}.") if __name__ == "__main__":