Fix so legacy custom themes still load. (#4757)

Co-authored-by: matt korwel <matt.korwel@gmail.com>
This commit is contained in:
Jacob Richman
2025-07-25 17:36:42 -07:00
committed by GitHub
parent b089845f1c
commit ad2ef080aa
3 changed files with 183 additions and 6 deletions
+25 -5
View File
@@ -323,6 +323,7 @@ export function createCustomTheme(customTheme: CustomTheme): Theme {
export function validateCustomTheme(customTheme: Partial<CustomTheme>): {
isValid: boolean;
error?: string;
warning?: string;
} {
// Check required fields
const requiredFields: Array<keyof CustomTheme> = [
@@ -336,12 +337,17 @@ export function validateCustomTheme(customTheme: Partial<CustomTheme>): {
'AccentGreen',
'AccentYellow',
'AccentRed',
'DiffAdded',
'DiffRemoved',
// 'DiffAdded' and 'DiffRemoved' are not required as they were added after
// the theme format was defined.
'Comment',
'Gray',
];
const recommendedFields: Array<keyof CustomTheme> = [
'DiffAdded',
'DiffRemoved',
];
for (const field of requiredFields) {
if (!customTheme[field]) {
return {
@@ -351,6 +357,14 @@ export function validateCustomTheme(customTheme: Partial<CustomTheme>): {
}
}
const missingFields: string[] = [];
for (const field of recommendedFields) {
if (!customTheme[field]) {
missingFields.push(field);
}
}
// Validate color format (basic hex validation)
const colorFields: Array<keyof CustomTheme> = [
'Background',
@@ -369,8 +383,8 @@ export function validateCustomTheme(customTheme: Partial<CustomTheme>): {
];
for (const field of colorFields) {
const color = customTheme[field] as string;
if (!isValidColor(color)) {
const color = customTheme[field] as string | undefined;
if (color !== undefined && !isValidColor(color)) {
return {
isValid: false,
error: `Invalid color format for ${field}: ${color}`,
@@ -386,7 +400,13 @@ export function validateCustomTheme(customTheme: Partial<CustomTheme>): {
};
}
return { isValid: true };
return {
isValid: true,
warning:
missingFields.length > 0
? `Missing field(s) ${missingFields.join(', ')}`
: undefined,
};
}
/**