feat: watch mode fetch immediatly on track changes regardless of player status

This commit is contained in:
2026-04-10 07:24:29 +02:00
parent 1c160d5ccb
commit 633983ed98
6 changed files with 206 additions and 139 deletions
+10 -2
View File
@@ -3,12 +3,20 @@
from abc import ABC, abstractmethod
from bisect import bisect_right
from dataclasses import dataclass
from typing import Literal, Optional
from enum import Enum
from typing import Optional
from ...lrc import LRCData, LyricLine
from ...models import TrackMeta
class WatchStatus(str, Enum):
IDLE = "idle"
FETCHING = "fetching"
OK = "ok"
NO_LYRICS = "no_lyrics"
@dataclass(slots=True, frozen=True)
class LyricView:
"""View-ready immutable lyric data projected from one normalized LRC object."""
@@ -70,7 +78,7 @@ class WatchState:
lyrics: Optional[LyricView]
position_ms: int
offset_ms: int
status: Literal["fetching", "ok", "no_lyrics", "paused", "idle"]
status: WatchStatus
class BaseOutput(ABC):
+4 -6
View File
@@ -4,7 +4,7 @@ from bisect import bisect_right
from dataclasses import dataclass
import sys
from . import BaseOutput, WatchState
from . import BaseOutput, WatchState, WatchStatus
@dataclass(slots=True)
@@ -70,13 +70,11 @@ class PipeOutput(BaseOutput):
async def on_state(self, state: WatchState) -> None:
"""Render and flush one frame for the latest watch state."""
if state.status == "fetching":
if state.status == WatchStatus.FETCHING:
lines = self._render_status("[fetching...]")
elif state.status == "no_lyrics":
elif state.status == WatchStatus.NO_LYRICS:
lines = self._render_status("[no lyrics]")
elif state.status == "paused":
lines = self._render_status("[paused]")
elif state.status == "idle":
elif state.status == WatchStatus.IDLE:
lines = self._render_status("[idle]")
else:
lines = self._render_lyrics(state)