Skip to content

feat(api-server): added elapsedMilliseconds value for precision#4591

Open
AARP41298 wants to merge 1 commit into
pear-devs:masterfrom
AARP41298:elapsedMilliseconds
Open

feat(api-server): added elapsedMilliseconds value for precision#4591
AARP41298 wants to merge 1 commit into
pear-devs:masterfrom
AARP41298:elapsedMilliseconds

Conversation

@AARP41298

@AARP41298 AARP41298 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Fix #4320

Summary by CodeRabbit

  • New Features
    • Song information responses now include playback progress with millisecond precision when available.
    • Playback timing is synchronized with the current video position and remains compatible with second-based timing data.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The song info model and API schema now support optional millisecond precision. Song info routes read the renderer’s live video position, populate elapsed timing fields, and fall back to existing elapsed seconds when necessary.

Changes

Song info playback timing

Layer / File(s) Summary
Live playback timing response
src/providers/song-info.ts, src/plugins/api-server/backend/scheme/song-info.ts, src/plugins/api-server/backend/routes/control.ts
SongInfo and its response schema include optional elapsedMilliseconds; song info routes derive it from the renderer’s video.currentTime or existing elapsed seconds.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Suggested reviewers: jellybrick

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding elapsedMilliseconds precision to the API server.
Linked Issues check ✅ Passed The PR adds elapsedMilliseconds to the song API response and related schema/types, matching issue #4320's precision requirement.
Out of Scope Changes check ✅ Passed The changes are focused on exposing elapsedMilliseconds and related type updates, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/plugins/api-server/backend/routes/control.ts`:
- Around line 746-748: Handle rejections from the executeJavaScript call used to
assign currentTime in the endpoint by adding a catch that returns null, allowing
the existing elapsedSeconds fallback logic to run without propagating an API
error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6dacf97b-260b-4119-9a46-f9dbedb3e300

📥 Commits

Reviewing files that changed from the base of the PR and between 7ac6300 and 42f8ae1.

📒 Files selected for processing (3)
  • src/plugins/api-server/backend/routes/control.ts
  • src/plugins/api-server/backend/scheme/song-info.ts
  • src/providers/song-info.ts

Comment on lines +746 to +748
const currentTime = (await window.webContents.executeJavaScript(
'document.querySelector("video")?.currentTime ?? null',
)) as number | null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Handle executeJavaScript rejections to prevent API 500 errors.

If the renderer process is navigating, reloading, or otherwise unavailable when this endpoint is polled, executeJavaScript will reject. This causes an unhandled promise rejection that crashes the request handler instead of safely executing the elapsedSeconds fallback logic.

Add a .catch() block to gracefully handle these rejections.

🛡️ Proposed fix
     // Prefer live video.currentTime for ms precision
     const currentTime = (await window.webContents.executeJavaScript(
       'document.querySelector("video")?.currentTime ?? null',
-    )) as number | null;
+    ).catch(() => null)) as number | null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const currentTime = (await window.webContents.executeJavaScript(
'document.querySelector("video")?.currentTime ?? null',
)) as number | null;
const currentTime = (await window.webContents.executeJavaScript(
'document.querySelector("video")?.currentTime ?? null',
).catch(() => null)) as number | null;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/api-server/backend/routes/control.ts` around lines 746 - 748,
Handle rejections from the executeJavaScript call used to assign currentTime in
the endpoint by adding a catch that returns null, allowing the existing
elapsedSeconds fallback logic to run without propagating an API error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: add elapsedMilliseconds to api/v1/song

1 participant