Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0af8b98
fix(settings): save subtitle appearance and timing to the profile
Rhainland Oct 13, 2026
93ff3a6
fix(player): say where the subtitle and audio delays are saved
Rhainland Oct 13, 2026
894e86a
fix(settings): keep a device value written while a profile save retries
Rhainland Oct 14, 2026
7ae94e2
fix(settings): keep subtitle device clears that a retry or later edit…
Rhainland Oct 14, 2026
404da73
fix(player): pick forced subtitles the same way on phone and TV
Rhainland Oct 13, 2026
5175f8d
fix(player): judge TV auto subtitles by the audio that will play
Rhainland Oct 13, 2026
fd095bf
fix(player): show forced subtitles when subtitles are off
Rhainland Oct 13, 2026
baf180b
feat(player): remember subtitle choices for the whole series
Rhainland Oct 13, 2026
0ef808e
fix(player): restore a remembered subtitle when the server delivers i…
Rhainland Oct 13, 2026
5f0e9ce
fix(player): keep a series subtitle pick that has not reached the ser…
Rhainland Oct 14, 2026
8ac4c2a
fix(player): keep series subtitle picks a load's flush would lose or …
Rhainland Oct 14, 2026
a74b119
fix(settings): keep a device write a gated clear replaced, and order …
Rhainland Oct 16, 2026
f812316
fix(settings): retry only the device clear when a flush is cancelled …
Rhainland Oct 16, 2026
3db57d5
fix(player): settle a series subtitle pick saved twice before it lands
Rhainland Oct 16, 2026
b7b00b2
fix(player): drop the old profile's unsent subtitle picks on a profil…
Rhainland Oct 16, 2026
eafe4ed
fix(settings): keep a held timing save off a newer device write
Rhainland Oct 17, 2026
d9e3f03
fix(player): match subtitle languages across ISO 639 forms in Auto
Rhainland Oct 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ val playerInfraModule = module {
)
}

// Manual subtitle choices remembered per series on the server. App-scoped
// so a retry outlives the player that made the choice.
single<org.siloserver.silo.common.settings.SeriesSubtitleChoiceWriter> {
val v2 = get<org.siloserver.silo.network.apiv2.SettingsV2Api>()
org.siloserver.silo.common.settings.DefaultSeriesSubtitleChoiceWriter(
put = { key, choice, owner -> v2.putSubtitlePreference(key, choice, owner) },
delete = { key, owner -> v2.deleteSubtitlePreference(key, owner) },
captureOwner = {
get<TokenManager>().snapshotCurrentScope()?.takeIf { !it.profileId.isNullOrBlank() }
},
scope = CoroutineScope(SupervisorJob() + Dispatchers.IO),
identityChanges = get<org.siloserver.silo.network.IdentityTransitionBarrier>().transitions,
)
}

// Per-profile DataStore-backed settings store with legacy SharedPreferences
// migration. We resolve the active profile on demand via ProfileRepository,
// and the current server URL via TokenManager — both of which the auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class VideoPlaybackSessionCoordinator(
preferredAudioLanguage = result.preferredAudioLanguage,
preferredTextLanguage = result.preferredTextLanguage,
preferredSubtitleMode = result.preferredSubtitleMode,
preferredSubtitleTrackSignature = result.preferredSubtitleTrackSignature,
showForcedSubtitles = result.showForcedSubtitles,
intro = result.intro,
credits = result.credits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ sealed interface VideoPlaybackStartResult {
val preferredTextLanguage: String? = null,
val preferredSubtitleMode: String? = null,
val showForcedSubtitles: Boolean = true,
/** The series' remembered subtitle track (WatchDetail `effective_subtitle_track_signature`). */
val preferredSubtitleTrackSignature: org.siloserver.silo.model.playback.SubtitleTrackSignature? = null,
val intro: TimeRange? = null,
val credits: TimeRange? = null,
val recap: TimeRange? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ sealed interface VideoPlayerUiState {
val preferredAudioLanguage: String? = null,
val preferredTextLanguage: String? = null,
val preferredSubtitleMode: String? = null,
/** The series' remembered subtitle track (WatchDetail `effective_subtitle_track_signature`). */
val preferredSubtitleTrackSignature: org.siloserver.silo.model.playback.SubtitleTrackSignature? = null,
val showForcedSubtitles: Boolean = true,
val intro: TimeRange? = null,
val credits: TimeRange? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ class AndroidPlayerSettingsStore(
}.distinctUntilChanged()
}

// Unknown revision counts as profile, as text opacity does: the flusher
// holds the write until the revision is known.
override val subtitleSyncSavedToProfileFlow: Flow<Boolean> =
if (contractRevision == null) {
subtitleUsesDeviceOverrideFlow.map { !it }
} else {
combine(subtitleUsesDeviceOverrideFlow, currentScopeFlow, contractRevision.known) { deviceOnly, scope, known ->
val revision = known?.takeIf { scope != null && it.serverUrl == scope.serverUrl }
?.manifestRevision
!deviceOnly && (revision == null || revision >= PlaybackSettingsKeys.SubtitleSyncProfileMinRevision)
}.distinctUntilChanged()
}

override suspend fun setSubtitleMatchesDevice(enabled: Boolean) =
writeBoolLocal(PlaybackSettingsKeys.SubtitleMatchesDevice, enabled)

Expand Down Expand Up @@ -511,8 +524,66 @@ class AndroidPlayerSettingsStore(
override suspend fun setAudioSyncMs(value: Int) =
writeInt(PlaybackSettingsKeys.AudioSyncMs, value.coerceIn(-5000, 5000))

override suspend fun setSubtitleSyncMs(value: Int) =
writeInt(PlaybackSettingsKeys.SubtitleSyncMs, value.coerceIn(-10000, 10000))
/**
* Subtitle timing follows the subtitle appearance's scope: the profile's
* value unless this device keeps its own subtitles ("Only on This
* Device"). A server below [PlaybackSettingsKeys.SubtitleSyncProfileMinRevision]
* only stores it per device, so there it stays a device value — decided
* here when the revision is already known and by the flusher otherwise.
*/
override suspend fun setSubtitleSyncMs(value: Int) {
val clamped = value.coerceIn(-10000, 10000)
withScope { scope, store ->
val profileUnsupported = cachedRevision(scope)
?.let { it < PlaybackSettingsKeys.SubtitleSyncProfileMinRevision } ?: false
store.edit { prefs ->
prefs[intPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.SubtitleSyncMs)] = clamped
enqueueSubtitleScoped(
prefs, scope, PlaybackSettingsKeys.SubtitleSyncMs, clamped.toString(),
minRevision = PlaybackSettingsKeys.SubtitleSyncProfileMinRevision,
deviceOnly = profileUnsupported,
)
}
}
}

/** The settings manifest revision already known for [scope]'s server, without probing. */
private fun cachedRevision(scope: Scope): Int? =
contractRevision?.known?.value?.takeIf { it.serverUrl == scope.serverUrl }?.manifestRevision

/**
* Queues a subtitle setting at the scope the "Only on This Device" toggle
* names: this device's own row while it is on (or when [deviceOnly] says
* the server cannot store it per profile), otherwise the profile's.
*
* A profile save also clears a device row this device still holds for
* [key], so the value just saved is the one that shows here rather than a
* stale device value that outranks it.
*
* Called inside the edit transaction that wrote the value, so writes
* enqueue in commit order.
*/
private fun enqueueSubtitleScoped(
prefs: androidx.datastore.preferences.core.MutablePreferences,
scope: Scope,
key: String,
value: String,
minRevision: Int = 0,
deviceOnly: Boolean = false,
) {
val usesDevice = deviceOnly || prefs.boolFor(scope, PlaybackSettingsKeys.SubtitleUsesDeviceOverride, false)
if (usesDevice) {
markDeviceOverride(prefs, scope, key)
serverSettingsFlusher.enqueue(scope.profileId, key, value, scope.serverUrl, scope.authority, SettingWriteScope.Device)
} else {
val staleDeviceRow = key in prefs[deviceOverridesKey(scope)].orEmpty()
clearDeviceOverride(prefs, scope, key)
serverSettingsFlusher.enqueue(
scope.profileId, key, value, scope.serverUrl, scope.authority,
SettingWriteScope.Profile(clearDevice = staleDeviceRow, minRevision = minRevision),
)
}
}

override suspend fun setNextUpPromptSeconds(value: Int) =
writeInt(PlaybackSettingsKeys.NextUpPromptSeconds, value.coerceIn(0, 120))
Expand Down Expand Up @@ -596,6 +667,9 @@ class AndroidPlayerSettingsStore(
// `edit` returns would let two concurrent edits enqueue in the opposite
// order to the one they committed in, and the server would keep the
// older composite.
//
// The edit starts from the appearance on screen and saves to the profile
// unless "Only on This Device" is on ([enqueueSubtitleScoped]).
override suspend fun updateSubtitleAppearance(transform: (SubtitleAppearance) -> SubtitleAppearance) {
withScope { scope, store ->
store.edit { prefs ->
Expand All @@ -608,11 +682,10 @@ class AndroidPlayerSettingsStore(
// than left behind: they are read back as an overlay, so a
// stale field would resurrect the value the user just replaced.
writeGranularAppearance(prefs, scope, sanitized)
// Setting an explicit appearance implicitly enables the
// device override (matches iOS `setSubtitleAppearance`).
prefs[booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.SubtitleUsesDeviceOverride)] = true
markDeviceOverride(prefs, scope, PlaybackSettingsKeys.SubtitleAppearance)
serverSettingsFlusher.enqueue(scope.profileId, PlaybackSettingsKeys.SubtitleAppearance, json, scope.serverUrl, scope.authority)
// An edit no longer turns on the device override: appearance
// is a profile preference, and only the explicit toggle keeps
// a device's own.
enqueueSubtitleScoped(prefs, scope, PlaybackSettingsKeys.SubtitleAppearance, json)
}
}
}
Expand All @@ -636,8 +709,7 @@ class AndroidPlayerSettingsStore(
if (prefs.stringFor(scope, PlaybackSettingsKeys.SubtitleAppearance, "") == json) return@edit
prefs[stringPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.SubtitleAppearance)] = json
prefs[stringPreferencesKey(scope.keyPrefix + SAVED_CUSTOM_SUBTITLE_APPEARANCE)] = json
markDeviceOverride(prefs, scope, PlaybackSettingsKeys.SubtitleAppearance)
serverSettingsFlusher.enqueue(scope.profileId, PlaybackSettingsKeys.SubtitleAppearance, json, scope.serverUrl, scope.authority)
enqueueSubtitleScoped(prefs, scope, PlaybackSettingsKeys.SubtitleAppearance, json)
}
}
}
Expand Down Expand Up @@ -738,18 +810,19 @@ class AndroidPlayerSettingsStore(
owner.profileToken == current?.profileToken
}

/**
* "Only on This Device". On pins the appearance on screen to this device
* (Apple parity), and later subtitle edits — appearance and timing — stay
* here. Off deletes this device's rows so the profile's values apply again.
*/
override suspend fun setSubtitleDeviceOverrideEnabled(enabled: Boolean) {
withScope { scope, store ->
val snapshot = store.data.first()
val current = snapshot.boolFor(scope, PlaybackSettingsKeys.SubtitleUsesDeviceOverride, false)
if (current == enabled) return@withScope

if (enabled) {
val appearance = SubtitleAppearance.decode(
snapshot[stringPreferencesKey(scope.keyPrefix + SAVED_CUSTOM_SUBTITLE_APPEARANCE)]
?: snapshot.stringFor(scope, PlaybackSettingsKeys.SubtitleAppearance, "")
)
val sanitized = appearance.sanitized()
val sanitized = snapshot.projectedAppearance(scope).sanitized()
val json = sanitized.toJsonString()
store.edit {
it[booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.SubtitleUsesDeviceOverride)] = true
Expand All @@ -775,6 +848,23 @@ class AndroidPlayerSettingsStore(
}
it[booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.SubtitleUsesDeviceOverride)] = false
clearDeviceOverride(it, scope, PlaybackSettingsKeys.SubtitleAppearance)
// Timing goes back to the profile's too — but only where
// the server can hold it per profile; below that revision
// this device's row is the only timing there is. An
// unknown revision queues a clear the flusher holds until
// the revision is known, so going offline cannot lose it.
// Read and queued in this transaction, so a timing edit
// made after the toggle-off is never cleared by it.
val timingOnDevice = PlaybackSettingsKeys.SubtitleSyncMs in it[deviceOverridesKey(scope)].orEmpty()
val timingDeviceOnly = cachedRevision(scope)
?.let { revision -> revision < PlaybackSettingsKeys.SubtitleSyncProfileMinRevision } ?: false
if (timingOnDevice && !timingDeviceOnly) {
clearDeviceOverride(it, scope, PlaybackSettingsKeys.SubtitleSyncMs)
serverSettingsFlusher.enqueueDelete(
scope.profileId, PlaybackSettingsKeys.SubtitleSyncMs, scope.serverUrl, scope.authority,
minRevision = PlaybackSettingsKeys.SubtitleSyncProfileMinRevision,
)
}
}
serverSettingsFlusher.enqueueDelete(scope.profileId, PlaybackSettingsKeys.SubtitleAppearance, scope.serverUrl, scope.authority)
serverSettingsFlusher.flushNow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,20 @@ interface PlayerSettingsStore {
get() = subtitleAppearanceFlow

/**
* Whether the user has enabled a device-scoped subtitle-appearance
* override (mirrors iOS `subtitleUsesDeviceAppearanceOverride`).
* When false, the effective subtitle appearance comes from the
* user-level setting; when true, the local override is in effect.
* "Only on This Device" for subtitles (mirrors iOS
* `subtitleUsesDeviceAppearanceOverride`). When false, subtitle appearance
* and timing edits save to the profile and apply on every device; when
* true, they are saved for this device only.
*/
val subtitleUsesDeviceOverrideFlow: Flow<Boolean>

/**
* Whether a subtitle delay set now is saved for the profile on every
* device (false: on this device only — the toggle is on, or the server
* stores timing per device only).
*/
val subtitleSyncSavedToProfileFlow: Flow<Boolean>
get() = subtitleUsesDeviceOverrideFlow.map { !it }
/** tvOS "Match Device Settings": appearance follows OS captioning prefs. */
val subtitleMatchesDeviceFlow: Flow<Boolean>
/** iOS AppNavPreferences.showAudiobooks parity — audiobook surfaces are opt-in. */
Expand Down Expand Up @@ -244,11 +252,11 @@ interface PlayerSettingsStore {
suspend fun refreshFromServer()

/**
* Toggle the device-level override for `subtitle_appearance`. When
* `enabled` is false, deletes the device override on the server and
* refetches the effective appearance from the user-level setting.
* When true, pushes the current local appearance up as a device
* override.
* Toggle "Only on This Device" for subtitles. When `enabled` is false,
* deletes this device's subtitle appearance (and, where the server stores
* timing per profile, its timing) and refetches the profile's values.
* When true, pins the appearance on screen to this device; later edits
* stay on this device.
*/
suspend fun setSubtitleDeviceOverrideEnabled(enabled: Boolean)
suspend fun setSubtitleMatchesDevice(enabled: Boolean)
Expand Down
Loading