Skip to content

Commit

Permalink
Use dbus for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
l0drex committed Apr 18, 2024
1 parent 97e9e8c commit cf2a4d3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
31 changes: 28 additions & 3 deletions yin_yang/NotificationHandler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import subprocess
from logging import Handler

from PySide6.QtDBus import QDBusMessage, QDBusConnection


def create_dbus_message(title: str, body: str):
message = QDBusMessage.createMethodCall(
'org.freedesktop.portal.Desktop',
'/org/freedesktop/portal/desktop',
'org.freedesktop.portal.Notification',
'AddNotification'
)

notification = {
'title': title,
'body': body,
'icon': 'yin_yang',
'priority': 'low',
}

message.setArguments([
'YingYang.ThemeChanged',
notification
])

return message


class NotificationHandler(Handler):
"""Shows logs as notifications"""
def emit(self, record):
subprocess.call(['notify-send', record.levelname, str(record.msg),
'-a', 'Yin & Yang', '-u', 'low', '--icon', 'yin_yang'])
connection = QDBusConnection.sessionBus()
message = create_dbus_message(record.levelname, str(record.msg))
connection.call(message)
13 changes: 9 additions & 4 deletions yin_yang/plugins/notify.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from ._plugin import PluginCommandline
from PySide6.QtDBus import QDBusMessage

from NotificationHandler import create_dbus_message
from ._plugin import DBusPlugin

class Notification(PluginCommandline):

class Notification(DBusPlugin):
def __init__(self):
super().__init__(['notify-send', 'Theme changed', 'Set the theme to {theme}',
'-a', 'Yin & Yang', '-u', 'low', '--icon', 'yin_yang'])
super().__init__()
self.theme_light = 'Day'
self.theme_dark = 'Night'

def create_message(self, theme: str) -> QDBusMessage:
return create_dbus_message('Theme changed', f'Set the theme to {theme}')

0 comments on commit cf2a4d3

Please sign in to comment.