switch from dbus-python to gio

This commit is contained in:
deltragon 2023-12-31 00:01:57 +01:00
parent 8fb1eb911d
commit 8553693ddf
No known key found for this signature in database
GPG Key ID: 41F552553C6D94B5
5 changed files with 45 additions and 18 deletions

2
debian/control vendored
View File

@ -9,7 +9,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/
Package: safeeyes Package: safeeyes
Architecture: all Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}, gir1.2-ayatanaappindicator3-0.1, python3 (>= 3.10.0), python3-xlib, python3-dbus, gir1.2-notify-0.7, python3-babel, x11-utils, xprintidle, alsa-utils, python3-psutil, python3-croniter, python3-packaging Depends: ${misc:Depends}, ${python3:Depends}, gir1.2-ayatanaappindicator3-0.1, python3 (>= 3.10.0), python3-xlib, gir1.2-notify-0.7, python3-babel, x11-utils, xprintidle, alsa-utils, python3-psutil, python3-croniter, python3-packaging
Description: Safe Eyes Description: Safe Eyes
Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems. Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems.
. .

View File

@ -5,7 +5,7 @@
"version": "0.0.1" "version": "0.0.1"
}, },
"dependencies": { "dependencies": {
"python_modules": ["dbus"], "python_modules": [],
"shell_commands": [], "shell_commands": [],
"operating_systems": [], "operating_systems": [],
"desktop_environments": [], "desktop_environments": [],

View File

@ -22,12 +22,11 @@ Media Control plugin lets users to pause currently playing media player from the
import logging import logging
import os import os
import dbus
import re import re
import gi import gi
from safeeyes.model import TrayAction from safeeyes.model import TrayAction
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk, Gio
tray_icon_path = None tray_icon_path = None
@ -37,13 +36,31 @@ def __active_players():
List of all media players which are playing now. List of all media players which are playing now.
""" """
players = [] players = []
bus = dbus.SessionBus()
for service in bus.list_names(): dbus_proxy = Gio.DBusProxy.new_for_bus_sync(
bus_type=Gio.BusType.SESSION,
flags=Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES,
info=None,
name='org.freedesktop.DBus',
object_path='/org/freedesktop/DBus',
interface_name='org.freedesktop.DBus',
cancellable=None,
)
for service in dbus_proxy.ListNames():
if re.match('org.mpris.MediaPlayer2.', service): if re.match('org.mpris.MediaPlayer2.', service):
player = bus.get_object(service, "/org/mpris/MediaPlayer2") player = Gio.DBusProxy.new_for_bus_sync(
interface = dbus.Interface(player, 'org.freedesktop.DBus.Properties') bus_type=Gio.BusType.SESSION,
status = str(interface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')).lower() flags=Gio.DBusProxyFlags.NONE,
info=None,
name=service,
object_path='/org/mpris/MediaPlayer2',
interface_name='org.mpris.MediaPlayer2.Player',
cancellable=None,
)
status = player.get_cached_property('PlaybackStatus').unpack().lower()
if status == "playing": if status == "playing":
players.append(player) players.append(player)
return players return players
@ -54,8 +71,7 @@ def __pause_players(players):
Pause all playing media players using dbus. Pause all playing media players using dbus.
""" """
for player in players: for player in players:
interface = dbus.Interface(player, dbus_interface='org.mpris.MediaPlayer2.Player') player.Pause()
interface.Pause()
def init(ctx, safeeyes_config, plugin_config): def init(ctx, safeeyes_config, plugin_config):

View File

@ -25,9 +25,7 @@ import logging
import os import os
from threading import Timer from threading import Timer
import dbus
import gi import gi
from dbus.mainloop.glib import DBusGMainLoop
from safeeyes import utility from safeeyes import utility
from safeeyes.ui.about_dialog import AboutDialog from safeeyes.ui.about_dialog import AboutDialog
from safeeyes.ui.break_screen import BreakScreen from safeeyes.ui.break_screen import BreakScreen
@ -189,14 +187,28 @@ class SafeEyes(Gtk.Application):
self.plugins_manager.start() self.plugins_manager.start()
self.safe_eyes_core.start() self.safe_eyes_core.start()
def handle_suspend_signal(self, proxy, sender, signal, parameters):
if signal != "PrepareForSleep":
return
(sleeping, ) = parameters
self.handle_suspend_callback(sleeping)
def handle_system_suspend(self): def handle_system_suspend(self):
""" """
Setup system suspend listener. Setup system suspend listener.
""" """
DBusGMainLoop(set_as_default=True) self.suspend_proxy = Gio.DBusProxy.new_for_bus_sync(
bus = dbus.SystemBus() bus_type=Gio.BusType.SYSTEM,
bus.add_signal_receiver(self.handle_suspend_callback, 'PrepareForSleep', flags=Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES,
'org.freedesktop.login1.Manager', 'org.freedesktop.login1') info=None,
name='org.freedesktop.login1',
object_path='/org/freedesktop/login1',
interface_name='org.freedesktop.login1.Manager',
cancellable=None,
)
self.suspend_proxy.connect('g-signal', self.handle_suspend_signal)
def on_skipped(self): def on_skipped(self):
""" """

View File

@ -7,7 +7,6 @@ requires = [
'babel', 'babel',
'psutil', 'psutil',
'croniter', 'croniter',
'dbus-python',
'PyGObject', 'PyGObject',
'packaging', 'packaging',
'python-xlib' 'python-xlib'