Repository navigation
Persist audio/subtitle track selections across player exits (web parity) - #50
Conversation
Dismissing the remote sheet flipped isShowingRemoteControl, which re-attached the tabViewBottomAccessory and triggered the system's accessory slide-in — a second animation on top of the sheet dismissal. Keep the bar visible (covered by the sheet) so dismissal just reveals it. Co-Authored-By: Claude Fable 5 <[email protected]>
Track picks on the detail page and in the player were transient: the web app writes them to /audio-prefs and /subtitle-prefs (episodes key by series id, movies by content id) and the server folds them back into the effective_* fields both clients already read, but the Apple clients never wrote anything — every selection died with the view. - New TrackSelectionPersistence: pref key resolution, pure request builders (pick → mode "always", off → "off"/index -1, Auto → DELETE the override), best-effort fire-and-forget writers. - PlayerViewModel selectAudio/selectSubtitle/disableSubtitles persist the choice; offline playback and live AI tracks are excluded, and signatures prefer the server's probed metadata from the selected version so re-resolution gets an exact match. - iOS + tvOS detail selector callbacks persist (movie/episode branch and next-up selectors on season/series pages). - AudioTrack/SubtitleTrack decode embedded_title / hearing_impaired; the server's signature matcher compares them separately, so omitting them broke exact cross-episode matching. - PlaybackSessionBridge falls back to the detail-resolved effective audio index: /playback/start only consults saved audio prefs for episodes, so movie audio prefs were dropped at start otherwise. Version choice needed no work: last-played hints on watch_progress (written at stop) and series-level traits already round-trip. Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughAdds server-backed persistence of user audio/subtitle track selections via a new TrackSelectionPersistence networking layer, wires it into PlayerViewModel and detail views (phone and tvOS), extends track models with embeddedTitle/hearingImpaired fields, adjusts iOS control-bar visibility logic, and adds an audio index fallback in playback session start. ChangesTrack Selection Persistence
iOS Control Bar Visibility
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant PlayerViewModel
participant TrackSelectionPersistence
participant ContinuumAPI
User->>PlayerViewModel: select audio/subtitle track
PlayerViewModel->>PlayerViewModel: compute trackPrefPersistKey
alt server-backed item
PlayerViewModel->>TrackSelectionPersistence: persistAudioSelection / persistSubtitleSelection
TrackSelectionPersistence->>ContinuumAPI: PUT or DELETE preference
ContinuumAPI-->>TrackSelectionPersistence: success or error
TrackSelectionPersistence-->>PlayerViewModel: warning logged on failure
else offline playback
PlayerViewModel-->>PlayerViewModel: no-op (nil pref key)
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11ab974ff7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ) { | ||
| guard let prefKey else { return } | ||
| guard let requested else { | ||
| TrackSelectionPersistence.clearAudio(prefKey: prefKey) |
There was a problem hiding this comment.
Await Auto clears before starting playback
When a user selects Auto for audio on the detail page and immediately taps Play, this unawaited DELETE can race with PlaybackSessionBridge.startSession: the next /watch fetch may still include the old per-series audio override, and the new bridge code then passes that stale selectedVersion.effectiveAudioTrackIndex explicitly to /playback/start. The UI has switched to Auto, but the old audio track can still start; the clear needs to complete or be carried as an explicit inherit sentinel for that start.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
iosApp/iosApp/Control/iOS/NowPlayingShelf.swift (1)
23-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate visibility formula across two files.
This formula
(control.hasActiveSession && !control.isAutoResuming) || control.isReconnectingis now duplicated verbatim inSiloControlMiniBar.isVisible(iosApp/iosApp/Control/iOS/SiloControlMiniBar.swift, lines 21-23). Consider extracting a shared computed property (e.g., onSiloControlClient) to prevent the two copies from silently drifting apart in future edits.♻️ Proposed consolidation
// SiloControlClient.swift + var isMiniBarVisible: Bool { + (hasActiveSession && !isAutoResuming) || isReconnecting + }// NowPlayingShelf.swift - static func controlBarVisible(_ control: SiloControlClient) -> Bool { - (control.hasActiveSession && !control.isAutoResuming) || control.isReconnecting - } + static func controlBarVisible(_ control: SiloControlClient) -> Bool { + control.isMiniBarVisible + }// SiloControlMiniBar.swift - private var isVisible: Bool { - (controller.hasActiveSession && !controller.isAutoResuming) || controller.isReconnecting - } + private var isVisible: Bool { + controller.isMiniBarVisible + }🤖 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 `@iosApp/iosApp/Control/iOS/NowPlayingShelf.swift` around lines 23 - 29, The visibility check is duplicated between NowPlayingShelf.controlBarVisible and SiloControlMiniBar.isVisible, so extract the shared formula into a single computed property on SiloControlClient (or another shared helper) and update both call sites to use it. Keep the existing logic exactly the same while removing the verbatim copy so future changes only need to be made in one place.iosApp/iosApp/Screens/Detail/ItemDetailView.swift (1)
626-680: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate persistence helpers across ItemDetailView and TVItemDetailView.
prefKey(for:),persistAudioSelection(prefKey:version:requested:sanitized:), andpersistSubtitleSelection(...)here are near-identical to the ones added inTVItemDetailView.swift(Lines 512-554). Consider hoisting this shared "requested == sanitized → persist, nil → clear" logic intoTrackSelectionPersistenceas static helpers, called from both detail views. This would also have prevented theshowForcedinconsistency flagged inTVItemDetailView.swift.♻️ Proposed consolidation sketch (in TrackSelectionPersistence.swift)
extension TrackSelectionPersistence { static func persistAudioSelection(prefKey: String?, version: FileVersion?, requested: Int?, sanitized: Int?) { guard let prefKey else { return } guard let requested else { clearAudio(prefKey: prefKey) return } guard requested == sanitized, let version, let request = audioRequest(version: version, ordinal: requested) else { return } saveAudio(prefKey: prefKey, request: request) } static func persistSubtitleSelection(prefKey: String?, version: FileVersion?, requested: Int?, sanitized: Int?, showForced: Bool?) { guard let prefKey else { return } guard let requested else { clearSubtitle(prefKey: prefKey) return } guard requested == sanitized, let version, let request = subtitleRequest(version: version, ffIndex: requested, showForced: showForced) else { return } saveSubtitle(prefKey: prefKey, request: request) } }Both detail views would then just call
TrackSelectionPersistence.persistAudioSelection(...)/persistSubtitleSelection(...), dropping their local private copies.🤖 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 `@iosApp/iosApp/Screens/Detail/ItemDetailView.swift` around lines 626 - 680, Duplicate track-selection persistence logic is still defined locally in ItemDetailView via prefKey(for:), persistAudioSelection(prefKey:version:requested:sanitized:), and persistSubtitleSelection(...), even though the same “requested == sanitized persist, nil clear” behavior belongs in TrackSelectionPersistence. Move this shared logic into static helpers on TrackSelectionPersistence and update both ItemDetailView and TVItemDetailView to call those helpers, so the persistence behavior stays consistent and the showForced handling remains centralized.
🤖 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 `@iosApp/iosApp/Networking/TrackSelectionPersistence.swift`:
- Around line 156-211: The fire-and-forget writers in TrackSelectionPersistence
can race when saveAudio, saveSubtitle, clearAudio, and clearSubtitle are called
back-to-back for the same prefKey, allowing an older network response to
overwrite a newer track choice. Add per-prefKey serialization in these helpers,
such as tracking the in-flight Task or a generation/token per key and canceling
or ignoring stale work before starting the next ContinuumAPI.shared request.
Make the fix around the existing saveAudio/saveSubtitle/clearAudio/clearSubtitle
methods so each prefKey only persists the latest selection.
In `@iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift`:
- Around line 154-173: The next-up subtitle save in TVItemDetailView is dropping
the forced-subtitle preference by passing a nil value. Update the
onSelectNextUpSubtitleTrack flow to thread the existing
effectiveShowForcedSubtitles value into persistSubtitleSelection, using the same
prefKey(for:), effectiveVersion(for:versionFileId:), and
sanitizedSubtitleTrackIndex path so the saved subtitle choice matches iOS
behavior.
---
Nitpick comments:
In `@iosApp/iosApp/Control/iOS/NowPlayingShelf.swift`:
- Around line 23-29: The visibility check is duplicated between
NowPlayingShelf.controlBarVisible and SiloControlMiniBar.isVisible, so extract
the shared formula into a single computed property on SiloControlClient (or
another shared helper) and update both call sites to use it. Keep the existing
logic exactly the same while removing the verbatim copy so future changes only
need to be made in one place.
In `@iosApp/iosApp/Screens/Detail/ItemDetailView.swift`:
- Around line 626-680: Duplicate track-selection persistence logic is still
defined locally in ItemDetailView via prefKey(for:),
persistAudioSelection(prefKey:version:requested:sanitized:), and
persistSubtitleSelection(...), even though the same “requested == sanitized
persist, nil clear” behavior belongs in TrackSelectionPersistence. Move this
shared logic into static helpers on TrackSelectionPersistence and update both
ItemDetailView and TVItemDetailView to call those helpers, so the persistence
behavior stays consistent and the showForced handling remains centralized.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4de0d08e-6b85-41f7-be28-488cbcc28585
📒 Files selected for processing (9)
iosApp/Tests/TrackSelectionPersistenceTests.swiftiosApp/iosApp/Control/iOS/NowPlayingShelf.swiftiosApp/iosApp/Control/iOS/SiloControlMiniBar.swiftiosApp/iosApp/Networking/Models.swiftiosApp/iosApp/Networking/TrackSelectionPersistence.swiftiosApp/iosApp/Screens/Detail/ItemDetailView.swiftiosApp/iosApp/Screens/Player/PlaybackSessionBridge.swiftiosApp/iosApp/Screens/Player/PlayerViewModel.swiftiosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift
| // MARK: - Fire-and-forget writers | ||
|
|
||
| static func saveAudio(prefKey: String, request: AudioPrefRequest) { | ||
| Task { | ||
| do { | ||
| try await ContinuumAPI.shared.setAudioPref(seriesId: prefKey, body: request) | ||
| } catch { | ||
| logger.warning( | ||
| "audio pref save failed key=\(prefKey, privacy: .public): \(String(describing: error), privacy: .public)" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static func saveSubtitle(prefKey: String, request: SubtitlePrefRequest) { | ||
| Task { | ||
| do { | ||
| try await ContinuumAPI.shared.setSubtitlePref(seriesId: prefKey, body: request) | ||
| } catch { | ||
| logger.warning( | ||
| "subtitle pref save failed key=\(prefKey, privacy: .public): \(String(describing: error), privacy: .public)" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The detail selectors' "Auto" choice — remove the sticky override | ||
| /// so the library/profile cascade applies again. A 404 just means | ||
| /// no override existed. | ||
| static func clearAudio(prefKey: String) { | ||
| Task { | ||
| do { | ||
| try await ContinuumAPI.shared.deleteAudioPref(seriesId: prefKey) | ||
| } catch HTTPError.http(let code, _) where code == 404 { | ||
| // Nothing to clear. | ||
| } catch { | ||
| logger.warning( | ||
| "audio pref clear failed key=\(prefKey, privacy: .public): \(String(describing: error), privacy: .public)" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static func clearSubtitle(prefKey: String) { | ||
| Task { | ||
| do { | ||
| try await ContinuumAPI.shared.deleteSubtitlePref(seriesId: prefKey) | ||
| } catch HTTPError.http(let code, _) where code == 404 { | ||
| // Nothing to clear. | ||
| } catch { | ||
| logger.warning( | ||
| "subtitle pref clear failed key=\(prefKey, privacy: .public): \(String(describing: error), privacy: .public)" | ||
| ) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the target file around the reported lines
FILE="iosApp/iosApp/Networking/TrackSelectionPersistence.swift"
wc -l "$FILE"
sed -n '1,260p' "$FILE" | cat -n | sed -n '130,240p'
# Find call sites and related coordination logic
rg -n "saveAudio\(|saveSubtitle\(|clearAudio\(|clearSubtitle\(" iosApp/iosApp
rg -n "TrackSelectionPersistence|prefKey|AudioPrefRequest|SubtitlePrefRequest|deboun|seriali|Task\s*\{" iosApp/iosAppRepository: Silo-Server/silo-apple
Length of output: 50378
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the exact call sites for track-selection persistence
sed -n '4260,4325p' iosApp/iosApp/Screens/Player/PlayerViewModel.swift | cat -n
sed -n '635,685p' iosApp/iosApp/Screens/Detail/ItemDetailView.swift | cat -n
sed -n '515,560p' iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift | cat -n
# Look for any dedicated serialization/cancellation around track-selection writes
rg -n "TrackSelectionPersistence|inFlight|cancel\(\)|debounce|prefKey" iosApp/iosApp/Networking iosApp/iosApp/Screens/Player iosApp/iosApp/Screens/Detail iosApp/iosApp/tvOS/Screens/DetailRepository: Silo-Server/silo-apple
Length of output: 36064
Serialize track-selection writes per prefKey. These helpers are called directly from the player/detail selection handlers, so back-to-back audio/subtitle changes can issue overlapping PUT/DELETE requests and let an older response overwrite the newer choice. A per-key cancel/replace task or generation check would prevent stale preferences from being persisted.
🤖 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 `@iosApp/iosApp/Networking/TrackSelectionPersistence.swift` around lines 156 -
211, The fire-and-forget writers in TrackSelectionPersistence can race when
saveAudio, saveSubtitle, clearAudio, and clearSubtitle are called back-to-back
for the same prefKey, allowing an older network response to overwrite a newer
track choice. Add per-prefKey serialization in these helpers, such as tracking
the in-flight Task or a generation/token per key and canceling or ignoring stale
work before starting the next ContinuumAPI.shared request. Make the fix around
the existing saveAudio/saveSubtitle/clearAudio/clearSubtitle methods so each
prefKey only persists the latest selection.
| persistAudioSelection( | ||
| prefKey: prefKey(for: nextUpPlaybackDetail), | ||
| version: effectiveVersion(for: nextUpPlaybackDetail, versionFileId: preferredNextUpFileId), | ||
| requested: index, | ||
| sanitized: preferredNextUpAudioTrackIndex | ||
| ) | ||
| }, | ||
| onSelectNextUpSubtitleTrack: { index in | ||
| preferredNextUpSubtitleTrackIndex = sanitizedSubtitleTrackIndex( | ||
| for: nextUpPlaybackDetail, | ||
| versionFileId: preferredNextUpFileId, | ||
| candidate: index | ||
| ) | ||
| persistSubtitleSelection( | ||
| prefKey: prefKey(for: nextUpPlaybackDetail), | ||
| version: effectiveVersion(for: nextUpPlaybackDetail, versionFileId: preferredNextUpFileId), | ||
| requested: index, | ||
| sanitized: preferredNextUpSubtitleTrackIndex, | ||
| showForced: nil | ||
| ) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm whether WatchDetail carries a forced-subtitles field that could be
# threaded through ItemDetail via enrichPlaybackMetadata, or whether ItemDetail
# genuinely has no equivalent.
rg -n "effectiveShowForcedSubtitles" --type=swift -C3
rg -n "struct WatchDetail" --type=swift -A30
rg -n "struct ItemDetail" --type=swift -A40Repository: Silo-Server/silo-apple
Length of output: 160
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Relevant Swift files =="
fd -a 'TVItemDetailView.swift|ItemDetailView.swift|WatchDetail|ItemDetail' iosApp/iosApp -t f
echo
echo "== Outline tvOS detail view =="
ast-grep outline iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift --view expanded || true
echo
echo "== Outline iOS detail view =="
ast-grep outline iosApp/iosApp/Screens/Detail/ItemDetailView.swift --view expanded || true
echo
echo "== Search for forced-subtitle related identifiers =="
rg -n "showForced|forced subtitle|forcedSubtitles|effectiveShowForced" iosApp/iosApp -g '*.swift' -C 2 || trueRepository: Silo-Server/silo-apple
Length of output: 33211
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Detail view files =="
git ls-files 'iosApp/iosApp/**/Detail/*View.swift' 'iosApp/iosApp/**/Detail/**/*.swift' | sed -n '1,200p'
echo
echo "== tvOS detail view excerpts =="
rg -n "onSelectNextUpSubtitleTrack|persistSubtitleSelection|nextUpPlaybackDetail|nextUpWatchDetail|showForced" iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift -n -C 4 || true
echo
echo "== iOS detail view excerpts =="
rg -n "onSelectNextUpSubtitleTrack|persistSubtitleSelection|nextUpPlaybackDetail|nextUpWatchDetail|showForced" iosApp/iosApp/Screens/Detail/ItemDetailView.swift -n -C 4 || true
echo
echo "== model / helper excerpts =="
rg -n "func persistSubtitleSelection|struct ItemDetail|struct WatchDetail|effectiveShowForcedSubtitles|enrichPlaybackMetadata" iosApp/iosApp -g '*.swift' -C 4 || trueRepository: Silo-Server/silo-apple
Length of output: 39256
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== persistSubtitleSelection definition and callsites =="
rg -n "func persistSubtitleSelection|persistSubtitleSelection\(" iosApp/iosApp -g '*.swift' -C 5 || true
echo
echo "== subtitle selection related definitions =="
rg -n "showForced|forced subtitle|subtitleTrack" iosApp/iosApp -g '*.swift' -C 3 || trueRepository: Silo-Server/silo-apple
Length of output: 50379
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== TrackSelectionPersistence subtitle helpers =="
sed -n '1,220p' iosApp/iosApp/Networking/TrackSelectionPersistence.swift
echo
echo "== tvOS enrichPlaybackMetadata =="
sed -n '652,700p' iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift
echo
echo "== ItemDetail / WatchDetail fields around forced subtitles =="
sed -n '344,430p' iosApp/iosApp/Networking/Models.swift
echo
sed -n '974,1020p' iosApp/iosApp/Networking/Models.swiftRepository: Silo-Server/silo-apple
Length of output: 16472
Pass effectiveShowForcedSubtitles into tvOS next-up subtitle saves
showForced: nil drops the user’s forced-subtitle preference from the write, so the next-up selection can’t preserve that setting. Thread the flag through from the watch detail here to match iOS behavior.
🤖 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 `@iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift` around lines 154 -
173, The next-up subtitle save in TVItemDetailView is dropping the
forced-subtitle preference by passing a nil value. Update the
onSelectNextUpSubtitleTrack flow to thread the existing
effectiveShowForcedSubtitles value into persistSubtitleSelection, using the same
prefKey(for:), effectiveVersion(for:versionFileId:), and
sanitizedSubtitleTrackIndex path so the saved subtitle choice matches iOS
behavior.
What
Audio and subtitle selections — made on the item detail page or mid-playback — now persist to the server's per-series preference endpoints on iOS, tvOS, and macOS, so they survive exiting the player and revisiting or restarting the video. This matches the web app.
TrackSelectionPersistence(shared): pref-key resolution (episodes key by series id so one pick covers the show; movies by their own content id — the key the server's detail resolver reads movie prefs from), pure request builders, and best-effort fire-and-forgetPUT/DELETEwriters.selectAudio/selectSubtitle/disableSubtitlespersist the pick on all three platforms. Offline playback and ephemeral live-AI subtitle tracks are excluded. Signatures are built from the server's own probed metadata (currentSelectedVersion) when possible so re-resolution gets an exact match.ItemDetailView+ tvOSTVItemDetailView), including the next-up selectors on season/series pages. Semantics mirror the web: pick → modealways, Off → modeoff+ index −1, "Auto" →DELETEthe override so the library/profile cascade applies again.AudioTrack/SubtitleTracknow decodeembedded_title/hearing_impaired. The server's signature matcher comparestitleandembedded_titleseparately, so omitting them silently broke exact cross-episode track matching.PlaybackSessionBridgesendspreferredAudioTrackIndex ?? selectedVersion.effectiveAudioTrackIndex./playback/startonly consults saved audio prefs for episodes (its series-id lookup is empty for movies), so a movie's remembered audio track was otherwise dropped at session start even though the watch detail had already resolved it.Why
The read path already existed end-to-end — the server cascades per-series → per-library → profile prefs into
effective_*fields that the detail selectors andSubtitleAutoResolverconsume — but the Apple clients never wrote anything, so every explicit pick was lost on exit. Version choice needed no work: last-played version hints onwatch_progress(written server-side at stop) plus series-level traits already round-trip and are honored byDetailVersionSelectionandselectVersion.Reviewer notes
silo-server(audio_prefs.go,subtitle_prefs.go,playback.SelectAudioTrack,catalog/detail.go); the subtitle mode derivation matches the web'sderivePersistedSubtitleMode.Testing
Silo(iOS),SiloTV,SiloMacall build clean.TrackSelectionPersistenceTestspinning the request builders (index spaces, signature fields, off/auto semantics, external-subtitle path).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes