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:
import dbus
try:
bus = dbus.SessionBus()
def inhibit_sleep(reason):
if inhibit_sleep.handler is None:
inhibit_sleep_handler = None
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)
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
inhibit_sleep_handler = dbus.Interface(proxy, service_name)
def inhibit_sleep(reason):
global inhibit_sleep_handler
inhibit_sleep.token = inhibit_sleep_handler.Inhibit("printrun", reason)
def deinhibit_sleep():
if inhibit_sleep.handler is None:
global inhibit_sleep_handler
if inhibit_sleep_handler is None:
return
inhibit_sleep.handler.UnInhibit(inhibit_sleep.token)
inhibit_sleep_handler.UnInhibit(inhibit_sleep.token)
inhibit_sleep.token = None
except dbus.DBusException, e:
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