From ab352b95958c9427d7ec1fdd43d18cb8e4cb9fb5 Mon Sep 17 00:00:00 2001 From: Ultradesu Date: Tue, 9 Jun 2026 10:50:08 +0100 Subject: [PATCH] fix: send Last.fm now-playing notification when track starts Add POST /api/player/lastfm/now-playing call on every track start via onTrackStarted callback in PlayerManager, matching other clients. Co-Authored-By: Claude Sonnet 4.6 --- furumi_macos/CatalogService.swift | 6 ++++++ furumi_macos/ContentView.swift | 3 +++ furumi_macos/PlayerManager.swift | 3 +++ 3 files changed, 12 insertions(+) diff --git a/furumi_macos/CatalogService.swift b/furumi_macos/CatalogService.swift index 161c963..a4d15a7 100644 --- a/furumi_macos/CatalogService.swift +++ b/furumi_macos/CatalogService.swift @@ -190,6 +190,12 @@ struct CatalogService { _ = try await post(path: "api/player/devices/command", body: body) } + func lastfmNowPlaying(trackId: Int64) async throws { + struct Body: Encodable { let trackId: Int64 } + let body = try Self.deviceEncoder.encode(Body(trackId: trackId)) + _ = try await post(path: "api/player/lastfm/now-playing", body: body) + } + func recordHistory(trackId: Int64, startedAt: Int64?, durationListened: Int32, completed: Bool) async throws { struct Body: Encodable { let trackId: Int64 diff --git a/furumi_macos/ContentView.swift b/furumi_macos/ContentView.swift index c816c3a..22fbc76 100644 --- a/furumi_macos/ContentView.swift +++ b/furumi_macos/ContentView.swift @@ -106,6 +106,9 @@ struct ContentView: View { Task { await authManager.loadLikedIds() } deviceManager.start(service: service, player: player) let am = authManager + player.onTrackStarted = { trackId in + try? await am.catalogService?.lastfmNowPlaying(trackId: trackId) + } player.onTrackFinished = { trackId, startedAt, durationListened, completed in guard let svc = am.catalogService else { return } try? await svc.recordHistory(trackId: trackId, startedAt: startedAt, durationListened: durationListened, completed: completed) diff --git a/furumi_macos/PlayerManager.swift b/furumi_macos/PlayerManager.swift index a6a013c..cd7bafc 100644 --- a/furumi_macos/PlayerManager.swift +++ b/furumi_macos/PlayerManager.swift @@ -37,6 +37,7 @@ final class PlayerManager { var canGoPrevious: Bool { currentIndex > 0 } var formattedCurrentTime: String { formatTime(currentTime) } + var onTrackStarted: ((Int64) async -> Void)? var onTrackFinished: ((Int64, Int64?, Int32, Bool) async -> Void)? private var player: AVPlayer? @@ -102,6 +103,8 @@ final class PlayerManager { addObserver() updateNowPlayingInfo(track: track) + let cb = onTrackStarted + Task { await cb?(track.id) } } // MARK: - Public playback