Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/pages/install/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Avatar,
Button,
Dropdown,
Message,
Expand Down Expand Up @@ -33,6 +32,7 @@
import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key";
import { cacheInstance } from "@App/app/cache";
import { formatBytes, prettyUrl } from "@App/pkg/utils/utils";
import { ScriptIcons } from "../options/routes/utils";

const backgroundPromptShownKey = "background_prompt_shown";

Expand Down Expand Up @@ -324,7 +324,7 @@

useEffect(() => {
!loaded && initAsync();
}, [searchParams, loaded]);

Check warning on line 327 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has a missing dependency: 'initAsync'. Either include it or remove the dependency array

const [watchFile, setWatchFile] = useState(false);
const metadataLive = useMemo(() => (scriptInfo?.metadata || {}) as SCMetadata, [scriptInfo]);
Expand Down Expand Up @@ -633,7 +633,7 @@
return () => {
unmountFileTrack(handle);
};
}, [memoWatchFile]);

Check warning on line 636 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has missing dependencies: 'localFileHandle', 'scriptInfo?.uuid', 'setupWatchFile', and 'watchFile'. Either include them or remove the dependency array

// 检查是否有 uuid 或 file
const hasUUIDorFile = useMemo(() => {
Expand Down Expand Up @@ -700,7 +700,7 @@
useEffect(() => {
if (!urlHref) return;
loadURLAsync(urlHref);
}, [urlHref]);

Check warning on line 703 in src/pages/install/App.tsx

View workflow job for this annotation

GitHub Actions / Run tests

React Hook useEffect has a missing dependency: 'loadURLAsync'. Either include it or remove the dependency array

if (!hasUUIDorFile) {
return urlHref ? (
Expand Down Expand Up @@ -766,11 +766,7 @@
</Modal>
<div className="tw-flex tw-flex-row tw-gap-x-3 tw-pt-3 tw-pb-3">
<div className="tw-grow-1 tw-shrink-1 tw-flex tw-flex-row tw-justify-start tw-items-center">
{upsertScript?.metadata.icon && (
<Avatar size={32} shape="square" style={{ marginRight: "8px" }}>
<img src={upsertScript.metadata.icon[0]} alt={upsertScript.name} />
</Avatar>
)}
{upsertScript?.metadata.icon && <ScriptIcons script={upsertScript} size={32} />}
{upsertScript && (
<Tooltip position="tl" content={i18nName(upsertScript)}>
<Typography.Text bold className="tw-text-size-lg tw-truncate tw-w-0 tw-grow-1">
Expand Down
28 changes: 15 additions & 13 deletions src/pages/options/routes/ScriptList/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ EnableSwitch.displayName = "EnableSwitch";

// Memoized Avatar component to prevent unnecessary re-renders
export const MemoizedAvatar = React.memo(
({ match, icon, website, ...rest }: { match: string; icon?: string; website?: string; [key: string]: any }) => (
<Avatar
shape="square"
style={{
backgroundColor: "unset",
borderWidth: 1,
}}
className={website ? "tw-cursor-pointer" : "tw-cursor-default"}
{...rest}
>
{icon ? <img title={match} src={icon} /> : <TbWorldWww title={match} color="#aaa" size={24} />}
</Avatar>
),
({ match, icon, website, ...rest }: { match: string; icon?: string; website?: string; [key: string]: any }) => {
return (
<Avatar
shape="square"
style={{
backgroundColor: "unset",
borderWidth: 0,
}}
className={website ? "tw-cursor-pointer" : "tw-cursor-default"}
{...rest}
>
{icon ? <img title={match} src={icon} /> : <TbWorldWww title={match} color="#aaa" size={24} />}
</Avatar>
);
},
(prevProps, nextProps) => {
return (
prevProps.match === nextProps.match &&
Expand Down
6 changes: 4 additions & 2 deletions src/pages/options/routes/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ export type ScriptIconsProps = {
};

export function ScriptIcons({ script, size = 32, style }: ScriptIconsProps) {
const [imageError, setImageError] = useState(false);
style = style || {};
style.display = style.display || "inline-block";
style.marginRight = style.marginRight || "8px";
style.backgroundColor = style.backgroundColor || "unset";
const m = script.metadata;
const [icon] = m.icon || m.iconurl || m.icon64 || m.icon64url || [];
if (icon) {
if (icon && !imageError) {
return (
<Avatar size={size || 32} shape="square" style={style}>
<img src={icon} alt={script?.name} />
<img src={icon} alt={script?.name} onError={() => setImageError(true)} />
</Avatar>
);
}
Expand Down
9 changes: 0 additions & 9 deletions src/pages/store/favicons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type Script, ScriptDAO } from "@App/app/repo/scripts";
import { cacheInstance } from "@App/app/cache";
import { CACHE_KEY_FAVICON } from "@App/app/cache_key";
import { FaviconDAO, type FaviconFile, type FaviconRecord } from "@App/app/repo/favicon";
import { v5 as uuidv5 } from "uuid";
import { getFaviconRootFolder } from "@App/app/service/service_worker/utils";
Expand Down Expand Up @@ -225,12 +223,6 @@ export const loadFavicon = async (iconUrl: string): Promise<string> => {
const directoryHandle = await getFaviconRootFolder();
// 使用url的uuid作为文件名
const filename = `icon_${uuidv5(iconUrl, uuidv5.URL)}.dat`;
try {
const sessionBlobUrl = await cacheInstance.get<string>(`${CACHE_KEY_FAVICON}${filename}`);
if (sessionBlobUrl) return sessionBlobUrl;
} catch {
// 即使报错也不影响
}
Comment on lines -228 to -233
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyfung1031 这里是运行在option页面上的,刷新option页面,会释放掉,这里用了缓存第二次会返回无效的链接

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原來如此

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那就不cache每次都取opfs 做bloburl吧

// 检查文件是否存在
let fileHandle: FileSystemFileHandle | undefined;
try {
Expand All @@ -251,7 +243,6 @@ export const loadFavicon = async (iconUrl: string): Promise<string> => {
const opfsRet = { dirs: ["cached_favicons"], filename: filename };
const file = await getFileFromOPFS(opfsRet);
const blobUrl = URL.createObjectURL(file);
cacheInstance.set(`${CACHE_KEY_FAVICON}${filename}`, blobUrl); // 不用等待。针对SW重启 - blobURL 的生命周期依附于页面
return blobUrl;
};

Expand Down
Loading