2015-08-27 20:08:33 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2018-03-06 00:05:55 +01:00
|
|
|
from gi.repository import Gio # pylint: disable=import-error
|
|
|
|
from gi.repository import GLib # pylint: disable=import-error
|
2015-08-27 20:08:33 +02:00
|
|
|
import sys
|
2018-03-05 23:37:42 +01:00
|
|
|
import os
|
2015-08-27 20:08:33 +02:00
|
|
|
|
2018-03-05 23:37:42 +01:00
|
|
|
def pid_callback(launcher, pid, pid_list):
|
|
|
|
pid_list.append(pid)
|
|
|
|
|
|
|
|
def launch(desktop, *files, **kwargs):
|
|
|
|
wait = kwargs.pop('wait', True)
|
2015-08-27 20:08:33 +02:00
|
|
|
launcher = Gio.DesktopAppInfo.new_from_filename(desktop)
|
2017-12-16 19:45:10 +01:00
|
|
|
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
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2018-03-05 23:37:42 +01:00
|
|
|
if wait:
|
|
|
|
pid_list = []
|
|
|
|
flags = GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD
|
|
|
|
launcher.launch_uris_as_manager(files, None, flags, None, None,
|
|
|
|
pid_callback, pid_list)
|
|
|
|
for pid in pid_list:
|
|
|
|
os.waitpid(pid, 0)
|
|
|
|
else:
|
|
|
|
launcher.launch(files, None)
|
2015-08-27 20:08:33 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
launch(*sys.argv[1:])
|