Fix for icons with firefox private mode (#5985)

This commit is contained in:
Bram Kragten 2020-05-22 17:55:28 +02:00 committed by GitHub
parent 4ad3dbf3e2
commit 3640960486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -90,7 +90,14 @@ export class HaIcon extends LitElement {
return;
}
const databaseIcon: string = await getIcon(iconName);
let databaseIcon: string | undefined;
try {
databaseIcon = await getIcon(iconName);
} catch (_err) {
// Firefox in private mode doesn't support IDB
databaseIcon = undefined;
}
if (databaseIcon) {
this._path = databaseIcon;
cachedIcons[iconName] = databaseIcon;

View File

@ -14,12 +14,12 @@ export const iconStore = new Store("hass-icon-db", "mdi-icon-store");
export const MDI_PREFIXES = ["mdi", "hass", "hassio", "hademo"];
let toRead: Array<[string, (string) => void]> = [];
let toRead: Array<[string, (string) => void, () => void]> = [];
// Queue up as many icon fetches in 1 transaction
export const getIcon = (iconName: string) =>
new Promise<string>((resolve) => {
toRead.push([iconName, resolve]);
new Promise<string>((resolve, reject) => {
toRead.push([iconName, resolve, reject]);
if (toRead.length > 1) {
return;
@ -38,6 +38,13 @@ export const getIcon = (iconName: string) =>
for (const [resolve_, request] of results) {
resolve_(request.result);
}
})
.catch(() => {
// Firefox in private mode doesn't support IDB
for (const [, , reject_] of toRead) {
reject_();
}
toRead = [];
});
});

View File

@ -136,7 +136,7 @@ export class HuiMarkdownCard extends LitElement implements LovelaceCard {
},
}
);
} catch {
} catch (_err) {
this._content = this._config!.content;
this._unsubRenderTemplate = undefined;
}