Skip to content

Commit b509d44

Browse files
committed
Extracted CustomErrorSettings
1 parent f1bc6b7 commit b509d44

File tree

5 files changed

+54
-51
lines changed

5 files changed

+54
-51
lines changed

special-pages/pages/duckplayer/app/features/error-detection.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { YOUTUBE_ERROR_EVENT, YOUTUBE_ERRORS } from '../providers/YouTubeErrorPr
33
/**
44
* @typedef {import("./iframe").IframeFeature} IframeFeature
55
* @typedef {import('../../types/duckplayer').YouTubeError} YouTubeError
6-
* @typedef {import('../../types/duckplayer').DuckPlayerPageSettings['customError']} CustomErrorOptions
6+
* @typedef {import('../../types/duckplayer').CustomErrorSettings} CustomErrorSettings
77
*/
88

99
/**
@@ -15,11 +15,11 @@ export class ErrorDetection {
1515
/** @type {HTMLIFrameElement} */
1616
iframe;
1717

18-
/** @type {CustomErrorOptions} */
18+
/** @type {CustomErrorSettings} */
1919
options;
2020

2121
/**
22-
* @param {CustomErrorOptions} options
22+
* @param {CustomErrorSettings} options
2323
*/
2424
constructor(options) {
2525
this.options = options;
@@ -115,7 +115,8 @@ export class ErrorDetection {
115115

116116
// 2. Check for sign-in support link
117117
try {
118-
if (this.options?.signInRequiredSelector && !!iframeWindow.document.querySelector(this.options.signInRequiredSelector)) {
118+
const { settings } = this.options;
119+
if (settings?.signInRequiredSelector && !!iframeWindow.document.querySelector(settings.signInRequiredSelector)) {
119120
return YOUTUBE_ERRORS.signInRequired;
120121
}
121122
} catch (e) {

special-pages/pages/duckplayer/app/settings.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
const DEFAULT_SIGN_IN_REQURED_HREF = '[href*="//support.google.com/youtube/answer/3037019"]';
22

3-
/**
4-
* @typedef {object} CustomErrorSettings
5-
* @property {'enabled'|'disabled'} state
6-
* @property {object} [settings]
7-
* @property {string} [settings.signInRequiredSelector]
8-
*/
9-
103
export class Settings {
114
/**
125
* @param {object} params
@@ -47,15 +40,15 @@ export class Settings {
4740
* }
4841
* }
4942
*
50-
* @param {import("../types/duckplayer.js").DuckPlayerPageSettings['customError']} customErrorSettings
51-
* @return {CustomErrorSettings}
43+
* @param {import("../types/duckplayer.js").DuckPlayerPageSettings['customError']} initialSettings
44+
* @return {import("../types/duckplayer.js").CustomErrorSettings}
5245
*/
53-
parseLegacyCustomError(customErrorSettings) {
54-
if (customErrorSettings?.state !== 'enabled') {
46+
parseLegacyCustomError(initialSettings) {
47+
if (initialSettings?.state !== 'enabled') {
5548
return { state: 'disabled' };
5649
}
5750

58-
const { settings, signInRequiredSelector } = customErrorSettings;
51+
const { settings, signInRequiredSelector } = initialSettings;
5952

6053
return {
6154
state: 'enabled',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "CustomErrorSettings",
4+
"type": "object",
5+
"description": "Configures a custom error message for YouTube errors",
6+
"required": ["state"],
7+
"properties": {
8+
"state": {
9+
"type": "string",
10+
"enum": ["enabled", "disabled"]
11+
},
12+
"settings": {
13+
"type": "object",
14+
"description": "Custom error settings",
15+
"properties": {
16+
"signInRequiredSelector": {
17+
"description": "A selector that, when not empty, indicates a sign-in required error",
18+
"type": "string"
19+
}
20+
}
21+
}
22+
}
23+
}

special-pages/pages/duckplayer/messages/initialSetup.response.json

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,18 @@
4040
}
4141
},
4242
"customError": {
43-
"type": "object",
44-
"description": "Configures a custom error message for YouTube errors",
45-
"required": ["state"],
46-
"properties": {
47-
"state": {
48-
"type": "string",
49-
"enum": ["enabled", "disabled"]
50-
},
51-
"settings": {
52-
"type": "object",
53-
"description": "Custom error settings",
43+
"allOf": [
44+
{ "$ref": "customErrorSettings.shared.json" },
45+
{
5446
"properties": {
5547
"signInRequiredSelector": {
56-
"$ref": "#/definitions/signInRequiredSelector"
48+
"type": "string",
49+
"description": "A selector that, when not empty, indicates a sign-in required error",
50+
"$comment": "This setting is duplicated at the top level until Apple and Windows are migrated to the settings object above"
5751
}
5852
}
59-
},
60-
"signInRequiredSelector": {
61-
"$ref": "#/definitions/signInRequiredSelector",
62-
"$comment": "This setting is duplicated at the top level until Apple and Windows are migrated to the settings object above"
6353
}
64-
}
54+
]
6555
}
6656
}
6757
},
@@ -86,11 +76,5 @@
8676
"type": "string",
8777
"description": "Optional locale-specific strings"
8878
}
89-
},
90-
"definitions": {
91-
"signInRequiredSelector": {
92-
"description": "A selector that, when not empty, indicates a sign-in required error",
93-
"type": "string"
94-
}
9579
}
9680
}

special-pages/pages/duckplayer/types/duckplayer.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,22 @@ export interface DuckPlayerPageSettings {
129129
focusMode?: {
130130
state: "enabled" | "disabled";
131131
};
132-
/**
133-
* Configures a custom error message for YouTube errors
134-
*/
135-
customError?: {
136-
state: "enabled" | "disabled";
132+
customError?: CustomErrorSettings & {
137133
/**
138-
* Custom error settings
134+
* A selector that, when not empty, indicates a sign-in required error
139135
*/
140-
settings?: {
141-
/**
142-
* A selector that, when not empty, indicates a sign-in required error
143-
*/
144-
signInRequiredSelector?: string;
145-
};
136+
signInRequiredSelector?: string;
137+
};
138+
}
139+
/**
140+
* Configures a custom error message for YouTube errors
141+
*/
142+
export interface CustomErrorSettings {
143+
state: "enabled" | "disabled";
144+
/**
145+
* Custom error settings
146+
*/
147+
settings?: {
146148
/**
147149
* A selector that, when not empty, indicates a sign-in required error
148150
*/

0 commit comments

Comments
 (0)