Skip to content

Commit 9cc3091

Browse files
authored
fix(settings): save subtitle appearance and timing to the profile (#2451)
Subtitle appearance and the subtitle offset now save for the profile and follow it to every device; a device can still keep its own value, which wins there. Settings manifest revision 19 adds the profile scope to player.subtitle_sync_ms. The web settings page and player apply the profile offset, and the Language & Subtitles page says where values are saved.
1 parent 01e01b0 commit 9cc3091

22 files changed

Lines changed: 875 additions & 177 deletions

‎contracts/settings/v1/conformance.json‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"fixture_version": 1,
3-
"manifest_revision": 18,
3+
"manifest_revision": 19,
44
"description": "Cross-platform conformance cases for settings resolution. Every case runs against the shipped manifest in this directory: definitions are referenced by key, never restated, so an expectation can only be satisfied by resolving the real contract. Each platform's resolver (Go in internal/settingsresolve, TypeScript in web/src/lib/settingsResolve.ts, Kotlin and Swift in the client repos) runs every case through a hand-written runner; a runner must fail on any fixture field it does not know, because schema drift in the fixture itself is drift. A case's constraint_bindings attach a constraint to a copy of a real definition so constraint semantics stay testable even while no shipped definition carries that constraint kind. In expected entries, constrained:true requires stored_value and constraint_kind to be present, and stored_value may be null to mean the authored value was JSON null.",
55
"cases": [
66
{
@@ -1087,6 +1087,25 @@
10871087
{"key": "ui.title_art", "scope": "profile_device", "profile_id": "p1", "device_id": "phone", "value": false}
10881088
],
10891089
"expected": [{"key": "ui.title_art", "value": true, "source": "profile"}]
1090+
},
1091+
{
1092+
"name": "subtitle_sync_follows_profile",
1093+
"description": "From revision 19 player.subtitle_sync_ms is also a profile value: a device with no offset of its own uses the profile's.",
1094+
"keys": ["player.subtitle_sync_ms"],
1095+
"context": {"profile_id": "p1", "device_id": "another-device"},
1096+
"stored": [{"key": "player.subtitle_sync_ms", "scope": "profile", "profile_id": "p1", "value": -750}],
1097+
"expected": [{"key": "player.subtitle_sync_ms", "value": -750, "source": "profile"}]
1098+
},
1099+
{
1100+
"name": "subtitle_sync_device_wins",
1101+
"description": "A device's own player.subtitle_sync_ms still wins over the profile offset on that device.",
1102+
"keys": ["player.subtitle_sync_ms"],
1103+
"context": {"profile_id": "p1", "device_id": "d1"},
1104+
"stored": [
1105+
{"key": "player.subtitle_sync_ms", "scope": "profile", "profile_id": "p1", "value": -750},
1106+
{"key": "player.subtitle_sync_ms", "scope": "profile_device", "profile_id": "p1", "device_id": "d1", "value": 250}
1107+
],
1108+
"expected": [{"key": "player.subtitle_sync_ms", "value": 250, "source": "profile_device"}]
10901109
}
10911110
]
10921111
}

‎contracts/settings/v1/manifest.json‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"api_version": 1,
3-
"revision": 18,
3+
"revision": 19,
44
"option_sets": {
55
"playback_audio_languages": {
66
"type": "language_tag",
@@ -796,16 +796,17 @@
796796
"key": "player.subtitle_sync_ms",
797797
"introduced_in": 1,
798798
"persistence": "remote",
799-
"allowed_scopes": ["profile_device"],
800-
"resolution_order": ["profile_device", "default"],
799+
"allowed_scopes": [{ "scope": "profile", "introduced_in": 19 }, "profile_device"],
800+
"resolution_order": ["profile_device", "profile", "default"],
801801
"value_schema": { "type": "integer", "minimum": -10000, "maximum": 10000 },
802802
"default_value": 0,
803803
"unit": "milliseconds",
804-
"platforms": ["ios", "tvos", "macos", "android", "android_tv"],
804+
"platforms": ["web", "ios", "tvos", "macos", "android", "android_tv"],
805805
"category": "player",
806806
"label": "Subtitle sync offset",
807-
"description": "Shift subtitles earlier or later on this device.",
808-
"recommended_control": "slider"
807+
"description": "Shift subtitles earlier or later for this profile. A device can keep its own offset.",
808+
"recommended_control": "slider",
809+
"notes": "Revision 19 adds the profile scope, so the offset follows the profile to every device like the other subtitle display settings, and adds the web client. A device value still wins on that device. Clients write the profile scope only when the server reports manifest revision 19 or later; older servers reject it."
809810
},
810811
{
811812
"key": "player.video_gravity",

‎docs/architecture/subtitle-sync.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ bytes never change.
3232
so effects keep pace with their stretched event. Other formats cannot be synced or retimed.
3333
- A timing change bumps the row's revision like any other update, so
3434
validators captured before it go stale.
35-
- Players already apply a per-device delay (`player.subtitle_sync_ms`); it
36-
stacks on top of the stored correction.
35+
- Players already apply the profile's subtitle offset
36+
(`player.subtitle_sync_ms`, which a device can override); it stacks on top
37+
of the stored correction.
3738

3839
## Sidecar subtitles
3940

‎docs/subtitles-api.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,9 @@ subtitle menu can still show the result and offer a reset.
563563
Corrected bytes reach every delivery path: playback subtitle routes, the
564564
Jellyfin subtitle stream, offline downloads (see [downloads](downloads-api.md)),
565565
and AI translation sources. Those responses are `Cache-Control: private,
566-
no-cache`, since the bytes change behind the same URL. Device delays
567-
(`player.subtitle_sync_ms`) still apply on top. The frozen v1 bridge exposes
566+
no-cache`, since the bytes change behind the same URL. The player's subtitle
567+
offset (`player.subtitle_sync_ms`, a profile value a device can override from
568+
settings manifest revision 19) still applies on top. The frozen v1 bridge exposes
568569
neither timing nor sync but serves corrected bytes.
569570

570571
Replacing the media file (a new file hash or size at the same path) resets the

‎internal/settingskeys/keys.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/src/components/admin/deviceOverrides.platforms.test.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ if (typeof globalThis.ResizeObserver === "undefined") {
1919
ResizeObserverStub;
2020
}
2121

22-
const NATIVE_ONLY_PLAYER_KEYS = [
23-
"player.playback_speed",
24-
"player.subtitle_sync_ms",
25-
"player.hdr_enabled",
26-
];
22+
const NATIVE_ONLY_PLAYER_KEYS = ["player.playback_speed", "player.hdr_enabled"];
2723

2824
function renderAllSettings(devicePlatform: string, settings: AdminDeviceSetting[] = []) {
2925
render(
@@ -84,6 +80,8 @@ describe("DeviceProfileTabs platform filtering", () => {
8480
expect(web).not.toContain(key);
8581
expect(tv).toContain(key);
8682
}
83+
// The web player applies the subtitle offset from manifest revision 19.
84+
expect(web).toContain("player.subtitle_sync_ms");
8785
expect(deviceSettingKeysForPlatform("Windows Web", ["player.playback_speed"])).toHaveLength(
8886
web.length + 1,
8987
);

‎web/src/hooks/queries/subtitleAppearance.test.tsx‎

Lines changed: 105 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { renderHook, waitFor } from "@testing-library/react";
66
import { v2Problem } from "@/api/v2/problems.test-support";
77
import { DEFAULT_SUBTITLE_APPEARANCE } from "@/lib/subtitleAppearance";
88
import { SETTING_KEYS } from "@/lib/settingsContract";
9+
import { resolveSettingValues, type StoredSettingRow } from "@/lib/settingsResolve";
910
import { useSubtitleAppearanceSetting } from "./subtitleAppearance";
1011

1112
const v2Mock = vi.hoisted(() => vi.fn());
@@ -14,6 +15,8 @@ vi.mock("@/api/v2/request", async () => {
1415
return { ...actual, v2: v2Mock };
1516
});
1617

18+
const KEY = SETTING_KEYS.PLAYBACK_SUBTITLE_APPEARANCE;
19+
1720
function createHarness() {
1821
const queryClient = new QueryClient({
1922
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
@@ -24,99 +27,137 @@ function createHarness() {
2427
return { queryClient, wrapper };
2528
}
2629

27-
/** The effective response the server sends for one resolved key. */
28-
function effectiveResponse(value: unknown, source: string) {
29-
return {
30-
revision: 1,
31-
items: [
32-
{ key: SETTING_KEYS.PLAYBACK_SUBTITLE_APPEARANCE, value, source, definition_revision: 1 },
33-
],
34-
};
30+
/**
31+
* A server stand-in that resolves through the shared client resolver, which
32+
* mirrors internal/settingsresolve, so a profile_device row really does
33+
* outrank a profile row here.
34+
*/
35+
function fakeSettingsServer(initial: StoredSettingRow[] = []) {
36+
const rows = [...initial];
37+
v2Mock.mockImplementation(
38+
(
39+
operation: string,
40+
options?: { path?: { key: string }; query?: { scope: string }; body?: { value: unknown } },
41+
) => {
42+
if (operation === "GET /api/v2/settings/values/effective") {
43+
const resolved = resolveSettingValues([KEY], rows, {
44+
profileId: "profile-1",
45+
deviceId: "device-1",
46+
})[0]!;
47+
return Promise.resolve({
48+
revision: 1,
49+
items: [
50+
{ key: KEY, value: resolved.value, source: resolved.source, definition_revision: 1 },
51+
],
52+
});
53+
}
54+
const key = options?.path?.key;
55+
const scope = options?.query?.scope;
56+
if (!key || !scope) return Promise.resolve(undefined);
57+
const index = rows.findIndex((row) => row.key === key && row.scope === scope);
58+
if (operation.startsWith("DELETE ")) {
59+
if (index < 0) {
60+
return Promise.reject(v2Problem(404, "not_found", "No value is set at this scope"));
61+
}
62+
rows.splice(index, 1);
63+
return Promise.resolve(undefined);
64+
}
65+
const row: StoredSettingRow = {
66+
key,
67+
scope: scope as StoredSettingRow["scope"],
68+
profileId: "profile-1",
69+
deviceId: scope === "profile_device" ? "device-1" : undefined,
70+
value: options?.body?.value,
71+
};
72+
if (index < 0) rows.push(row);
73+
else rows[index] = row;
74+
return Promise.resolve(undefined);
75+
},
76+
);
77+
return rows;
3578
}
3679

80+
const XLARGE = { ...DEFAULT_SUBTITLE_APPEARANCE, fontSize: "xlarge" as const };
81+
3782
describe("useSubtitleAppearanceSetting", () => {
3883
beforeEach(() => {
3984
v2Mock.mockReset();
4085
});
4186

42-
it("saves the device override at profile_device scope", async () => {
43-
v2Mock.mockImplementation((operation: string) => {
44-
if (operation === "GET /api/v2/settings/values/effective") {
45-
return Promise.resolve(effectiveResponse(DEFAULT_SUBTITLE_APPEARANCE, "default"));
46-
}
47-
return Promise.resolve(undefined);
48-
});
49-
87+
it("saves at profile scope so the appearance follows the profile to every device", async () => {
88+
const rows = fakeSettingsServer();
5089
const { wrapper } = createHarness();
5190
const { result } = renderHook(() => useSubtitleAppearanceSetting(), { wrapper });
52-
await waitFor(() => expect(result.current.appearance.fontSize).toBe("large"));
91+
await waitFor(() => expect(result.current.isLoading).toBe(false));
5392

54-
await result.current.save({ ...DEFAULT_SUBTITLE_APPEARANCE, fontSize: "xlarge" });
93+
await result.current.save(XLARGE);
5594

56-
const write = v2Mock.mock.calls.find(
57-
([operation]) => operation !== "GET /api/v2/settings/values/effective",
58-
);
59-
expect(write?.[0]).toBe("PUT /api/v2/settings/values/{key}");
60-
expect(write?.[1]).toMatchObject({
61-
path: { key: SETTING_KEYS.PLAYBACK_SUBTITLE_APPEARANCE },
62-
query: { scope: "profile_device" },
63-
// The contract types this value as an object, so the body carries the
64-
// object itself rather than the JSON-encoded string the legacy route took.
65-
body: { value: { ...DEFAULT_SUBTITLE_APPEARANCE, fontSize: "xlarge" } },
66-
});
95+
// The contract types this value as an object, so the body carries the
96+
// object itself rather than a JSON-encoded string.
97+
expect(rows).toEqual([expect.objectContaining({ key: KEY, scope: "profile", value: XLARGE })]);
6798
});
6899

69-
it("resets by clearing the device row so the profile value applies again", async () => {
70-
v2Mock.mockImplementation((operation: string) => {
71-
if (operation === "GET /api/v2/settings/values/effective") {
72-
return Promise.resolve(effectiveResponse(DEFAULT_SUBTITLE_APPEARANCE, "profile_device"));
73-
}
74-
return Promise.resolve(undefined);
75-
});
100+
it("clears this browser's row so a save from an older per-device build stops winning", async () => {
101+
const rows = fakeSettingsServer([
102+
{
103+
key: KEY,
104+
scope: "profile_device",
105+
profileId: "profile-1",
106+
deviceId: "device-1",
107+
value: { ...DEFAULT_SUBTITLE_APPEARANCE, fontSize: "small" },
108+
},
109+
]);
110+
const { wrapper } = createHarness();
111+
const { result } = renderHook(() => useSubtitleAppearanceSetting(), { wrapper });
112+
await waitFor(() => expect(result.current.appearance.fontSize).toBe("small"));
113+
114+
await result.current.save(XLARGE);
115+
116+
expect(rows).toEqual([expect.objectContaining({ scope: "profile", value: XLARGE })]);
117+
await waitFor(() => expect(result.current.appearance.fontSize).toBe("xlarge"));
118+
});
76119

120+
it("does not attempt a delete when nothing is shadowing the profile row", async () => {
121+
fakeSettingsServer([{ key: KEY, scope: "profile", profileId: "profile-1", value: XLARGE }]);
77122
const { wrapper } = createHarness();
78123
const { result } = renderHook(() => useSubtitleAppearanceSetting(), { wrapper });
79-
await waitFor(() => expect(result.current.hasDeviceOverride).toBe(true));
124+
await waitFor(() => expect(result.current.appearance.fontSize).toBe("xlarge"));
80125

81-
await result.current.reset();
126+
await result.current.save(DEFAULT_SUBTITLE_APPEARANCE);
82127

83-
const write = v2Mock.mock.calls.find(
84-
([operation]) => operation !== "GET /api/v2/settings/values/effective",
128+
const deletes = v2Mock.mock.calls.filter(([operation]) =>
129+
String(operation).startsWith("DELETE "),
85130
);
86-
expect(write?.[0]).toBe("DELETE /api/v2/settings/values/{key}");
87-
expect(write?.[1]).toMatchObject({
88-
path: { key: SETTING_KEYS.PLAYBACK_SUBTITLE_APPEARANCE },
89-
query: { scope: "profile_device" },
90-
});
131+
expect(deletes).toHaveLength(0);
91132
});
92133

93-
it("reports no device override when the value resolved from a wider scope", async () => {
94-
v2Mock.mockResolvedValue(effectiveResponse(DEFAULT_SUBTITLE_APPEARANCE, "profile"));
95-
134+
it("resets to the default by clearing both the profile and this browser's rows", async () => {
135+
const rows = fakeSettingsServer([
136+
{ key: KEY, scope: "profile", profileId: "profile-1", value: XLARGE },
137+
{
138+
key: KEY,
139+
scope: "profile_device",
140+
profileId: "profile-1",
141+
deviceId: "device-1",
142+
value: XLARGE,
143+
},
144+
]);
96145
const { wrapper } = createHarness();
97146
const { result } = renderHook(() => useSubtitleAppearanceSetting(), { wrapper });
147+
await waitFor(() => expect(result.current.isCustomized).toBe(true));
98148

99-
await waitFor(() => expect(result.current.isLoading).toBe(false));
100-
expect(result.current.appearance.fontSize).toBe("large");
101-
// A profile-wide appearance is not this device's override, so offering
102-
// "reset this device" would be a no-op the user cannot see the effect of.
103-
expect(result.current.hasDeviceOverride).toBe(false);
149+
await result.current.reset();
150+
151+
expect(rows).toEqual([]);
152+
await waitFor(() => expect(result.current.isCustomized).toBe(false));
153+
expect(result.current.appearance).toEqual(DEFAULT_SUBTITLE_APPEARANCE);
104154
});
105155

106156
it("treats a reset with nothing stored as already done", async () => {
107-
v2Mock.mockImplementation((operation: string) => {
108-
if (operation === "GET /api/v2/settings/values/effective") {
109-
return Promise.resolve(effectiveResponse(DEFAULT_SUBTITLE_APPEARANCE, "profile_device"));
110-
}
111-
if (operation.startsWith("DELETE ")) {
112-
return Promise.reject(v2Problem(404, "not_found", "No value is set at this scope"));
113-
}
114-
return Promise.resolve(undefined);
115-
});
116-
157+
fakeSettingsServer();
117158
const { wrapper } = createHarness();
118159
const { result } = renderHook(() => useSubtitleAppearanceSetting(), { wrapper });
119-
await waitFor(() => expect(result.current.hasDeviceOverride).toBe(true));
160+
await waitFor(() => expect(result.current.isLoading).toBe(false));
120161

121162
// The canonical DELETE answers 404 for "nothing stored here", which for a
122163
// reset is the requested state rather than a failure.

0 commit comments

Comments
 (0)