fix setTheme

This commit is contained in:
Snarling 2023-02-13 19:49:07 -05:00 committed by GitHub
parent f916007f2d
commit f16a4f1a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,17 +28,16 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
const hex = /^(#)((?:[A-Fa-f0-9]{2}){3,4}|(?:[A-Fa-f0-9]{3}))$/;
const currentTheme = { ...Settings.theme };
const errors: string[] = [];
if (typeof newTheme !== "object")
for (const key of Object.keys(newTheme)) {
if (!currentTheme[key]) {
// Invalid key
errors.push(`Invalid key "${key}"`);
} else if (!hex.test(newTheme[key] ?? "")) {
errors.push(`Invalid color "${key}": ${newTheme[key]}`);
} else {
currentTheme[key] = newTheme[key];
}
for (const key of Object.keys(newTheme)) {
if (!currentTheme[key]) {
// Invalid key
errors.push(`Invalid key "${key}"`);
} else if (!hex.test(newTheme[key] ?? "")) {
errors.push(`Invalid color "${key}": ${newTheme[key]}`);
} else {
currentTheme[key] = newTheme[key];
}
}
if (errors.length === 0) {
Object.assign(Settings.theme, currentTheme);