refactor: modules only need to know the config values they need to know

This commit is contained in:
2026-04-09 23:00:10 +02:00
parent 66a32c751a
commit 6d9cfaf8be
7 changed files with 29 additions and 44 deletions
+4 -5
View File
@@ -3,7 +3,6 @@
import asyncio
from typing import Awaitable, Callable, Optional
from ..config import AppConfig
from ..lrc import LRCData
from ..models import TrackMeta
@@ -11,7 +10,7 @@ from ..models import TrackMeta
class LyricFetcher:
"""Debounces track updates and runs at most one lyric fetch task at a time."""
_config: AppConfig
_watch_debounce_ms: int
_fetch_func: Callable[[TrackMeta], Awaitable[Optional[LRCData]]]
_on_fetching: Callable[[], Awaitable[None] | None]
_on_result: Callable[[Optional[LRCData]], Awaitable[None] | None]
@@ -24,10 +23,10 @@ class LyricFetcher:
fetch_func: Callable[[TrackMeta], Awaitable[Optional[LRCData]]],
on_fetching: Callable[[], Awaitable[None] | None],
on_result: Callable[[Optional[LRCData]], Awaitable[None] | None],
config: AppConfig,
watch_debounce_ms: int,
) -> None:
"""Initialize fetch callbacks and runtime options."""
self._config = config
self._watch_debounce_ms = watch_debounce_ms
self._fetch_func = fetch_func
self._on_fetching = on_fetching
self._on_result = on_result
@@ -56,7 +55,7 @@ class LyricFetcher:
async def _debounce_then_fetch(self) -> None:
"""Wait debounce window then start a fresh fetch task for latest pending track."""
await asyncio.sleep(self._config.watch.debounce_ms / 1000.0)
await asyncio.sleep(self._watch_debounce_ms / 1000.0)
track = self._pending_track
if track is None:
return