mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 12:21:47 +00:00
feat: use policy cache instead of creating a new policy for each request
This commit is contained in:
@ -5,10 +5,23 @@ import { ipcMain, ipcRenderer } from 'electron';
|
|||||||
|
|
||||||
import { ValueOf } from '../utils/type-utils';
|
import { ValueOf } from '../utils/type-utils';
|
||||||
|
|
||||||
export const noopTrustedHtmlPolicy = () => window?.trustedTypes?.createPolicy('forceInner', {
|
import type { TrustedTypePolicy } from 'trusted-types/lib';
|
||||||
createHTML: (s: string): string => s,
|
|
||||||
}) ?? {
|
let policyCache: Pick<TrustedTypePolicy<{ createHTML: (s: string) => string }>, 'name' | 'createHTML'> | {
|
||||||
createHTML: (s: string): string => s,
|
createHTML: (s: string) => string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const noopTrustedHtmlPolicy = () => {
|
||||||
|
if (policyCache) {
|
||||||
|
return policyCache;
|
||||||
|
} else {
|
||||||
|
policyCache = window?.trustedTypes?.createPolicy('forceInner', {
|
||||||
|
createHTML: (s: string): string => s,
|
||||||
|
}) ?? {
|
||||||
|
createHTML: (s: string): string => s,
|
||||||
|
};
|
||||||
|
return policyCache;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Creates a DOM element from an HTML string
|
// Creates a DOM element from an HTML string
|
||||||
|
|||||||
Reference in New Issue
Block a user