forked from oskarsh/Yin-Yang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' of github.com:oskarsh/Yin-Yang into add-flatpak
- Loading branch information
Showing
8 changed files
with
216 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import logging | ||
import subprocess | ||
from logging import Handler | ||
|
||
logger = logging.getLogger() | ||
from PySide6.QtDBus import QDBusConnection, QDBusMessage | ||
|
||
|
||
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): | ||
try: | ||
subprocess.call(['notify-send', record.levelname, str(record.msg), | ||
'-a', 'Yin & Yang', '-u', 'low', '--icon', 'yin_yang']) | ||
except FileNotFoundError: | ||
logger.warn('notify-send not found. Notifications will not work!') | ||
connection = QDBusConnection.sessionBus() | ||
message = create_dbus_message(record.levelname, str(record.msg)) | ||
connection.call(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
Oops, something went wrong.