don't rely on upower to check devices after wake-up (#111)
still use upower resume events to ping devices, just in case the old behaviour is available with a command-line option
This commit is contained in:
parent
9934755566
commit
69febfcea5
|
@ -73,6 +73,7 @@ def _create_parser():
|
|||
|
||||
|
||||
_cli_parser, actions = _create_parser()
|
||||
print_help = _cli_parser.print_help
|
||||
|
||||
|
||||
def _receivers():
|
||||
|
@ -130,10 +131,6 @@ def _find_device(receivers, name):
|
|||
|
||||
|
||||
def run(cli_args=None):
|
||||
if cli_args == 'help':
|
||||
_cli_parser.print_help()
|
||||
return
|
||||
|
||||
if cli_args:
|
||||
action = cli_args[0]
|
||||
args = _cli_parser.parse_args(cli_args)
|
||||
|
|
|
@ -128,12 +128,14 @@ def run(receivers, args, find_receiver, find_device):
|
|||
for r in receivers:
|
||||
_print_receiver(r)
|
||||
count = r.count()
|
||||
for dev in r:
|
||||
print ('')
|
||||
_print_device(dev)
|
||||
count -= 1
|
||||
if count == 0:
|
||||
break
|
||||
if count:
|
||||
for dev in r:
|
||||
print ('')
|
||||
_print_device(dev)
|
||||
count -= 1
|
||||
if not count:
|
||||
break
|
||||
print ('')
|
||||
return
|
||||
|
||||
dev = find_receiver(receivers, device_name)
|
||||
|
|
|
@ -42,6 +42,8 @@ def _parse_arguments():
|
|||
arg_parser = argparse.ArgumentParser(prog=NAME.lower())
|
||||
arg_parser.add_argument('-d', '--debug', action='count', default=0,
|
||||
help='print logging messages, for debugging purposes (may be repeated for extra verbosity)')
|
||||
arg_parser.add_argument('--restart-on-wake-up', action='store_true',
|
||||
help='restart Solaar on sleep wake-up (experimental)')
|
||||
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
||||
arg_parser.add_argument('--help-actions', action='store_true',
|
||||
help='print help for the optional actions')
|
||||
|
@ -51,7 +53,8 @@ def _parse_arguments():
|
|||
args = arg_parser.parse_args()
|
||||
|
||||
if args.help_actions:
|
||||
return 'help'
|
||||
_cli.print_help()
|
||||
return
|
||||
|
||||
import logging
|
||||
if args.debug > 0:
|
||||
|
@ -62,11 +65,11 @@ def _parse_arguments():
|
|||
logging.root.addHandler(logging.NullHandler())
|
||||
logging.root.setLevel(logging.ERROR)
|
||||
|
||||
if args.action:
|
||||
return args.action
|
||||
if not args.action:
|
||||
if logging.root.isEnabledFor(logging.INFO):
|
||||
logging.info("language %s (%s), translations path %s", _i18n.language, _i18n.encoding, _i18n.path)
|
||||
|
||||
if logging.root.isEnabledFor(logging.INFO):
|
||||
logging.info("language %s (%s), translations path %s", _i18n.language, _i18n.encoding, _i18n.path)
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -76,9 +79,9 @@ def main():
|
|||
import signal
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
cli_action = _parse_arguments()
|
||||
if cli_action:
|
||||
return _cli.run(cli_action)
|
||||
args = _parse_arguments()
|
||||
if not args: return
|
||||
if args.action: return _cli.run(args.action)
|
||||
|
||||
_require('gi.repository', 'python-gi')
|
||||
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
|
||||
|
@ -87,6 +90,13 @@ def main():
|
|||
import solaar.ui as ui
|
||||
import solaar.listener as listener
|
||||
listener.setup_scanner(ui.status_changed, ui.error_dialog)
|
||||
|
||||
import solaar.upower as _upower
|
||||
if args.restart_on_wake_up:
|
||||
_upower.watch(listener.start_all, listener.stop_all)
|
||||
else:
|
||||
_upower.watch(listener.ping_all)
|
||||
|
||||
# main UI event loop
|
||||
ui.run_loop(listener.start_all, listener.stop_all)
|
||||
except Exception as e:
|
||||
|
|
|
@ -268,9 +268,16 @@ def stop_all():
|
|||
l.join()
|
||||
|
||||
|
||||
# stop/start all receiver threads on suspend/resume events, if possible
|
||||
from . import upower
|
||||
upower.watch(start_all, stop_all)
|
||||
def ping_all():
|
||||
for l in _all_listeners.values():
|
||||
count = l.receiver.count()
|
||||
if count:
|
||||
for dev in l.receiver:
|
||||
dev.ping()
|
||||
l._status_changed(dev)
|
||||
count -= 1
|
||||
if not count:
|
||||
break
|
||||
|
||||
|
||||
from logitech_receiver import base as _base
|
||||
|
|
|
@ -43,7 +43,7 @@ def _resume():
|
|||
_resume_callback()
|
||||
|
||||
|
||||
def watch(on_resume_callback, on_suspend_callback):
|
||||
def watch(on_resume_callback=None, on_suspend_callback=None):
|
||||
"""Register callback for suspend/resume events.
|
||||
They are called only if the system DBus is running, and the UPower daemon is available."""
|
||||
global _resume_callback, _suspend_callback
|
||||
|
|
Loading…
Reference in New Issue