mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Linux: Fix long startup delay on systems that do not have a desktop notification service running
This commit is contained in:
parent
def1417d22
commit
7f29ced61a
@ -31,15 +31,16 @@ class DBUSNotifier(Notifier):
|
|||||||
|
|
||||||
ICON = I('lt.png')
|
ICON = I('lt.png')
|
||||||
|
|
||||||
def __init__(self, server, path, interface):
|
def __init__(self, session_bus):
|
||||||
self.ok, self.err = True, None
|
self.ok, self.err = True, None
|
||||||
|
server, path, interface = self.SERVICE
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
prints('Looking for desktop notifier support from:', server)
|
prints('Looking for desktop notifier support from:', server)
|
||||||
try:
|
try:
|
||||||
import dbus
|
import dbus
|
||||||
self.dbus = dbus
|
self.dbus = dbus
|
||||||
self._notify = dbus.Interface(dbus.SessionBus().get_object(server, path), interface)
|
self._notify = dbus.Interface(session_bus.get_object(server, path), interface)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.ok = False
|
self.ok = False
|
||||||
self.err = str(err)
|
self.err = str(err)
|
||||||
@ -49,9 +50,7 @@ class DBUSNotifier(Notifier):
|
|||||||
|
|
||||||
class KDENotifier(DBUSNotifier):
|
class KDENotifier(DBUSNotifier):
|
||||||
|
|
||||||
def __init__(self):
|
SERVICE = 'org.kde.VisualNotifications', '/VisualNotifications', 'org.kde.VisualNotifications'
|
||||||
DBUSNotifier.__init__(self, 'org.kde.VisualNotifications',
|
|
||||||
'/VisualNotifications', 'org.kde.VisualNotifications')
|
|
||||||
|
|
||||||
def __call__(self, body, summary=None, replaces_id=None, timeout=0):
|
def __call__(self, body, summary=None, replaces_id=None, timeout=0):
|
||||||
if replaces_id is None:
|
if replaces_id is None:
|
||||||
@ -69,9 +68,7 @@ class KDENotifier(DBUSNotifier):
|
|||||||
|
|
||||||
class FDONotifier(DBUSNotifier):
|
class FDONotifier(DBUSNotifier):
|
||||||
|
|
||||||
def __init__(self):
|
SERVICE = 'org.freedesktop.Notifications', '/org/freedesktop/Notifications', 'org.freedesktop.Notifications'
|
||||||
DBUSNotifier.__init__(self, 'org.freedesktop.Notifications',
|
|
||||||
'/org/freedesktop/Notifications', 'org.freedesktop.Notifications')
|
|
||||||
|
|
||||||
def __call__(self, body, summary=None, replaces_id=None, timeout=0):
|
def __call__(self, body, summary=None, replaces_id=None, timeout=0):
|
||||||
if replaces_id is None:
|
if replaces_id is None:
|
||||||
@ -86,6 +83,17 @@ class FDONotifier(DBUSNotifier):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
|
def get_dbus_notifier():
|
||||||
|
import dbus
|
||||||
|
session_bus = dbus.SessionBus()
|
||||||
|
names = frozenset(session_bus.list_names())
|
||||||
|
for srv in KDENotifier, FDONotifier:
|
||||||
|
if srv.SERVICE[0] in names:
|
||||||
|
ans = srv(session_bus)
|
||||||
|
if ans.ok:
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
class QtNotifier(Notifier):
|
class QtNotifier(Notifier):
|
||||||
|
|
||||||
def __init__(self, systray=None):
|
def __init__(self, systray=None):
|
||||||
@ -159,11 +167,7 @@ class AppleNotifier(Notifier):
|
|||||||
def get_notifier(systray=None):
|
def get_notifier(systray=None):
|
||||||
ans = None
|
ans = None
|
||||||
if islinux:
|
if islinux:
|
||||||
ans = KDENotifier()
|
ans = get_dbus_notifier()
|
||||||
if not ans.ok:
|
|
||||||
ans = FDONotifier()
|
|
||||||
if not ans.ok:
|
|
||||||
ans = None
|
|
||||||
elif isosx:
|
elif isosx:
|
||||||
if get_osx_version() >= (10, 8, 0):
|
if get_osx_version() >= (10, 8, 0):
|
||||||
ans = AppleNotifier()
|
ans = AppleNotifier()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user