feat: detect custom background image not available (fehmer) (#5460)

* feat: detect custom background image not available (fehmer)

* settings page not updating custom background input if config changes

* cleanup
This commit is contained in:
Christian Fehmer 2024-05-30 13:04:55 +02:00 committed by GitHub
parent 595000ad4f
commit 24909fda1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -4,7 +4,7 @@ import * as Misc from "../utils/misc";
import * as Arrays from "../utils/arrays";
import * as JSONData from "../utils/json-data";
import { isColorDark, isColorLight } from "../utils/colors";
import Config, { setAutoSwitchTheme } from "../config";
import Config, { setAutoSwitchTheme, setCustomBackground } from "../config";
import * as BackgroundFilter from "../elements/custom-background-filter";
import * as ConfigEvent from "../observables/config-event";
import * as DB from "../db";
@ -345,7 +345,7 @@ function applyCustomBackground(): void {
$("#words").addClass("noErrorBorder");
$("#resultWordsHistory").addClass("noErrorBorder");
$(".customBackground").html(
`<img src="${Config.customBackground}" alt="" />`
`<img src="${Config.customBackground}" alt="" onerror="javascript:window.dispatchEvent(new Event('customBackgroundFailed'))" />`
);
BackgroundFilter.apply();
applyCustomBackgroundSize();
@ -425,3 +425,10 @@ ConfigEvent.subscribe(async (eventKey, eventValue, nosave) => {
await set(Config.themeDark, true);
}
});
window.addEventListener("customBackgroundFailed", () => {
Notifications.add(
"The custom background cannot be loaded and will be removed from your configuration."
);
setCustomBackground("");
});

View file

@ -950,6 +950,9 @@ export async function update(groupUpdate = true): Promise<void> {
".pageSettings .section[data-config-name='customBackgroundFilter']"
).addClass("hidden");
}
$(
".pageSettings .section[data-config-name='customBackgroundSize'] input"
).val(Config.customBackground);
if (isAuthenticated()) {
showAccountSection();