Skip to content

Commit dffc77f

Browse files
committed
fix: resolved a bunch of bugs
I don't what bugs I resolved because most of them were a couple months old and I don't remember anymore.
1 parent 4d4790a commit dffc77f

File tree

7 files changed

+36
-18
lines changed

7 files changed

+36
-18
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mechvibes-lite"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "A lightweight backend for Mechvibes."
55
readme = "README.md"
66
authors = [

src/mechvibes_lite/__main__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import argparse
22
import asyncio
33
import importlib.metadata
4-
import kisesi
54
import pathlib
65
import sys
76
import threading
87

9-
import pyglet.app
10-
import pyglet.media
8+
import kisesi
119
import websockets.exceptions
1210
from websockets.asyncio.client import connect
1311

14-
from mechvibes_lite import audio, const, struct, util, wskey
12+
from mechvibes_lite import const, struct, util, wskey
1513

1614
log = kisesi.get_logger(__name__)
1715

1816

1917
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=}")
2021
theme = struct.Theme.from_config(theme_path / "config.json", theme_path)
2122
keyplayer = audio.KeyPlayer(theme)
2223

2324
async for websocket in connect(
2425
f"ws://{wskey_host}:{wskey_port}", ping_timeout=None
2526
):
2627
try:
28+
log.debug("Got a connection...")
2729
async for message in websocket:
2830
code = int(message)
2931
log.debug("Received scan code: %s", code)
@@ -54,6 +56,10 @@ def cmd_wskey_daemon(host, port, event_path=None) -> None:
5456

5557

5658
def cmd_daemon(theme_path, wskey_host, wskey_port) -> None:
59+
import pyglet.app
60+
import pyglet.media
61+
62+
log.debug("Starting daemon")
5763
pyglet.options["headless"] = True
5864
thread = threading.Thread(
5965
target=asyncio.run,
@@ -154,7 +160,7 @@ def main() -> None:
154160
args.theme_folder_name,
155161
args.wskey_host,
156162
args.wskey_port,
157-
event_id=args.event_id,
163+
event_id=getattr(args, "event_id", None),
158164
)
159165
except (KeyError, FileNotFoundError) as e:
160166
log.error(e.args[0])

src/mechvibes_lite/audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import kisesi
21
import pathlib
32
from functools import partial
43

4+
import kisesi
55
import pyglet.clock
66
import pyglet.media as media
77

src/mechvibes_lite/struct.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import kisesi
21
import pathlib
32
from dataclasses import dataclass
43
from enum import Enum, auto
54

5+
import kisesi
6+
67
from mechvibes_lite import util
78

89
log = kisesi.get_logger(__name__)
@@ -45,7 +46,9 @@ def __post_init__(self):
4546

4647
self.event_id = util.parse_event_id(self.event_id)
4748

48-
self.event_path = self.event_path_base / self.event_id
49+
self.event_path = (
50+
self.event_path_base / self.event_id if self.event_id else None
51+
)
4952
self.theme_path = self.theme_dir / self.theme_folder_name
5053

5154
self.ensure_files_exist()

src/mechvibes_lite/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
def get_config_path(app_name: str) -> pathlib.Path:
77
if os.name == "nt":
8-
config_dir = os.getenv("APPDATA", pathlib.Path.home() / "AppData" / "Roaming")
8+
config_dir = pathlib.Path(
9+
os.getenv("APPDATA", pathlib.Path.home() / "AppData" / "Roaming")
10+
)
911
elif os.name == "posix":
1012
if sys.platform == "darwin":
1113
config_dir = pathlib.Path.home() / "Library" / "Application Support"

src/mechvibes_lite/wskey/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import kisesi
1+
import asyncio
22
import sys
33
from functools import partial
44

5+
import kisesi
56
from websockets.asyncio.server import serve
67

78
log = kisesi.get_logger(__name__)
@@ -13,14 +14,21 @@ async def keyboard_mod_sender(websocket) -> None:
1314
log.debug("Sending keys from keyboard_mod_sender")
1415
import keyboard
1516

17+
loop = asyncio.get_running_loop()
18+
1619
while True:
17-
event = keyboard.read_event()
20+
try:
21+
event = await loop.run_in_executor(None, keyboard.read_event)
22+
except RuntimeError:
23+
await asyncio.sleep(0.1)
24+
continue
25+
1826
log.debug("Got event: %s", event)
1927

2028
if event.event_type is not keyboard.KEY_UP:
2129
continue
2230

23-
log.debug("Sending scancode from event: %s", event)
31+
log.debug(f"Sending {event.scan_code=} from {event=}")
2432

2533
await websocket.send(str(event.scan_code))
2634

@@ -31,8 +39,6 @@ async def evdev_sender(websocket, *, event_path) -> None:
3139

3240
device = evdev.InputDevice(event_path)
3341

34-
await websocket.send(str(1))
35-
3642
for event in device.read_loop():
3743
if event.type != evdev.ecodes.EV_KEY:
3844
continue
@@ -60,5 +66,6 @@ async def start(host, port, event_path=None) -> None:
6066
else:
6167
raise NotImplementedError(f"No listener for {sys.platform} yet")
6268

69+
log.debug(f"Serving wskey on {host=} {port=}")
6370
server = await serve(sender, host, port)
6471
await server.serve_forever()

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)