- Remove dbus
- hopefully fixes #248 - hopefully fixes #242 - Removed birdy - Moved notification logic into overlay
This commit is contained in:
parent
bb0819f291
commit
bd2a64ac70
6 changed files with 52 additions and 65655 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -77,7 +77,7 @@ class DiscordConnector:
|
|||
"args":
|
||||
{
|
||||
"client_id": self.oauth_token,
|
||||
"scopes": ["rpc", "messages.read"],
|
||||
"scopes": ["rpc", "messages.read", "rpc.notifications.read"],
|
||||
"prompt": "none",
|
||||
},
|
||||
"nonce": "deadbeef"
|
||||
|
|
@ -324,6 +324,8 @@ class DiscordConnector:
|
|||
elif j["evt"] == "CHANNEL_CREATE":
|
||||
# We haven't been told what guild this is in
|
||||
self.req_channel_details(j["data"]["id"], 'new')
|
||||
elif j["evt"] == "NOTIFICATION_CREATE":
|
||||
self.discover.notification_overlay.add_notification_message(j)
|
||||
else:
|
||||
log.warning(j)
|
||||
return
|
||||
|
|
@ -339,6 +341,7 @@ class DiscordConnector:
|
|||
log.info(
|
||||
"Logged in as %s", self.user["username"])
|
||||
self.authed = True
|
||||
self.on_connected()
|
||||
return
|
||||
elif j["cmd"] == "GET_GUILDS":
|
||||
for guild in j["data"]["guilds"]:
|
||||
|
|
@ -419,8 +422,6 @@ class DiscordConnector:
|
|||
for guild in self.guilds.values():
|
||||
if len(self.voice_settings.guild_ids) > 0 and guild["id"] in self.voice_settings.guild_ids and "channels" not in guild:
|
||||
return
|
||||
# All guilds are filled!
|
||||
self.on_connected()
|
||||
|
||||
def on_connected(self):
|
||||
"""
|
||||
|
|
@ -564,6 +565,7 @@ class DiscordConnector:
|
|||
self.sub_raw("VOICE_CONNECTION_STATUS", {}, "VOICE_CONNECTION_STATUS")
|
||||
self.sub_raw("GUILD_CREATE", {}, "GUILD_CREATE")
|
||||
self.sub_raw("CHANNEL_CREATE", {}, "CHANNEL_CREATE")
|
||||
self.sub_raw("NOTIFICATION_CREATE", {}, "NOTIFICATION_CREATE")
|
||||
|
||||
def sub_channel(self, event, channel):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -17,14 +17,6 @@ import time
|
|||
import sys
|
||||
import re
|
||||
import traceback
|
||||
try:
|
||||
# pylint: disable=wrong-import-position,wrong-import-order
|
||||
import dbus # nopep8
|
||||
# pylint: disable=wrong-import-position,wrong-import-order
|
||||
from dbus.mainloop.glib import DBusGMainLoop # nopep8
|
||||
except:
|
||||
dbus = None
|
||||
pass
|
||||
import logging
|
||||
import pkg_resources
|
||||
import gi
|
||||
|
|
@ -60,9 +52,6 @@ class Discover:
|
|||
self.connection = None
|
||||
self.show_settings_delay = False
|
||||
self.settings = None
|
||||
self.notification_messages = []
|
||||
self.dbus_notification = None
|
||||
self.bus = None
|
||||
|
||||
self.debug_file = debug_file
|
||||
|
||||
|
|
@ -98,19 +87,6 @@ class Discover:
|
|||
|
||||
Gtk.main()
|
||||
|
||||
def set_dbus_notifications(self, enabled=False):
|
||||
if not dbus:
|
||||
return
|
||||
if not self.bus:
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
self.bus = dbus.SessionBus()
|
||||
self.bus.add_match_string_non_blocking(
|
||||
"eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
|
||||
if enabled:
|
||||
if not self.dbus_notification:
|
||||
self.bus.add_message_filter(self.add_notification_message)
|
||||
self.dbus_notification = True
|
||||
|
||||
def periodic_run(self, data=None):
|
||||
if self.voice_overlay.needsredraw:
|
||||
self.voice_overlay.redraw()
|
||||
|
|
@ -118,40 +94,12 @@ class Discover:
|
|||
if self.text_overlay and self.text_overlay.needsredraw:
|
||||
self.text_overlay.redraw()
|
||||
|
||||
if self.notification_overlay and dbus:
|
||||
if self.notification_overlay.enabled:
|
||||
# This doesn't really belong in overlay or settings
|
||||
now = time.time()
|
||||
newlist = []
|
||||
oldsize = len(self.notification_messages)
|
||||
# Iterate over and remove messages older than 30s
|
||||
for message in self.notification_messages:
|
||||
if message['time'] + self.settings.notification_settings.text_time > now:
|
||||
newlist.append(message)
|
||||
self.notification_messages = newlist
|
||||
# If the list is different than before
|
||||
if oldsize != len(newlist):
|
||||
self.notification_overlay.set_content(
|
||||
self.notification_messages, True)
|
||||
if self.notification_overlay and self.notification_overlay.enabled:
|
||||
self.notification_overlay.tick()
|
||||
if self.notification_overlay.needsredraw:
|
||||
self.notification_overlay.redraw()
|
||||
return True
|
||||
|
||||
def add_notification_message(self, bus, message):
|
||||
args = message.get_args_list()
|
||||
if len(args) > 4:
|
||||
noti = {"title": "%s" % (args[3]), "body": "%s" % (args[4]),
|
||||
"icon": "%s" % (args[2]), "cmd": "%s" % (args[0]), "time": time.time()}
|
||||
if len(args) > 6:
|
||||
dictionary = args[6]
|
||||
if 'image-data' in dictionary:
|
||||
noti['icon_raw'] = dictionary['image-data']
|
||||
elif 'image_data' in dictionary:
|
||||
noti['icon_raw'] = dictionary['image_data']
|
||||
self.notification_messages.append(noti)
|
||||
self.notification_overlay.set_content(
|
||||
self.notification_messages, True)
|
||||
|
||||
def do_args(self, data, normal_close):
|
||||
"""
|
||||
Read in arg list from command or RPC and act accordingly
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import math
|
|||
import gi
|
||||
from .image_getter import get_surface, draw_img_to_rect, get_aspected_size, make_surface_from_raw
|
||||
from .overlay import OverlayWindow
|
||||
from .craig_birdy import birdy
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version('PangoCairo', '1.0')
|
||||
# pylint: disable=wrong-import-position,wrong-import-order
|
||||
|
|
@ -27,18 +26,21 @@ from gi.repository import Gtk, Pango, PangoCairo # nopep8
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NotificationOverlayWindow(OverlayWindow):
|
||||
"""Overlay window for notifications"""
|
||||
|
||||
def __init__(self, discover, piggyback=None):
|
||||
OverlayWindow.__init__(self, discover, piggyback)
|
||||
self.text_spacing = 4
|
||||
self.notification_messages = []
|
||||
self.content = []
|
||||
self.test_content = [{"icon": "next", "title": "Title1"},
|
||||
self.test_content = [{"icon": "https://cdn.discordapp.com/avatars/151774162749227008/75dd622dc9f5736f59f7ae1cfcf862a2.webp?size=128", "title": "Title1"},
|
||||
{"title": "Title2", "body": "Body", "icon": None},
|
||||
{"icon": "discord", "title": "Title 3", "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."},
|
||||
{"icon": "https://cdn.discordapp.com/avatars/151774162749227008/75dd622dc9f5736f59f7ae1cfcf862a2.webp?size=128", "title": "Title 3",
|
||||
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."},
|
||||
{"icon": None, "title": "Title 3", "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."},
|
||||
{"icon": None, "title": "PM", "body": "Birdy test", "icon_raw": birdy}]
|
||||
{"icon": "https://cdn.discordapp.com/avatars/147077941317206016/0c0a10fa527c428e68fa527fe7a90bc5.webp?size=128", "title": "PM", "body": "Birdy test"}]
|
||||
self.text_font = None
|
||||
self.text_size = 13
|
||||
self.text_time = None
|
||||
|
|
@ -65,6 +67,42 @@ class NotificationOverlayWindow(OverlayWindow):
|
|||
self.set_title("Discover Text")
|
||||
self.redraw()
|
||||
|
||||
def tick(self):
|
||||
# This doesn't really belong in overlay or settings
|
||||
now = time.time()
|
||||
newlist = []
|
||||
oldsize = len(self.notification_messages)
|
||||
# Iterate over and remove messages older than 30s
|
||||
for message in self.notification_messages:
|
||||
if message['time'] + self.text_time > now:
|
||||
newlist.append(message)
|
||||
self.notification_messages = newlist
|
||||
# If the list is different than before
|
||||
if oldsize != len(newlist):
|
||||
self.set_content(self.notification_messages, True)
|
||||
|
||||
def add_notification_message(self, data):
|
||||
noti = None
|
||||
data = data['data']
|
||||
message_id = data['message']['id']
|
||||
for message in self.notification_messages:
|
||||
if message['id'] == message_id:
|
||||
return
|
||||
if 'body' in data and 'title' in data:
|
||||
if 'icon_url' in data:
|
||||
noti = {"icon": data['icon_url'],
|
||||
"title": data['title'],
|
||||
"body": data['body'], "time": time.time(),
|
||||
"id": message_id}
|
||||
else:
|
||||
noti = {"title": data['title'],
|
||||
"body": data['body'], "time": time.time(),
|
||||
"id": message_id}
|
||||
|
||||
if noti:
|
||||
self.notification_messages.append(noti)
|
||||
self.set_content(self.notification_messages, True)
|
||||
|
||||
def set_padding(self, padding):
|
||||
"""
|
||||
Set the padding between notifications
|
||||
|
|
@ -126,18 +164,10 @@ class NotificationOverlayWindow(OverlayWindow):
|
|||
the_list = self.test_content
|
||||
for line in the_list:
|
||||
icon = line["icon"]
|
||||
if "icon_raw" in line:
|
||||
if "icon_surface" not in line:
|
||||
line["icon_surface"] = make_surface_from_raw(
|
||||
line["icon_raw"], self.icon_size)
|
||||
|
||||
if icon and icon not in self.image_list:
|
||||
icon_theme = Gtk.IconTheme.get_default()
|
||||
icon_info = icon_theme.lookup_icon(
|
||||
icon, self.icon_size, Gtk.IconLookupFlags.FORCE_SIZE)
|
||||
if icon_info:
|
||||
get_surface(self.recv_icon,
|
||||
icon_info.get_filename(), icon, self.icon_size)
|
||||
get_surface(self.recv_icon, icon, icon,
|
||||
self.icon_size)
|
||||
|
||||
def recv_icon(self, identifier, pix):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -147,7 +147,6 @@ class NotificationSettingsWindow(SettingsWindow):
|
|||
self.overlay.set_icon_pad(self.icon_padding)
|
||||
self.overlay.set_padding(self.padding)
|
||||
self.overlay.set_border_radius(self.border_radius)
|
||||
self.discover.set_dbus_notifications(self.enabled)
|
||||
if self.font:
|
||||
self.overlay.set_font(self.font)
|
||||
|
||||
|
|
@ -513,5 +512,4 @@ class NotificationSettingsWindow(SettingsWindow):
|
|||
"""
|
||||
self.overlay.set_enabled(button.get_active())
|
||||
self.enabled = button.get_active()
|
||||
self.discover.set_dbus_notifications(self.enabled)
|
||||
self.save_config()
|
||||
|
|
|
|||
3
setup.py
3
setup.py
|
|
@ -32,8 +32,7 @@ setup(
|
|||
'requests',
|
||||
'python-pidfile>=3.0.0',
|
||||
'pillow',
|
||||
'python-xlib',
|
||||
'dbus-python'
|
||||
'python-xlib'
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue