def main():
'''Dispatches control to the appropriate parts of the app'''
args = parse_args()
config = get_config()
if not dependencies_are_satisfied():
return 'This program depends on xprintidle and xdotool being installed.'
config.acpi_available = battery.acpi_available()
if args.delete:
config = get_config()
for file_ in (config.config_file, config.desktop_filename):
try:
os.unlink(file_)
except FileNotFoundError:
print('{}: File not found'.format(file_))
return 0
elif args.mode == 'indicator':
if args.battery is not None:
config.battery = args.battery
if args.percent is not None:
config.batt_percent = args.percent
inhibitor = sleepinhibit.gui.main.SleepInhibitGUI()
if config.start_inhibited or args.inhibit:
inhibitor.on_toggle()
try:
GLib.MainLoop().run()
except KeyboardInterrupt:
inhibitor.on_quit(signal='SIGINT')
return 0
elif args.mode == 'inhibit-process':
from sleepinhibit.inhibitor import run
kw = {}
if args.battery is True:
kw['battery'] = True
if args.percent:
kw['percent'] = args.percent
try:
run(**kw)
except KeyboardInterrupt:
return 0
else:
return 'ERROR: Invalid value for --mode!'
评论列表
文章目录