@@ -718,22 +718,42 @@ def on_unregister_failed(error):
718718
719719if __name__ == '__main__' :
720720 settings = Gio .Settings (schema = "org.blueberry" )
721- if settings .get_boolean ("obex-enabled" ):
722- try :
723- dbus .mainloop .glib .DBusGMainLoop (set_as_default = True )
724- mainloop = GLib .MainLoop ()
725- service = TransferService ()
726- service .load ()
727- cont = True
728- while cont :
729- try :
730- mainloop .run ()
731- except KeyboardInterrupt :
732- service .unload ()
733- cont = False
734- except Exception as e :
735- dprint ("Something went wrong in blueberry-obex-agent: %s" % e )
736- dprint ("Setting org.blueberry obex-enabled to False and exiting." )
721+ service = mainloop = setting_id = None
722+ disable_on_exit = False
723+
724+ def exit_if_disabled (* args ):
725+ if not settings .get_boolean ("obex-enabled" ):
726+ dprint ("org.blueberry obex-enabled is False, exiting." )
727+ sys .exit (0 )
728+
729+ exit_if_disabled ()
730+
731+ try :
732+ setting_id = settings .connect ("changed::obex-enabled" , exit_if_disabled )
733+ dbus .mainloop .glib .DBusGMainLoop (set_as_default = True )
734+ mainloop = GLib .MainLoop ()
735+ service = TransferService ()
736+ service .load ()
737+ cont = True
738+ while cont :
739+ try :
740+ mainloop .run ()
741+ except KeyboardInterrupt :
742+ sys .exit (1 )
743+ cont = False
744+ except SystemExit :
745+ pass
746+ except Exception as e :
747+ dprint ("Something went wrong in blueberry-obex-agent: %s" % e )
748+ dprint ("Setting org.blueberry obex-enabled to False and exiting." )
749+ disable_on_exit = True
750+ sys .exit (1 )
751+ finally :
752+ if service :
753+ service .unload ()
754+ if setting_id :
755+ settings .disconnect (setting_id )
756+ if mainloop :
757+ mainloop .quit ()
758+ if disable_on_exit :
737759 settings .set_boolean ("obex-enabled" , False )
738- else :
739- dprint ("org.blueberry obex-enabled is False, exiting." )
0 commit comments