mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-22 18:21:39 +01:00
Make code more readable
This commit is contained in:
parent
5d63069f31
commit
86fec8bf0e
@ -334,8 +334,7 @@ export class Platform {
|
|||||||
|
|
||||||
async replaceStylesheet(newPath, log) {
|
async replaceStylesheet(newPath, log) {
|
||||||
const error = await this.logger.wrapOrRun(log, { l: "replaceStylesheet", location: newPath, }, async (l) => {
|
const error = await this.logger.wrapOrRun(log, { l: "replaceStylesheet", location: newPath, }, async (l) => {
|
||||||
let resolve, error;
|
let error;
|
||||||
const promise = new Promise(r => resolve = r);
|
|
||||||
const head = document.querySelector("head");
|
const head = document.querySelector("head");
|
||||||
// remove default theme
|
// remove default theme
|
||||||
document.querySelectorAll(".theme").forEach(e => e.remove());
|
document.querySelectorAll(".theme").forEach(e => e.remove());
|
||||||
@ -345,6 +344,7 @@ export class Platform {
|
|||||||
styleTag.rel = "stylesheet";
|
styleTag.rel = "stylesheet";
|
||||||
styleTag.type = "text/css";
|
styleTag.type = "text/css";
|
||||||
styleTag.className = "theme";
|
styleTag.className = "theme";
|
||||||
|
const promise = new Promise(resolve => {
|
||||||
styleTag.onerror = () => {
|
styleTag.onerror = () => {
|
||||||
error = new Error(`Failed to load stylesheet from ${newPath}`);
|
error = new Error(`Failed to load stylesheet from ${newPath}`);
|
||||||
l.catch(error);
|
l.catch(error);
|
||||||
@ -353,6 +353,7 @@ export class Platform {
|
|||||||
styleTag.onload = () => {
|
styleTag.onload = () => {
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
});
|
||||||
head.appendChild(styleTag);
|
head.appendChild(styleTag);
|
||||||
await promise;
|
await promise;
|
||||||
return error;
|
return error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user