Skip to content
Open
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
22 changes: 10 additions & 12 deletions src/app/service/service_worker/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@
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 @@ -797,15 +797,8 @@
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 @@ -896,7 +889,8 @@
}

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 === newMeta?.version?.[0];
}

// 用于定时自动检查脚本更新
Expand Down Expand Up @@ -1187,11 +1181,15 @@
}

isInstalled({ name, namespace }: { name: string; namespace: string }): Promise<App.IsInstalledResponse> {
// 用於 window.external
console.error(1237, name, namespace);

Check failure on line 1185 in src/app/service/service_worker/script.ts

View workflow job for this annotation

GitHub Actions / Run tests

Delete `··`
return this.scriptDAO.findByNameAndNamespace(name, namespace).then((script) => {
console.log(1238, name, namespace, script);
console.error(1239, name, namespace, 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 @@ -92,7 +92,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 @@ -269,12 +270,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);
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 @@ -181,7 +181,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 @@ -403,7 +403,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
5 changes: 1 addition & 4 deletions src/pkg/utils/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ export async function prepareScriptByCode(
if (!metadata.name?.[0]) {
throw new Error(i18n_t("error_script_name_required"));
}
// 不接受空白version
if (!metadata.version?.[0]) {
throw new Error(i18n_t("error_script_version_required"));
}
// 可接受空白namespace
if (metadata.namespace === undefined) {
throw new Error(i18n_t("error_script_namespace_required"));
}
// 可接受空白version
let type = SCRIPT_TYPE_NORMAL;
if (metadata.crontab !== undefined) {
type = SCRIPT_TYPE_CRONTAB;
Expand Down
Loading