Commit 02de13cf authored by Guillaume Seguin's avatar Guillaume Seguin

Refactor inhibit_sleep handling on linux to catch errors earlier

parent 20c7ef70
...@@ -36,29 +36,29 @@ else: ...@@ -36,29 +36,29 @@ else:
import dbus import dbus
try: try:
inhibit_sleep_handler = None
bus = dbus.SessionBus() bus = dbus.SessionBus()
try:
# GNOME uses the right object path, try it first
service_name = "org.freedesktop.ScreenSaver"
proxy = bus.get_object(service_name,
"/org/freedesktop/ScreenSaver")
inhibit_sleep_handler = dbus.Interface(proxy, service_name)
except dbus.DBusException:
# KDE uses /ScreenSaver object path, let's try it as well
proxy = bus.get_object(service_name,
"/ScreenSaver")
inhibit_sleep_handler = dbus.Interface(proxy, service_name)
def inhibit_sleep(reason): def inhibit_sleep(reason):
if inhibit_sleep.handler is None: global inhibit_sleep_handler
bus = dbus.SessionBus() inhibit_sleep.token = inhibit_sleep_handler.Inhibit("printrun", reason)
try:
# GNOME uses the right object path, try it first
service_name = "org.freedesktop.ScreenSaver"
proxy = bus.get_object(service_name,
"/org/freedesktop/ScreenSaver")
inhibit_sleep.handler = dbus.Interface(proxy, service_name)
except dbus.DBusException:
# KDE uses /ScreenSaver object path, let's try it as well
proxy = bus.get_object(service_name,
"/ScreenSaver")
inhibit_sleep.handler = dbus.Interface(proxy, service_name)
inhibit_sleep.token = inhibit_sleep.handler.Inhibit("printrun", reason)
inhibit_sleep.handler = None
def deinhibit_sleep(): def deinhibit_sleep():
if inhibit_sleep.handler is None: global inhibit_sleep_handler
if inhibit_sleep_handler is None:
return return
inhibit_sleep.handler.UnInhibit(inhibit_sleep.token) inhibit_sleep_handler.UnInhibit(inhibit_sleep.token)
inhibit_sleep.token = None inhibit_sleep.token = None
except dbus.DBusException, e: except dbus.DBusException, e:
print "dbus unavailable:", e.message print "dbus unavailable:", e.message
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment