cli: handle situation where GTK application cannot be set up
This commit is contained in:
parent
7d230a1f31
commit
74fe7d7920
|
@ -187,19 +187,22 @@ def run(receivers, args, find_receiver, find_device):
|
||||||
_print_setting(setting)
|
_print_setting(setting)
|
||||||
return
|
return
|
||||||
|
|
||||||
APP_ID = 'io.github.pwr_solaar.solaar'
|
remote = False
|
||||||
application = Gtk.Application.new(APP_ID, Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
|
if Gtk.init_check()[0]: # can Gtk be initialized?
|
||||||
application.register()
|
APP_ID = 'io.github.pwr_solaar.solaar'
|
||||||
|
application = Gtk.Application.new(APP_ID, Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
|
||||||
|
application.register()
|
||||||
|
remote = application.get_is_remote()
|
||||||
|
|
||||||
# if the Solaar UI is running don't save configuration here
|
# if the Solaar UI is running don't save configuration here
|
||||||
result, message, value = set(dev, setting, args, not application.get_is_remote())
|
result, message, value = set(dev, setting, args, not remote)
|
||||||
if message is not None:
|
if message is not None:
|
||||||
print(message)
|
print(message)
|
||||||
if result is None:
|
if result is None:
|
||||||
raise Exception("%s: failed to set value '%s' [%r]" % (setting.name, str(value), value))
|
raise Exception("%s: failed to set value '%s' [%r]" % (setting.name, str(value), value))
|
||||||
|
|
||||||
# if the Solaar UI is running tell it to also perform the set
|
# if the Solaar UI is running tell it to also perform the set
|
||||||
if application.get_is_remote():
|
if remote:
|
||||||
argl = ['config', dev.serial or dev.unitId, setting.name]
|
argl = ['config', dev.serial or dev.unitId, setting.name]
|
||||||
argl.extend([a for a in [args.value_key, args.extra_subkey, args.extra2] if a is not None])
|
argl.extend([a for a in [args.value_key, args.extra_subkey, args.extra2] if a is not None])
|
||||||
application.run(_yaml.safe_dump(argl))
|
application.run(_yaml.safe_dump(argl))
|
||||||
|
|
Loading…
Reference in New Issue