controller: Add thread for HID handler to app
This commit is contained in:
		@@ -42,12 +42,16 @@ def main():
 | 
			
		||||
 | 
			
		||||
  conf = configparser.ConfigParser()
 | 
			
		||||
  conf.read_dict({
 | 
			
		||||
    'general': {'log_level': 'info'},
 | 
			
		||||
    'general': {
 | 
			
		||||
      'log_level': 'info',
 | 
			
		||||
      'dummy_impl': False,
 | 
			
		||||
    },
 | 
			
		||||
    'valorant': {'player_uuid': ''},
 | 
			
		||||
  })
 | 
			
		||||
  conf.read(CONFIG_FILE)
 | 
			
		||||
  with open(CONFIG_FILE, 'w') as f:
 | 
			
		||||
    conf.write(f)
 | 
			
		||||
  conf.getboolean('general', 'dummy_impl')
 | 
			
		||||
 | 
			
		||||
  log_level = parse_log_level(conf['general']['log_level'])
 | 
			
		||||
  logging.basicConfig(
 | 
			
		||||
@@ -59,13 +63,19 @@ def main():
 | 
			
		||||
    log.error(f'No player UUID set, exiting...')
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
  if use_dummy_impl:
 | 
			
		||||
    val_handler = valconomy.ValconomyHandler()
 | 
			
		||||
  else:
 | 
			
		||||
    val_handler = valconomy.HIDValconomyHandler()
 | 
			
		||||
    val_handler.start()
 | 
			
		||||
  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):
 | 
			
		||||
    log.info('Shutting down')
 | 
			
		||||
    val_client.stop()
 | 
			
		||||
    if use_dummy_impl:
 | 
			
		||||
      val_handler.stop()
 | 
			
		||||
 | 
			
		||||
  with infi.systray.SysTrayIcon(
 | 
			
		||||
      data_file('icon.ico'), 'Valconomy', on_quit=do_quit,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ from pprint import pprint
 | 
			
		||||
import os
 | 
			
		||||
import queue
 | 
			
		||||
import struct
 | 
			
		||||
import threading
 | 
			
		||||
import time
 | 
			
		||||
from typing import Callable
 | 
			
		||||
 | 
			
		||||
@@ -242,6 +243,7 @@ class HIDValconomyHandler(ValconomyHandler):
 | 
			
		||||
    self.dev = None
 | 
			
		||||
    self.running = True
 | 
			
		||||
    self.queue = queue.Queue(128)
 | 
			
		||||
    self._thread = None
 | 
			
		||||
 | 
			
		||||
  def close(self):
 | 
			
		||||
    if self.dev is not None:
 | 
			
		||||
@@ -300,6 +302,15 @@ class HIDValconomyHandler(ValconomyHandler):
 | 
			
		||||
 | 
			
		||||
      self.service()
 | 
			
		||||
 | 
			
		||||
  def start(self):
 | 
			
		||||
    assert self._thread is None
 | 
			
		||||
    self._thread = threading.Thread(name='HIDValconomyHandler', target=self.run)
 | 
			
		||||
    self._thread.start()
 | 
			
		||||
 | 
			
		||||
  def stop(self):
 | 
			
		||||
    assert self._thread is not None and self.running
 | 
			
		||||
    self._thread.join()
 | 
			
		||||
 | 
			
		||||
  def none(self):
 | 
			
		||||
    self._enq(0)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user