Skip to content

Honor complete Apple subtitle preferences - #124

Merged
Quick104 merged 8 commits into
mainfrom
codex/complete-system-subtitle-settings
Aug 6, 2026
Merged

Quick104 merged 8 commits into
mainfrom
codex/complete-system-subtitle-settings

Conversation

@Quick104

@Quick104 Quick104 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make Use Device Settings control subtitle selection as well as appearance
  • honor Apple's ordered caption languages, Forced Only / Automatic / Always On display modes, and CC/SDH media-characteristic preference
  • map the remaining visual preferences: foreground opacity, exact relative size, all edge styles, and the separate rounded caption window
  • keep Apple-only detail runtime-local so the server subtitle appearance contract and other clients do not change
  • refresh selection and appearance when MediaAccessibility reports a settings change, while preserving a manual in-player track choice
  • respect Apple's per-category Video Overrides Style precedence for authored ASS content

Root cause

The existing bridge only mapped a subset of MediaAccessibility into Silo's persistent appearance model. It quantized the system font scale, omitted foreground opacity and window radius, collapsed Apple's glyph background and caption window into one layer, and treated raised/depressed/uniform edges as the same outline.

The toggle also never participated in subtitle track selection, so Apple's language order, display mode, and CC/SDH preference were ignored in favor of the Silo profile settings.

User impact

When Use Device Settings is enabled, iPhone and Apple TV users now get one coherent system-driven experience: track choice, font, color, alpha, scale, edge, glyph background, caption window, and authored-style precedence all follow the active Apple accessibility profile. The Silo profile controls are disabled while the system source is active so the UI reflects the actual source of truth.

Validation

  • rebased onto main at 671d4f1
  • focused iOS simulator tests: 43 passed, 0 failed
    • system appearance mapping
    • renderer parameter mapping and server-encoding isolation
    • ordered language fallback, CC/SDH preference, and forced-only selection
  • normally signed iOS simulator build and launch succeeded; authenticated Settings UI visually confirmed system-driven preview and disabled Silo profile/appearance controls
  • normally signed tvOS 26.4 simulator build and launch succeeded after the rebase
  • read the active tvOS MediaAccessibility profile without modifying it and confirmed the signed app preview matches its green foreground, 1.75x scale, transparent glyph background, 50% magenta window, and 8-point rounded corners

Summary by CodeRabbit

  • New Features

    • Improved automatic subtitle selection with language fallbacks, forced-subtitle mode, accessibility-track preference, and configurable no-match behavior.
    • Added broader support for device caption settings, including opacity, font scaling, caption windows, colors, corner radius, and text-edge styles.
    • Subtitle previews and playback rendering now better reflect system caption appearance.
  • Improvements

    • “Use Device Settings” wording clarifies how Accessibility preferences control subtitle appearance.
    • Profile appearance controls are disabled when device settings are active.
    • Manual subtitle selections are preserved without automatic reselection.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2eb11eab-a8a7-4f66-9d9b-14c5e30c8189

📥 Commits

Reviewing files that changed from the base of the PR and between c9b1251 and cbe5a04.

📒 Files selected for processing (4)
  • iosApp/Tests/SubtitleAutoResolverTests.swift
  • iosApp/iosApp/Screens/Detail/ItemDetailView.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift
📝 Walkthrough

Walkthrough

The PR adds system-driven subtitle language selection and playback state handling. It also maps caption appearance settings into runtime styling, native overrides, previews, and layered rendering. Settings screens now describe and enforce device Accessibility control.

Changes

Subtitle preferences and playback integration

Layer / File(s) Summary
System subtitle selection
iosApp/iosApp/Screens/Player/..., iosApp/iosApp/Screens/Detail/..., iosApp/Tests/SubtitleAutoResolverTests.swift, iosApp/Tests/DetailVersionSelectionTests.swift
System preferences now support ordered languages, forced-only selection, accessibility tracks, no-match behavior, and explicit-choice preservation across playback transitions.
Launch and tvOS selection behavior
iosApp/iosApp/Screens/Detail/..., iosApp/iosApp/tvOS/Screens/Detail/..., iosApp/iosApp/tvOS/Screens/Settings/...
Launch selection ignores server subtitle seeds when device settings control subtitles. Manual selections prevent automatic reseeding, and tvOS focus targets the device-settings row when applicable.

Caption appearance and rendering

Layer / File(s) Summary
Caption appearance mapping
iosApp/iosApp/Screens/Player/Subtitles/SubtitleAppearance.swift, iosApp/iosApp/Screens/Player/Subtitles/SystemCaptionAppearance.swift, iosApp/Tests/SystemCaptionAppearanceTests.swift
Runtime appearance state now carries independent glyph and caption-window properties, opacity, scale, edge styles, corner radius, and content overrides.
Styling and compositing
iosApp/iosApp/Screens/Player/Subtitles/SubtitleStylingOverride.swift, iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift, iosApp/iosApp/Screens/Player/Subtitles/SubtitleAppearancePreview.swift, iosApp/Tests/SubtitleStylingOverrideTests.swift
ASS, native-track, preview, and live rendering now apply selective system styling, grouped bounds, caption windows, glyph backgrounds, edge layers, alpha, and rounded masks.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: zzebrahz

Sequence Diagram(s)

sequenceDiagram
  participant SystemCaptionSelectionPreferences
  participant PlayerSettings
  participant PlayerViewModel
  participant PlaybackPrefsResolver
  SystemCaptionSelectionPreferences->>PlayerSettings: Read current caption selection
  PlayerSettings->>PlayerViewModel: Refresh system preferences
  PlayerViewModel->>PlaybackPrefsResolver: Resolve ordered subtitle preferences
  PlaybackPrefsResolver-->>PlayerViewModel: Apply selected, disabled, or unchanged state
Loading
sequenceDiagram
  participant SystemCaptionAppearance
  participant SubtitleStylingOverride
  participant SubtitleRenderer
  SystemCaptionAppearance->>SubtitleStylingOverride: Convert caption appearance
  SubtitleStylingOverride->>SubtitleRenderer: Apply styling and compositing overrides
  SubtitleRenderer-->>SubtitleStylingOverride: Render grouped caption regions
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 primary change: applying complete Apple subtitle preferences across subtitle selection and appearance.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/complete-system-subtitle-settings

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

@Quick104
Quick104 marked this pull request as ready for review August 6, 2026 15:40

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f8725e454

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

behavior: behavior
)
}
if behavior == .useValue { result.contentOverrides.insert(.colors) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve per-property color override precedence

When a native ASS track is shown and only one Apple color property has “Video Overrides Style” disabled—for example, foreground color is .useValue while background color remains .useContentIfAvailable—this single .colors flag causes SubtitleStylingOverride.apply to enable ASS_OVERRIDE_BIT_COLORS, replacing the track’s primary, outline, and background colors together. Consequently, authored values are lost for color properties whose individual Apple preference explicitly allows content to override them; retain precedence separately for each color/opacity property rather than promoting any one property to a category-wide override.

Useful? React with 👍 / 👎.

Comment on lines +649 to +650
let primaryBounds = paintedBounds(imgPrimary)
let secondaryBounds = paintedBounds(imgSecondary)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Draw caption windows per simultaneous cue

When a subtitle slot contains two simultaneous events at different positions, paintedBounds unions every libass image in the slot and the renderer draws one window around that union. This produces a large rectangle spanning the empty area between independent cues—especially common with ASS dialogue plus positioned signs—instead of a separate caption window behind each cue. The window bounds need to preserve event/cue grouping rather than collapsing the entire rendered slot into one rectangle.

Useful? React with 👍 / 👎.

Comment on lines +105 to +109
var assShadow: Double {
backgroundStyle == .shadow ? 1.5 : boxPadding
if systemTextEdgeStyle == .dropShadow { return 1.5 }
if systemTextEdgeStyle == .raised { return 1.0 }
if systemTextEdgeStyle == .depressed { return -1.0 }
return backgroundStyle == .shadow ? 1.5 : boxPadding

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Render drop shadows independently from glyph backgrounds

When the Apple profile combines a nonzero glyph background with the drop-shadow edge style, boxEnabled selects ASS BorderStyle 4 while this branch supplies 1.5 as Shadow. As the comments above assBorderStyle and boxPadding note, libass interprets Shadow as box padding under BorderStyle 4, so the requested drop shadow is not rendered even though the preview shows the background and shadow together. The system edge needs a separate rendering path when a glyph background box is also enabled.

Useful? React with 👍 / 👎.

Comment on lines +113 to +117
if let forced = bestLanguageMatch(
nil,
in: inputs.availableSubtitles.filter(\.isForced),
preferForced: true,
preferAccessibility: inputs.preferAccessibilityTracks

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid selecting forced tracks in unrequested languages

When Forced Only is enabled and no forced track matches any Apple preferred language, this fallback calls bestLanguageMatch(nil, ...) and therefore selects the first forced track in an arbitrary language. For example, an English-only caption profile will enable a French forced track rather than disabling captions, despite the new language stack being the declared source of truth. Limit the fallback to a meaningful match such as the current audio language, or disable subtitles when none of the requested caption languages is available.

Useful? React with 👍 / 👎.

Comment on lines +125 to +126
case .outline, .none:
return 0xFF
return systemTextEdgeStyle == .dropShadow ? 0x80 : 0xFF

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make raised and depressed edges visible in playback

When Apple's edge style is Raised or Depressed and there is no glyph background box, assShadow supplies a nonzero directional shadow but this alpha calculation leaves BackColour fully transparent because it only recognizes .dropShadow. Libass uses BackColour for the shadow, so the directional component disappears and both styles render as the same uniform outline, unlike the distinct preview. Supply an appropriate visible shadow color/alpha for raised and depressed edges.

Useful? React with 👍 / 👎.

Comment on lines +172 to +176
for language in preferredLanguages {
if let pick = bestLanguageMatch(
language,
in: inputs.availableSubtitles,
preferForced: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear server-selected subtitles when system languages miss

When playback starts with a server-profile subtitle already selected but Use Device Settings specifies languages for which no track exists, this new language loop exhausts its candidates and the resolver eventually returns .noChange. applyAutoSubtitle then leaves the server-selected track active—for example, an English subtitle remains visible under a Spanish-only device profile—even though the UI disables the server preference controls and says selection follows Apple settings. Once an explicit system language stack has no acceptable match, disable the existing selection or apply a documented system fallback instead of preserving the server choice.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0eb8015be9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1222 to +1223
} else if img.type == IMAGE_TYPE_SHADOW {
if let backgroundColorOverride {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Create native ASS backgrounds instead of only recoloring shadows

When a native ASS cue has no authored shadow or box and Apple marks background color or opacity as .useValue, this branch has no IMAGE_TYPE_SHADOW bitmap to modify, while SubtitleStylingOverride.apply enables the border override only for .edge. The requested glyph background therefore remains completely absent; authored drop shadows can also be mistaken for backgrounds because they share this image type. Synthesize the system background or make libass emit an appropriate box whenever either background property overrides content.

Useful? React with 👍 / 👎.

Comment on lines +7438 to +7440
forcedOnly: true,
preferAccessibilityTracks: system.prefersAccessibilityTracks,
disableWhenNoLanguageMatch: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Route forced sidecars through the system language policy

When Forced Only is active and no embedded forced track matches the device languages, a later forced sidecar bypasses this restricted resolver: appendSidecarTracks selects the first forced descriptor at lines 7280–7285 and returns. Thus an English-only device profile can still enable a French forced sidecar despite disableWhenNoLanguageMatch; skip that unconditional fallback in device-settings mode or resolve sidecars through the same ordered language policy.

Useful? React with 👍 / 👎.

mode: prefs.mode,
showForced: prefs.showForced,
forcedOnly: prefs.forcedOnly,
preferAccessibilityTracks: prefs.preferAccessibilityTracks,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-resolve when preferred sidecar tracks arrive

When embedded tracks are reported before sidecars, this preference can initially select a plain embedded subtitle and set prefsResolvedForCurrentItem. If an SDH/CC sidecar—or a track in an earlier preferred language—arrives afterward, appendSidecarTracks calls the resolver with forceWhenNoSelection: true, but the existing selection makes the guard at line 7401 return before this preference is considered. Re-run system resolution when the available track set expands unless hasExplicitSubtitleChoice is set.

Useful? React with 👍 / 👎.

Comment on lines +714 to +715
!handle.isNativeASS
|| !currentParams.systemContentOverrides.intersection(.window).isEmpty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve per-property precedence for native caption windows

Although the native color overrides are now split per property, this guard still collapses all three window behaviors: if only window corner radius is .useValue, for example, a native ASS cue also receives the device window color and opacity even when those properties are .useContentIfAvailable. Check the individual window override bits when deciding whether to create and style the compositor window so one forced property does not promote the entire window category.

Useful? React with 👍 / 👎.

guard let self, self.settings.subtitleMatchesSystemAppearance else { return }
self.settings.refreshSubtitleSystemAppearance()
self.applySubtitleAppearanceToPlayer()
guard !self.hasExplicitSubtitleChoice else { return }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve automatic selections across route recovery

When a system-selected subtitle is active and playback falls back to another route or rebuilds for a quality change, the recovery paths infer hasExplicitSubtitleChoice = true merely because a subtitle snapshot exists at lines 2190–2192 and 4948–4951. After that, this guard treats the automatic choice as manual and ignores later MediaAccessibility language or display-mode changes. Preserve the pre-recovery explicit-choice flag instead of deriving it from the presence of any selected track.

Useful? React with 👍 / 👎.

disableWhenNoLanguageMatch: prefs.disableWhenNoLanguageMatch,
trackSignature: prefs.trackSignature,
availableSubtitles: allSubs,
currentAudioLanguage: audioLang

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-resolve automatic captions after audio-track changes

The system Automatic decision depends on this current audio language, but selectAudioTrack never invalidates prefsResolvedForCurrentItem or invokes the subtitle resolver. For example, starting with preferred English audio can disable full captions, then manually switching to Japanese audio leaves them disabled instead of selecting the preferred English subtitle. Re-run the system subtitle policy after a successful audio selection unless the user made an explicit subtitle choice.

Useful? React with 👍 / 👎.

Comment on lines +111 to +112
if systemTextEdgeStyle == .raised { return 1.0 }
if systemTextEdgeStyle == .depressed { return -1.0 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match raised and depressed shadow directions to the preview

Fresh evidence after the prior visibility fix is that the no-box playback offsets are reversed: positive ASS shadow moves down/right for .raised and negative moves up/left for .depressed, while both the preview and the new compositor path use raised up/left and depressed down/right. Consequently, adding or removing the glyph background flips the emboss direction for the same Apple edge setting; swap these signs so both rendering paths agree.

Useful? React with 👍 / 👎.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift (1)

245-250: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prefer an exact language-tag match before a primary-subtag fallback.

Line 249 places pt-PT and pt-BR in the same pool. If the Brazilian track appears first, it can be selected for a Portuguese-from-Portugal preference.

First filter for a case-insensitive exact tag match. Only use languagesMatch when no exact match exists. Add a test with pt-BR listed before pt-PT.

Proposed fix
         let pool: [PlayerTrack]
         if let lang = language {
-            pool = tracks.filter {
+            let exactMatches = tracks.filter {
+                $0.lang?.caseInsensitiveCompare(lang) == .orderedSame
+            }
+            pool = exactMatches.isEmpty ? tracks.filter {
                 guard let trackLang = $0.lang else { return false }
                 return languagesMatch(trackLang, lang)
-            }
+            } : exactMatches
         } else {
             pool = tracks
         }
🤖 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/Player/PlaybackPrefsResolver.swift` around lines 245 -
250, Update the language-based pool selection in the playback preference
resolver to first filter tracks whose language tags exactly match the requested
language case-insensitively. Only fall back to the existing languagesMatch
primary-subtag logic when that exact-match pool is empty, and add coverage with
pt-BR ordered before pt-PT to verify pt-PT is selected.
iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift (1)

117-134: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Keep .top on a stable focus owner.

When subtitleMatchesSystemAppearance changes, .top moves between the Language row and “Use Device Settings”. The current focus target can then become invalid. Keep .focused(detailFocus, equals: .top) outside the conditional branches, or restore detailFocus after the update. Apply the same correction to the Language row.

🤖 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/Settings/TVSubtitleSettingsView.swift` around
lines 117 - 134, Keep the .top focus modifier attached to a stable view outside
the conditional branches for both the Language row and the “Use Device Settings”
row in TVSubtitleSettingsView, so changing subtitleMatchesSystemAppearance does
not invalidate the active focus target. Preserve the existing toggle behavior
and ensure detailFocus remains associated with the same focus owner across state
updates.

Source: Coding guidelines

🧹 Nitpick comments (2)
iosApp/Tests/SystemCaptionAppearanceTests.swift (1)

27-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rename testWindowOpacityMapsToBox to match its assertions.

The test no longer asserts a box background. It asserts caption-window opacity, color, and corner radius. The current name describes the removed behavior.

♻️ Proposed rename
-    func testWindowOpacityMapsToBox() {
+    func testWindowPropertiesMapToCaptionWindow() {
🤖 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/Tests/SystemCaptionAppearanceTests.swift` around lines 27 - 37, Rename
the test method testWindowOpacityMapsToBox to reflect that it verifies
caption-window opacity, color, and corner-radius mapping, while leaving its
assertions and implementation unchanged.
iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift (1)

712-716: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use isDisjoint(with:) for the window override check.

SwiftLint reports the intersection(_:).isEmpty pattern here. isDisjoint(with:) states the intent directly and avoids building an intermediate option set.

♻️ Proposed change
             guard currentParams.captionWindowEnabled,
                   let handle,
                   !handle.isNativeASS
-                    || !currentParams.systemContentOverrides.intersection(.window).isEmpty
+                    || !currentParams.systemContentOverrides.isDisjoint(with: .window)
                     else { return [] }
🤖 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/Player/Subtitles/SubtitleRenderer.swift` around lines
712 - 716, Update the window override condition in the subtitle renderer’s guard
to use isDisjoint(with:) instead of intersection(.window).isEmpty, preserving
the existing logic that allows native ASS handles when systemContentOverrides
overlaps the window option.

Source: Linters/SAST tools

🤖 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/Screens/Player/Subtitles/SubtitleStylingOverride.swift`:
- Around line 105-114: Update assShadow in SubtitleStylingOverride to avoid
relying on a negative ASS Style.Shadow value for .depressed when generating
synthetic headers. Route the depressed direction through \xshad/\yshad overrides
or the existing compositor path, while preserving the current box, dropShadow,
raised, and default behavior.

---

Outside diff comments:
In `@iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift`:
- Around line 245-250: Update the language-based pool selection in the playback
preference resolver to first filter tracks whose language tags exactly match the
requested language case-insensitively. Only fall back to the existing
languagesMatch primary-subtag logic when that exact-match pool is empty, and add
coverage with pt-BR ordered before pt-PT to verify pt-PT is selected.

In `@iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift`:
- Around line 117-134: Keep the .top focus modifier attached to a stable view
outside the conditional branches for both the Language row and the “Use Device
Settings” row in TVSubtitleSettingsView, so changing
subtitleMatchesSystemAppearance does not invalidate the active focus target.
Preserve the existing toggle behavior and ensure detailFocus remains associated
with the same focus owner across state updates.

---

Nitpick comments:
In `@iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift`:
- Around line 712-716: Update the window override condition in the subtitle
renderer’s guard to use isDisjoint(with:) instead of
intersection(.window).isEmpty, preserving the existing logic that allows native
ASS handles when systemContentOverrides overlaps the window option.

In `@iosApp/Tests/SystemCaptionAppearanceTests.swift`:
- Around line 27-37: Rename the test method testWindowOpacityMapsToBox to
reflect that it verifies caption-window opacity, color, and corner-radius
mapping, while leaving its assertions and implementation unchanged.
🪄 Autofix

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: 67866d57-3205-423d-bb54-82138cc1f31e

📥 Commits

Reviewing files that changed from the base of the PR and between 671d4f1 and 0eb8015.

📒 Files selected for processing (16)
  • iosApp/Tests/SubtitleAutoResolverTests.swift
  • iosApp/Tests/SubtitleStylingOverrideTests.swift
  • iosApp/Tests/SystemCaptionAppearanceTests.swift
  • iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift
  • iosApp/iosApp/Screens/Player/PlayerSettings.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Sheets/PlayerSettingsSheet.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleAppearance.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleAppearancePreview.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleStylingOverride.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SystemCaptionAppearance.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SystemCaptionSelectionPreferences.swift
  • iosApp/iosApp/Screens/Player/tvOS/TVPlayerInfoHUD.swift
  • iosApp/iosApp/Screens/Settings/SubtitleSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0647b0de75

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +892 to +896
canvas.draw(
imageList: imageList,
offsetX: frameOffsetX,
offsetY: frameOffsetY,
characterColorOverride: characterColor,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Suppress authored boxes when overriding native backgrounds

Fresh evidence after the prior native-background fix is that, when a native ASS cue already contains an authored box and Apple forces a different background color or opacity, the synthesized system rectangle is painted first but this call then composites the complete libass image list—including the authored non-character box—over it. An opaque authored box therefore continues to determine the visible color and opacity; filter or replace the authored background layer whenever the system background override is active.

Useful? React with 👍 / 👎.

Comment on lines +437 to +438
if params.systemContentOverrides.contains(.edge) {
systemBits |= Int32(ASS_OVERRIDE_BIT_BORDER.rawValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep edge overrides from forcing the fallback background

When a native ASS track has only the Apple edge option set to .useValue while background opacity remains .useContentIfAvailable, the mapped fallback background can still make boxEnabled true. Enabling this border bit then applies the override style's BorderStyle = 4, so changing the edge also replaces the authored border style with a glyph box even though the background preference explicitly yields to content. Apply the forced edge independently instead of passing the combined edge/background style through the atomic border override.

Useful? React with 👍 / 👎.

Comment on lines +39 to +41
let selectedLanguages = MACaptionAppearanceCopySelectedLanguages(.user)
.takeRetainedValue() as? [String] ?? []
let languages = selectedLanguages.isEmpty ? Locale.preferredLanguages : selectedLanguages

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Canonicalize all system caption languages

Apple's selected and locale language lists are not limited to the twelve languages covered by SubtitleAutoResolver.isoEquivalent, so valid two-letter/three-letter pairs outside that table never match. For example, a device preference of nl-NL and a subtitle track tagged nld are treated as a language miss and device-settings mode disables captions despite the languages being equivalent. Canonicalize these arbitrary system identifiers with a complete ISO mapping before passing them to the resolver.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12b74e8922

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 3407 to +3410
if !self.hasExplicitSubtitleChoice {
let modeRaw = prepared.watchDetail.effectiveSubtitleMode ?? ""
self.prefsForCurrentItem = PrefsSnapshot(
preferredLanguage: prepared.watchDetail.effectiveSubtitleLanguage,
mode: SubtitleMode(rawValue: modeRaw),
showForced: prepared.watchDetail.effectiveShowForcedSubtitles ?? false,
trackSignature: prepared.watchDetail.effectiveSubtitleTrackSignature
)
self.prefsForCurrentItem = self.settings.subtitleMatchesSystemAppearance
? self.systemCaptionPrefsSnapshot()
: self.serverSubtitlePrefsSnapshot(prepared.watchDetail)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Let device policy replace server-seeded launch picks

When Use Device Settings is enabled and the detail screen seeds preferredSubtitleTrackIndex from a remembered server signature or server mode .off (ItemDetailView.seedSubtitleOverrideIfNeeded), resetPublishedLoadState marks that index as an explicit user choice. This guard then skips creating the system caption snapshot entirely, so the pending server track or Off sentinel wins and Apple's language/display policy never runs. This remains fresh evidence after the no-language-match resolver fix because the resolver is not reached on this launch path; distinguish genuinely manual route choices from server-seeded indices, or ignore the latter in device-settings mode.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9852f04c89

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +669 to +673
preferredSubtitleTrackIndex = DetailPlaybackFormatting.launchPreferredSubtitleIndex(
version: effectiveVersion(for: detail, versionFileId: preferredVersionFileId),
signature: detail.effectiveSubtitleTrackSignature,
mode: detail.effectiveSubtitleMode
mode: detail.effectiveSubtitleMode,
usesDeviceSettings: PlayerSettings.shared.subtitleMatchesSystemAppearance

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear cached subtitle seeds when enabling device settings

When a tvOS detail was first opened with device settings disabled, the server-derived subtitle index remains in the cached detail view model; after enabling Use Device Settings and returning to the same item, .task(id:) does not rerun and this guard prevents recalculating the launch value. Playback therefore still forwards that stale index as an explicit choice and skips Apple's caption policy. Fresh evidence after the launch-seed fix is that TVItemDetailView deliberately persists this selection in ItemDetailCache, while its onAppear does not clear or reseed it; invalidate server-seeded values when the device-settings flag changes while preserving genuinely manual selector choices.

Useful? React with 👍 / 👎.

Comment on lines +252 to +257
pool = exactMatches.isEmpty
? tracks.filter {
guard let trackLang = $0.lang else { return false }
return languagesMatch(trackLang, lang)
}
: exactMatches

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prefer full-dialogue tracks before exact forced matches

When the preferred locale has an exact forced track but the only full-dialogue track uses a generic or sibling regional tag, this exact-match pool discards the full track before forced/full-dialogue ranking runs. For example, a pt-PT forced track plus a non-forced pt track causes Always On—or Automatic with foreign audio—to select the signs-only track, contradicting the resolver's invariant that forced subtitles must not steal a full-dialogue pick. Rank forced/accessibility status first among all primary-language matches, using regional exactness only to break ties within the same track class.

Useful? React with 👍 / 👎.

Comment on lines +3408 to +3410
self.prefsForCurrentItem = self.settings.subtitleMatchesSystemAppearance
? self.systemCaptionPrefsSnapshot()
: self.serverSubtitlePrefsSnapshot(prepared.watchDetail)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Order the subtitle picker by the active device languages

When Use Device Settings is enabled and Apple's first caption language differs from the server profile language, this branch resolves and selects using the system snapshot but leaves subtitleOrderingLanguage set to prepared.watchDetail.effectiveSubtitleLanguage. The two in-player subtitle pickers therefore continue floating the disabled server language to the top instead of the active Apple language; settings-change notifications also replace the resolver snapshot without updating this ordering value. Set the display ordering from the system language stack whenever device policy is active, and refresh it alongside that snapshot.

Useful? React with 👍 / 👎.

Comment on lines +284 to +286
for language in [first] + inputs.additionalPreferredLanguages where !language.isEmpty {
if !result.contains(where: { languagesMatch($0, language) }) {
result.append(language)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve regional entries in Apple's language order

When Apple's ordered caption languages contain multiple variants of the same primary language, this deduplication treats them as identical and removes every variant after the first. Moreover, the first variant's primary-subtag fallback can select an arbitrary sibling before a later exact preference is considered; for example, [pt-BR, pt-PT] with source-ordered tracks [pt-AO, pt-PT] selects pt-AO. Deduplicate only identical normalized identifiers and exhaust exact matches across the ordered stack before falling back to primary-language equivalence.

Useful? React with 👍 / 👎.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift (1)

96-98: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Apply the empty-track result in PlayerViewModel.

Lines 96-98 return .disable for device settings with no subtitle tracks. PlayerViewModel.applyAutoSubtitlePreferencesIfNeeded returns before it calls resolve when subtitleTracks is empty. The player cannot clear an automatic subtitle selection in this case.

Remove the empty-track guard or call resolve with the empty list. Preserve manual selections through the existing hasExplicitSubtitleChoice guard.

Proposed consumer change
 let allSubs = subtitleTracks
-guard !allSubs.isEmpty else { return }

 let audioLang = audioTracks
🤖 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/Player/PlaybackPrefsResolver.swift` around lines 96 -
98, Update PlayerViewModel.applyAutoSubtitlePreferencesIfNeeded so empty
subtitleTracks still reaches PlaybackPrefsResolver.resolve and applies the
.disable result. Remove the early return for empty tracks while preserving the
existing hasExplicitSubtitleChoice guard so manual selections remain unchanged.
🧹 Nitpick comments (1)
iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift (1)

579-602: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Cache the solid-mask classification per frame.

isSolidBackgroundMask scans the whole bitmap when the mask is solid. Solid background bitmaps are the largest ones in a cue. The classification runs repeatedly for the same image in one render: paintedRects is called for primary, secondary, characters-only, and again inside shadowBounds; hasAuthoredGlyphBackground walks both lists; CompositorCanvas.draw classifies every image once per draw pass, and the uniform edge style adds eight extra passes.

At 4K this repeats a full-area scan of the box bitmap more than ten times per composited frame, on the path this file already documents as the dominant render cost. Classify each image once per frame and reuse the result, for example by collecting the background image pointers in a Set<UnsafePointer<UInt8>> before grouping and drawing, then passing that set into paintedRects and draw.

🤖 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/Player/Subtitles/SubtitleRenderer.swift` around lines
579 - 602, Cache each image’s solid-background classification once per render
frame instead of rescanning it in every consumer. Update the subtitle rendering
flow around paintedRects, hasAuthoredGlyphBackground, shadowBounds, and
CompositorCanvas.draw to collect background image pointers in a per-frame Set
and pass or reuse that classification through grouping and all draw passes,
including uniform edge-style passes.
🤖 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/Screens/Detail/ItemDetailView.swift`:
- Around line 764-768: Update the iOS subtitle-selection flow around
preferredSubtitleTrackIndex and
DetailPlaybackFormatting.launchPreferredSubtitleIndex so active device settings
clear only existing non-manual server seeds before the guard can return.
Preserve manual selector choices by marking iOS selections as manual, and mirror
the tvOS behavior so Apple preferences handle selection when no manual choice
exists.

---

Outside diff comments:
In `@iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift`:
- Around line 96-98: Update PlayerViewModel.applyAutoSubtitlePreferencesIfNeeded
so empty subtitleTracks still reaches PlaybackPrefsResolver.resolve and applies
the .disable result. Remove the early return for empty tracks while preserving
the existing hasExplicitSubtitleChoice guard so manual selections remain
unchanged.

---

Nitpick comments:
In `@iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift`:
- Around line 579-602: Cache each image’s solid-background classification once
per render frame instead of rescanning it in every consumer. Update the subtitle
rendering flow around paintedRects, hasAuthoredGlyphBackground, shadowBounds,
and CompositorCanvas.draw to collect background image pointers in a per-frame
Set and pass or reuse that classification through grouping and all draw passes,
including uniform edge-style passes.
🪄 Autofix

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: 3bbdfdc1-40f7-4236-83eb-3fd551040c9d

📥 Commits

Reviewing files that changed from the base of the PR and between 0eb8015 and c9b1251.

📒 Files selected for processing (14)
  • iosApp/Tests/DetailVersionSelectionTests.swift
  • iosApp/Tests/SubtitleAutoResolverTests.swift
  • iosApp/Tests/SubtitleStylingOverrideTests.swift
  • iosApp/Tests/SystemCaptionAppearanceTests.swift
  • iosApp/iosApp/Screens/Detail/DetailPlaybackFormatting.swift
  • iosApp/iosApp/Screens/Detail/ItemDetailView.swift
  • iosApp/iosApp/Screens/Detail/ItemDetailViewModel.swift
  • iosApp/iosApp/Screens/Player/PlaybackPrefsResolver.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleRenderer.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleStylingOverride.swift
  • iosApp/iosApp/tvOS/Screens/Detail/TVItemDetailView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift
🚧 Files skipped from review as they are similar to previous changes (4)
  • iosApp/Tests/SystemCaptionAppearanceTests.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift
  • iosApp/iosApp/Screens/Player/Subtitles/SubtitleStylingOverride.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbe5a0495a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +726 to +727
if Self.isGlyphBackgroundImage(image), let bitmap = image.bitmap {
glyphBackgroundBitmaps.insert(UInt(bitPattern: UnsafeRawPointer(bitmap)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not identify ASS backgrounds solely by solid masks

When native ASS contains an opaque rectangular \p drawing or another character image whose cropped mask is entirely 0xFF, this classifies that foreground bitmap as a BorderStyle 4 background. Its pointer is then excluded from character-only edge/color passes, can be recolored by the Apple background preference, and makes hasAuthoredGlyphBackground suppress synthesized backgrounds for other cues in the slot. Use image/style context in addition to mask solidity so solid authored drawings remain foreground content.

Useful? React with 👍 / 👎.

Comment on lines +750 to +753
let isCharacter = !isGlyphBackground(img)
&& img.type == IMAGE_TYPE_CHARACTER
if (!charactersOnly || isCharacter),
img.w > 0, img.h > 0, img.bitmap != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve cue fades when synthesizing caption backgrounds

When a native ASS cue uses \fad, \fade, or an animated alpha and Apple forces a caption window or glyph background, paintedRects includes the image even when its rendered color is fully transparent, while the synthesized rectangle is drawn later at the fixed system opacity. The result is a visible empty box before the text fades in and after it fades out. Filter transparent render images or propagate each cue's current effective alpha into the synthesized window/background.

Useful? React with 👍 / 👎.

@Quick104
Quick104 merged commit 682530b into main Aug 6, 2026
1 check passed
@Quick104
Quick104 deleted the codex/complete-system-subtitle-settings branch August 6, 2026 18:10
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.

1 participant