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
2 changes: 1 addition & 1 deletion src/app/service/content/gm_api/gm_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function evaluateGMInfo(envInfo: GMInfoEnv, script: TScriptInfo) {
// TODO: 更多完整的信息(为了兼容Tampermonkey,后续待定)
name: script.name,
namespace: script.namespace,
version: script.metadata.version?.[0],
version: script.metadata.version?.[0] || "0.0",
author: script.author,
lastModified: script.updatetime,
downloadURL: script.downloadUrl || null,
Expand Down
62 changes: 7 additions & 55 deletions src/app/service/service_worker/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export class ScriptService {
const logger = this.logger.with({
name: script.name,
uuid: script.uuid,
version: script.metadata.version![0],
version: script.metadata.version?.[0] || "0.0",
upsertBy,
});
let update = false;
Expand Down Expand Up @@ -803,15 +803,8 @@ export class ScriptService {
logger.error("parse metadata failed");
return false;
}
const newVersion = metadata.version && metadata.version[0];
if (!newVersion) {
logger.error("parse version failed", { version: metadata.version });
return false;
}
let oldVersion = script.metadata.version && script.metadata.version[0];
if (!oldVersion) {
oldVersion = "0.0.0";
}
const newVersion = metadata.version?.[0] || "0.0";
const oldVersion = script.metadata.version?.[0] || "0.0";
// 对比版本大小
if (ltever(newVersion, oldVersion)) {
return false;
Expand Down Expand Up @@ -902,7 +895,8 @@ export class ScriptService {
}

shouldIgnoreUpdate(script: Script, newMeta: Partial<Record<string, string[]>> | null) {
return script.ignoreVersion === newMeta?.version?.[0];
const newVersion = newMeta?.version?.[0];
return typeof newVersion === "string" && script.ignoreVersion === newVersion;
}

// 用于定时自动检查脚本更新
Expand Down Expand Up @@ -1139,7 +1133,6 @@ export class ScriptService {
}

requestCheckUpdate(uuid: string) {
// src/pages/options/routes/ScriptList.tsx
return this.checkUpdateAvailable(uuid).then((script) => {
if (script) {
// 如有更新则打开更新画面进行更新
Expand All @@ -1148,56 +1141,15 @@ export class ScriptService {
}
return false;
});

// 没有空值 case
/*
if (uuid) {
return this.checkUpdateAvailable(uuid).then((script) => {
if (script) {
// 如有更新则打开更新画面进行更新
this.openUpdatePage(script, "user");
return true;
}
return false;
});
} else {
// 批量检查更新
InfoNotification("检查更新", "正在检查所有的脚本更新");
this.scriptDAO
.all()
.then(async (scripts) => {
// 检查是否有更新
const results = await this.checkUpdatesAvailable(
scripts.map((script) => script.uuid),
{
MIN_DELAY: 300,
MAX_DELAY: 800,
}
);
return Promise.all(
scripts.map((script, i) => {
const result = results[i];
if (result) {
// 如有更新则打开更新画面进行更新
this.openUpdatePage(script, "user");
}
})
);
})
.then(() => {
InfoNotification("检查更新", "所有脚本检查完成");
});
return Promise.resolve(true); // 无视检查结果,立即回传true
}
*/
}

isInstalled({ name, namespace }: { name: string; namespace: string }): Promise<App.IsInstalledResponse> {
// 用於 window.external
return this.scriptDAO.findByNameAndNamespace(name, namespace).then((script) => {
if (script) {
return {
installed: true,
version: script.metadata.version && script.metadata.version[0],
version: script.metadata.version?.[0] || "0.0",
} as App.IsInstalledResponse;
}
return { installed: false } as App.IsInstalledResponse;
Expand Down
3 changes: 2 additions & 1 deletion src/app/service/service_worker/script_update_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ScriptUpdateCheck {
if (!list) return [] as string[];
const s = new Set<string>();
for (const entry of list) {
if (entry.script?.ignoreVersion === entry.newMeta?.version?.[0]) continue;
const newVersion = entry.newMeta?.version?.[0];
if (typeof newVersion === "string" && entry.script?.ignoreVersion === newVersion) continue;
if (entry.script?.status !== 1) continue;
if (!entry.script?.checkUpdate) continue;
if (!entry.sites) continue;
Expand Down
11 changes: 2 additions & 9 deletions src/app/service/service_worker/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,8 @@ export class SubscribeService {
logger.error("parse metadata failed");
return false;
}
const newVersion = metadata.version && metadata.version[0];
if (!newVersion) {
logger.error("parse version failed", { version: metadata.version });
return false;
}
let oldVersion = subscribe.metadata.version && subscribe.metadata.version[0];
if (!oldVersion) {
oldVersion = "0.0.0";
}
const newVersion = metadata.version?.[0] || "0.0";
const oldVersion = subscribe.metadata.version?.[0] || "0.0";
// 对比版本大小
if (ltever(newVersion, oldVersion)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/app/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare namespace App {
export type IsInstalledResponse =
| {
installed: true;
version: string | undefined;
version: string;
}
| {
installed: false;
Expand Down
8 changes: 5 additions & 3 deletions src/pages/batchupdate/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ function App() {
site.push(entry);
continue;
}
const isIgnored = entry.script.ignoreVersion === entry.newMeta?.version?.[0];
const newVersion = entry.newMeta?.version?.[0];
const isIgnored = typeof newVersion === "string" && entry.script.ignoreVersion === newVersion;
const mEntry = {
...entry,
};
Expand Down Expand Up @@ -267,12 +268,13 @@ function App() {
<Link disabled={isDoingTask} onClick={() => onUpdateClick(item.uuid)}>
{t("updatepage.update")}
</Link>
{item.script.ignoreVersion !== item.newMeta?.version?.[0] ? (
{typeof item.newMeta?.version?.[0] === "string" &&
item.script.ignoreVersion !== item.newMeta.version[0] ? (
<>
<Divider type="vertical" />
<Link
disabled={isDoingTask}
onClick={() => onIgnoreClick(item.uuid, item.newMeta?.version?.[0])}
onClick={() => onIgnoreClick(item.uuid, item.newMeta.version[0])}
>
{t("updatepage.ignore")}
</Link>
Expand Down
12 changes: 8 additions & 4 deletions src/pages/install/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@
await scriptClient.install({ script: newScript, code });
const metadata = newScript.metadata;
setScriptInfo((prev) => (prev ? { ...prev, code, metadata } : prev));
setOldScriptVersion(metadata!.version![0]);
const scriptVersion = metadata.version?.[0];
const oldScriptVersion = typeof scriptVersion === "string" ? scriptVersion : "N/A";
setOldScriptVersion(oldScriptVersion);
Comment on lines +203 to +205
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

安装页这里把缺失/空的版本显示为 "N/A",而其它列表页回退显示为 "0.0"。如果目标是“跟 TM 一样显示 0.0”,建议这里也统一回退为 "0.0";如果确实需要区分未知(N/A)与空值,请在 UI/文案上明确规则并保持各页面一致。

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

這裡寫 N/A 會比較好

setUpsertScript(newScript);
setDiffCode(code);
};
Expand Down Expand Up @@ -289,15 +291,17 @@
prepare = await prepareSubscribeByCode(code, url);
action = prepare.subscribe;
if (prepare.oldSubscribe) {
oldVersion = prepare.oldSubscribe!.metadata!.version![0] || "";
const oldSubscribeVersion = prepare.oldSubscribe.metadata.version?.[0];
oldVersion = typeof oldSubscribeVersion === "string" ? oldSubscribeVersion : "N/A";
}
diffCode = prepare.oldSubscribe?.code;
} else {
const knownUUID = isKnownUpdate ? info.uuid : undefined;
prepare = await prepareScriptByCode(code, url, knownUUID, false, undefined, paramOptions);
action = prepare.script;
if (prepare.oldScript) {
oldVersion = prepare.oldScript!.metadata!.version![0] || "";
const oldScriptVersion = prepare.oldScript.metadata.version?.[0];
oldVersion = typeof oldScriptVersion === "string" ? oldScriptVersion : "N/A";
}
diffCode = prepare.oldScriptCode;
}
Expand Down Expand Up @@ -326,7 +330,7 @@

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

Check warning on line 333 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 @@ -641,7 +645,7 @@
return () => {
unmountFileTrack(handle);
};
}, [memoWatchFile]);

Check warning on line 648 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 @@ -708,7 +712,7 @@
useEffect(() => {
if (!urlHref) return;
loadURLAsync(urlHref);
}, [urlHref]);

Check warning on line 715 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 @@ -793,7 +797,7 @@
<Tag bordered>{oldScriptVersion}</Tag>
</Tooltip>
)}
{metadataLive.version && metadataLive.version[0] !== oldScriptVersion && (
{typeof metadataLive.version?.[0] === "string" && metadataLive.version[0] !== oldScriptVersion && (
<Tooltip color="red" content={`${t("update_version")}: v${metadataLive.version[0]}`}>
<Tag bordered color="red">
{metadataLive.version[0]}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/options/routes/ScriptList/ScriptCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export const ScriptCardItem = React.memo(

{/* 版本和更新时间 */}
<div className="tw-flex tw-flex-row tw-gap-4 tw-text-sm tw-text-gray-500">
{item.metadata.version && (
{item.metadata.version?.[0] && (
<div>
<span className="tw-font-medium">
{t("version")}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/options/routes/ScriptList/ScriptTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const NameCell = React.memo(({ col, item }: { col: string; item: ListType }) =>
NameCell.displayName = "NameCell";

const VersionCell = React.memo(({ item }: { item: ListType }) => {
return item.metadata.version && item.metadata.version[0];
return item.metadata.version?.[0] || "0.0";
});
VersionCell.displayName = "VersionCell";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/options/routes/SubscribeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function SubscribeList() {
align: "center",
key: "version",
render(col, item: Subscribe) {
return item.metadata.version && item.metadata.version[0];
return item.metadata.version?.[0] || "0.0";
},
},
{
Expand Down
Loading
Loading