load image faster: do not preload if url is local (#563)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-05-05 15:41:51 +08:00 committed by GitHub
parent ae02ff020a
commit 34161aebea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,12 @@
let lastProcessedPkg: GUIPackage | null = null; let lastProcessedPkg: GUIPackage | null = null;
const loadImage = async (url: string): Promise<string> => { const loadImage = async (url: string): Promise<string> => {
if (url.includes("cached_images")) {
loadedImg = url;
loaded = true;
return url;
}
const image = new Image(); const image = new Image();
image.src = url; image.src = url;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -23,7 +29,7 @@
loadedImg = url; loadedImg = url;
setTimeout(() => { setTimeout(() => {
loaded = true; loaded = true;
}, 300); }, 100);
resolve(url); resolve(url);
}; };
image.onerror = () => { image.onerror = () => {