controller: Improve shutdown handling
This commit is contained in:
parent
244a340764
commit
f501dc046e
@ -1,6 +1,7 @@
|
||||
import configparser
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
|
||||
import infi.systray
|
||||
@ -51,7 +52,7 @@ def main():
|
||||
conf.read(CONFIG_FILE)
|
||||
with open(CONFIG_FILE, 'w') as f:
|
||||
conf.write(f)
|
||||
conf.getboolean('general', 'dummy_impl')
|
||||
use_dummy_impl = conf.getboolean('general', 'dummy_impl')
|
||||
|
||||
log_level = parse_log_level(conf['general']['log_level'])
|
||||
logging.basicConfig(
|
||||
@ -71,10 +72,10 @@ def main():
|
||||
val_sm = valconomy.ValconomyStateMachine(conf['valorant']['player_uuid'], val_handler)
|
||||
|
||||
val_client = valconomy.ValorantLocalClient(val_sm.handle_presence)
|
||||
def do_quit(tray: infi.systray.SysTrayIcon):
|
||||
def do_quit(*args):
|
||||
log.info('Shutting down')
|
||||
val_client.stop()
|
||||
if use_dummy_impl:
|
||||
if not use_dummy_impl:
|
||||
val_handler.stop()
|
||||
|
||||
with infi.systray.SysTrayIcon(
|
||||
@ -82,7 +83,9 @@ def main():
|
||||
menu_options=(
|
||||
('Open data directory', None, do_open_datadir),
|
||||
)) as tray:
|
||||
val_client.run()
|
||||
signal.signal(signal.SIGINT, do_quit)
|
||||
signal.signal(signal.SIGTERM, do_quit)
|
||||
val_client.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -1,7 +1,6 @@
|
||||
import base64
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
from pprint import pprint
|
||||
@ -287,7 +286,7 @@ class HIDValconomyHandler(ValconomyHandler):
|
||||
|
||||
while not self._dev_ready():
|
||||
if not self.running:
|
||||
break
|
||||
return
|
||||
time.sleep(0.1)
|
||||
|
||||
try:
|
||||
@ -298,6 +297,8 @@ class HIDValconomyHandler(ValconomyHandler):
|
||||
def run(self):
|
||||
while self.running:
|
||||
while self.queue.empty():
|
||||
if not self.running:
|
||||
return
|
||||
time.sleep(0.5)
|
||||
|
||||
self.service()
|
||||
@ -308,7 +309,9 @@ class HIDValconomyHandler(ValconomyHandler):
|
||||
self._thread.start()
|
||||
|
||||
def stop(self):
|
||||
assert self._thread is not None and self.running
|
||||
if self._thread is None or not self.running:
|
||||
return
|
||||
self.running = False
|
||||
self._thread.join()
|
||||
|
||||
def none(self):
|
||||
|
Loading…
Reference in New Issue
Block a user