From 8360bc3e21989a2e97fee92280c9aa2d50d055af Mon Sep 17 00:00:00 2001 From: hymbz Date: Sat, 27 Jul 2024 18:22:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- metaHeader.ts | 2 +- src/components/Manga/actions/imageLoad.ts | 30 +++++++++++------------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/metaHeader.ts b/metaHeader.ts index ba910d4d..364e2504 100644 --- a/metaHeader.ts +++ b/metaHeader.ts @@ -76,7 +76,7 @@ export const updateReadme = () => { }; const enSupportSite = [ - 'E-Hentai (Associate nhentai, Quick favorite, Colorize tags, Detect advertise page, etc.)', + 'E-Hentai (Associate nhentai, Quick favorite, Colorize tags, etc.)', 'nhentai (Totally block comics, Auto page turning)', 'hitomi', 'Anchira', diff --git a/src/components/Manga/actions/imageLoad.ts b/src/components/Manga/actions/imageLoad.ts index 566ff4d2..65a5e7a4 100644 --- a/src/components/Manga/actions/imageLoad.ts +++ b/src/components/Manga/actions/imageLoad.ts @@ -2,7 +2,6 @@ import { clamp, debounce, singleThreaded } from 'helper'; import { createEffectOn, createRootMemo } from 'helper/solidJs'; import { t } from 'helper/i18n'; import { log } from 'helper/logger'; -import { createSignal } from 'solid-js'; import { store, setState, _setState } from '../store'; @@ -10,8 +9,6 @@ import { activePage, preloadNum } from './memo/common'; import { updateImgSize } from './imageSize'; import { renderImgList } from './renderPage'; -const [loadLock, setLoadLock] = createSignal(false, { equals: false }); - /** 用于存储正在加载的图片元素 */ const loadingImgMap = new Map(); @@ -38,9 +35,11 @@ export const handleImgLoaded = (i: number, e: HTMLImageElement) => async () => { img.loadType = 'loaded'; state.prop.Loading?.(state.imgList, img); }); - setLoadLock(false); loadingImgMap.delete(i); - await e.decode(); + updateImgLoadType(); + try { + await e.decode(); + } catch {} }; /** 图片加载出错的次数 */ @@ -58,7 +57,7 @@ export const handleImgError = (i: number, e: HTMLImageElement) => () => { log.error(i, t('alert.img_load_failed'), e); state.prop.Loading?.(state.imgList, img); }); - setLoadLock(false); + updateImgLoadType(); }; /** 需要加载的图片 */ @@ -72,7 +71,7 @@ const needLoadImgList = createRootMemo(() => { /** 当前要加载的图片 */ const loadImgList = new Set(); -/** 加载指定图片。返回是否加载成功 */ +/** 加载指定图片。返回是否已加载完成 */ const loadImg = (index: number) => { if (index === -1 || !needLoadImgList().has(index)) return true; const img = store.imgList[index]; @@ -92,7 +91,7 @@ const loadImg = (index: number) => { checkImgSize(index, imgEle); } loadImgList.add(index); - return true; + return false; }; /** 获取指定页数下的头/尾图片 */ @@ -134,10 +133,7 @@ const loadRangeImg = (target = 0, loadNum = 2) => { while (condition()) { if (!loadImg(index)) hasUnloadedImg = true; - if (loadImgList.size >= loadNum) { - setLoadLock(true); - return index !== end || hasUnloadedImg; - } + if (loadImgList.size >= loadNum) return index !== end || hasUnloadedImg; index += step; } @@ -145,7 +141,7 @@ const loadRangeImg = (target = 0, loadNum = 2) => { }; const updateImgLoadType = singleThreaded(() => { - if (needLoadImgList().size === 0 || loadLock()) return; + if (needLoadImgList().size === 0) return; loadImgList.clear(); @@ -167,13 +163,15 @@ const updateImgLoadType = singleThreaded(() => { } // 取消其他预加载的图片 - for (const index of loadingImgMap.keys()) - if (!loadImgList.has(index)) loadingImgMap.delete(index); + for (const index of loadingImgMap.keys()) { + if (loadImgList.has(index)) continue; + loadingImgMap.delete(index); + _setState('imgList', index, 'loadType', 'wait'); + } }); createEffectOn( [ - loadLock, preloadNum, () => [...renderImgList()].map((i) => store.imgList[i]), () => store.option.alwaysLoadAllImg,