Fall back to direct execution when dbus is not installed or running

I have been using this with a dbus-less Gentoo template since the original
change, and have tested recently on whonix-gw with dbus enabled and running.

(cherry picked from commit bf69335074b45157734b881cc14d54ea43e7902a)
This commit is contained in:
MB 2017-12-16 18:45:10 +00:00 committed by Marek Marczykowski-Górecki
parent 29e4ac8f97
commit 3339df739d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -2,18 +2,25 @@
from gi.repository import Gio
import sys
import dbus
def launch(desktop, *files):
launcher = Gio.DesktopAppInfo.new_from_filename(desktop)
if hasattr(launcher, 'get_boolean'):
activatable = launcher.get_boolean('DBusActivatable')
if activatable:
bus = dbus.SessionBus()
service_id = launcher.get_id()
# cut the .desktop suffix
service_id = service_id[:-8]
bus.start_service_by_name(service_id)
try:
import dbus
if hasattr(launcher, 'get_boolean'):
activatable = launcher.get_boolean('DBusActivatable')
if activatable:
bus = dbus.SessionBus()
service_id = launcher.get_id()
# cut the .desktop suffix
service_id = service_id[:-8]
try:
bus.start_service_by_name(service_id)
except dbus.DBusException:
pass
return launcher.launch(files, None)
except ImportError:
pass
launcher.launch(files, None)
if __name__ == "__main__":