From 8f347417696b89d1837069606d1e3a4f2607e199 Mon Sep 17 00:00:00 2001 From: Boof2015 <75185879+Boof2015@users.noreply.github.com> Date: Fri, 17 Apr 2026 23:44:56 -0400 Subject: [PATCH] update time sync bug with macos spotify hook --- src/main/services/macSpotifyProvider.ts | 6 +++++- test/mac-spotify-provider.test.ts | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/services/macSpotifyProvider.ts b/src/main/services/macSpotifyProvider.ts index 4c1893c..c6101fb 100644 --- a/src/main/services/macSpotifyProvider.ts +++ b/src/main/services/macSpotifyProvider.ts @@ -123,6 +123,10 @@ function toSafeNumber(value: string | undefined): number { return Math.max(0, numeric) } +function millisecondsToSeconds(value: string | undefined): number { + return toSafeNumber(value) / 1000 +} + function toOptionalUrl(value: string | undefined): string | null { const normalized = normalizeString(value) if (!normalized) { @@ -160,7 +164,7 @@ function parseSpotifyStatusOutput(output: string, now: () => number): LocalSpoti ? parts[1] : 'stopped' const currentTime = toSafeNumber(parts[2]) - const duration = toSafeNumber(parts[3]) + const duration = millisecondsToSeconds(parts[3]) const trackId = normalizeString(parts[4]) const title = normalizeString(parts[5]) const artist = normalizeString(parts[6]) diff --git a/test/mac-spotify-provider.test.ts b/test/mac-spotify-provider.test.ts index da1d895..2fb4b30 100644 --- a/test/mac-spotify-provider.test.ts +++ b/test/mac-spotify-provider.test.ts @@ -104,7 +104,7 @@ test('provider reads local Spotify playback and hydrates artwork while active', createStatusPayload({ playbackState: 'playing', position: 42, - duration: 180, + duration: 180000, id: 'spotify:track:123', title: 'Song One', artist: 'Artist One', @@ -137,6 +137,8 @@ test('provider reads local Spotify playback and hydrates artwork while active', assert.equal(state.snapshot?.currentTrack?.isFavorite, true) assert.match(state.snapshot?.currentTrack?.artworkDataUrl ?? '', /^data:image\/png;base64,/) assert.equal(state.snapshot?.playbackState, 'playing') + assert.equal(state.snapshot?.currentTime, 42) + assert.equal(state.snapshot?.duration, 180) } finally { await provider.dispose() } @@ -183,7 +185,7 @@ test('provider routes transport controls through AppleScript and records control createStatusPayload({ playbackState: 'paused', position: 0, - duration: 180, + duration: 180000, id: 'spotify:track:123', title: 'Song One', artist: 'Artist One',