Descobri que realmente precisava que a DBus conseguisse o que eu precisava. Então, aqui está o que eu precisava fazer:
- Verifique se meu serviço está no dbus
- Se ele passar todas as variáveis de entrada para ele e sair
- se não for criar meu serviço dbus e iniciar meu programa
em Python, seria algo parecido com isto:
# using quickly...
#
# __init__.py
# # # # # # # # # # # # #
import dbus
import sys
from gi.repository import Gtk
# import whatever else you need...
from my_app import MyAppDBusService
# import whatever else from your app...
def main():
bus = dbus.SessionBus()
# Check if my app is running and providing DBus service
if bus.name_has_owner('com.example.myApp'):
#if it is running pass the commandline variables to it and exit
#get my service from DBus
myService = bus.get_object('com.example.myApp', '/com/example/myApp')
#get offered method from DBus
myMethod = myService.get_dbus_method('my_method', 'com.example.myApp')
#call the method and pass comandline varialbes
myMethod(sys.argv)
#exit
sys.exit(0)
else:
#if not running
#run my DBus service by creating MyAppDBusService instance
MyAppDBusService.MyAppDBusService()
#do whatever with sys.argv...
#...
Gtk.main()
# MyAppDBusService.py
# # # # # # # # # # # # # #
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
#import whatever else you need...
# use the dbus mainloop
DBusGMainLoop(set_as_default = True)
class MyAppDBusService(dbus.service.Object):
def __init__(self):
# create dbus service in the SessionBus()
dbus_name = dbus.service.BusName('com.example.myApp', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, dbus_name, '/com/example/myApp')
# offer a method to call using my dbus service
@dbus.service.method('com.example.myApp')
def my_method(self, argv):
#do whatever with argv...