Add support for disabling notifications with enviroment variable

This commit is contained in:
Layerex 2022-09-28 11:07:52 +03:00
parent ff2d5600eb
commit d302782073
No known key found for this signature in database
GPG Key ID: 21AE9A379DE6B677
2 changed files with 23 additions and 16 deletions

View File

@ -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

View File

@ -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__":