ui fix loader for css files
This commit is contained in:
parent
c8690afbba
commit
59d6ef6bd0
1 changed files with 5 additions and 24 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type Screen from '../../Screen/Screen';
|
||||
import { replaceCSSPseudoclasses } from '../../messages/rewriter/rewriteMessage'
|
||||
import type Screen from 'App/player/web/Screen/Screen';
|
||||
import { replaceCSSPseudoclasses } from 'App/player/web/messages/rewriter/rewriteMessage'
|
||||
import logger from 'App/logger'
|
||||
|
||||
// Doesn't work with css files (hasOwnProperty returns false)
|
||||
|
|
@ -18,31 +18,21 @@ function rewriteNodeStyleSheet(doc: Document, node: HTMLLinkElement | HTMLStyleE
|
|||
export default class StylesManager {
|
||||
private linkLoadingCount: number = 0;
|
||||
private linkLoadPromises: Array<Promise<void>> = [];
|
||||
private skipCSSLinks: Array<string> = []; // should be common for all pages
|
||||
private abortController = new AbortController()
|
||||
private skipCSSLinks: Array<string> = [];
|
||||
|
||||
constructor(private readonly screen: Screen, private readonly setLoading: (flag: boolean) => void) {}
|
||||
|
||||
reset():void {
|
||||
this.linkLoadingCount = 0;
|
||||
this.linkLoadPromises = [];
|
||||
|
||||
this.abortController.abort();
|
||||
this.abortController = new AbortController();
|
||||
}
|
||||
|
||||
setStyleHandlers(node: HTMLLinkElement, value: string): void {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||
const promise = new Promise<void>((resolve) => {
|
||||
if (
|
||||
this.abortController.signal.aborted
|
||||
|| this.skipCSSLinks.includes(value)
|
||||
|| node.ownerDocument !== this.screen.document
|
||||
) {
|
||||
resolve();
|
||||
}
|
||||
this.setLoading(true);
|
||||
if (this.skipCSSLinks.includes(value)) resolve();
|
||||
this.linkLoadingCount++;
|
||||
this.setLoading(true);
|
||||
const addSkipAndResolve = (e: any) => {
|
||||
this.skipCSSLinks.push(value); // watch out
|
||||
logger.error('skip node', e)
|
||||
|
|
@ -58,22 +48,13 @@ export default class StylesManager {
|
|||
resolve();
|
||||
}
|
||||
node.onerror = addSkipAndResolve;
|
||||
this.abortController.signal.addEventListener('abort', () => {
|
||||
node.onload = null;
|
||||
node.onerror = null;
|
||||
clearTimeout(timeoutId);
|
||||
resolve();
|
||||
});
|
||||
}).then(() => {
|
||||
node.onload = null;
|
||||
node.onerror = null;
|
||||
clearTimeout(timeoutId);
|
||||
this.linkLoadingCount--;
|
||||
if (this.linkLoadingCount === 0) {
|
||||
setTimeout(() => {
|
||||
this.setLoading(false)
|
||||
this.linkLoadPromises = [];
|
||||
}, 0)
|
||||
}
|
||||
});
|
||||
this.linkLoadPromises.push(promise);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue