|
1 | 1 | import argparse |
2 | 2 | import asyncio |
3 | 3 | import importlib.metadata |
4 | | -import kisesi |
5 | 4 | import pathlib |
6 | 5 | import sys |
7 | 6 | import threading |
8 | 7 |
|
9 | | -import pyglet.app |
10 | | -import pyglet.media |
| 8 | +import kisesi |
11 | 9 | import websockets.exceptions |
12 | 10 | from websockets.asyncio.client import connect |
13 | 11 |
|
14 | | -from mechvibes_lite import audio, const, struct, util, wskey |
| 12 | +from mechvibes_lite import const, struct, util, wskey |
15 | 13 |
|
16 | 14 | log = kisesi.get_logger(__name__) |
17 | 15 |
|
18 | 16 |
|
19 | 17 | async def start_wskey_listener(theme_path, wskey_host, wskey_port) -> None: |
| 18 | + from mechvibes_lite import audio |
| 19 | + |
| 20 | + log.debug(f"Started wskey listener {wskey_host=} {wskey_port=}") |
20 | 21 | theme = struct.Theme.from_config(theme_path / "config.json", theme_path) |
21 | 22 | keyplayer = audio.KeyPlayer(theme) |
22 | 23 |
|
23 | 24 | async for websocket in connect( |
24 | 25 | f"ws://{wskey_host}:{wskey_port}", ping_timeout=None |
25 | 26 | ): |
26 | 27 | try: |
| 28 | + log.debug("Got a connection...") |
27 | 29 | async for message in websocket: |
28 | 30 | code = int(message) |
29 | 31 | log.debug("Received scan code: %s", code) |
@@ -54,6 +56,10 @@ def cmd_wskey_daemon(host, port, event_path=None) -> None: |
54 | 56 |
|
55 | 57 |
|
56 | 58 | def cmd_daemon(theme_path, wskey_host, wskey_port) -> None: |
| 59 | + import pyglet.app |
| 60 | + import pyglet.media |
| 61 | + |
| 62 | + log.debug("Starting daemon") |
57 | 63 | pyglet.options["headless"] = True |
58 | 64 | thread = threading.Thread( |
59 | 65 | target=asyncio.run, |
@@ -154,7 +160,7 @@ def main() -> None: |
154 | 160 | args.theme_folder_name, |
155 | 161 | args.wskey_host, |
156 | 162 | args.wskey_port, |
157 | | - event_id=args.event_id, |
| 163 | + event_id=getattr(args, "event_id", None), |
158 | 164 | ) |
159 | 165 | except (KeyError, FileNotFoundError) as e: |
160 | 166 | log.error(e.args[0]) |
|
0 commit comments