Skip to content

Commit ebc6400

Browse files
committed
🐛 传递网页安装入口标记
1 parent a2fc97e commit ebc6400

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/pages/install/useInstallData.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,28 @@ describe("useInstallData 数据流编排", () => {
440440
expect(result.current.localFile).toBe(false);
441441
});
442442

443+
it("?url= 且 byWebRequest=1 时应把入口标记传给脚本准备流程", async () => {
444+
window.history.replaceState({}, "", "/install.html?byWebRequest=1&url=https://e.com/x.user.js");
445+
const metadata = { name: ["URL脚本"], version: ["1.0.0"] };
446+
(fetchScriptBody as Mock).mockResolvedValue("// url code");
447+
(parseMetadata as Mock).mockReturnValue(metadata);
448+
(prepareScriptByCode as Mock).mockResolvedValue({
449+
script: { name: "URL脚本", metadata, status: SCRIPT_STATUS_ENABLE } as unknown as Script,
450+
});
451+
452+
const { result } = renderHook(() => useInstallData());
453+
await waitFor(() => expect(result.current.state.status).toBe("ready"));
454+
455+
expect(prepareScriptByCode).toHaveBeenCalledWith(
456+
"// url code",
457+
"https://e.com/x.user.js",
458+
undefined,
459+
false,
460+
undefined,
461+
{ byWebRequest: true }
462+
);
463+
});
464+
443465
it("?url= 下载过程中在 loading 状态展示已接收字节与百分比", async () => {
444466
window.history.replaceState({}, "", "/install.html?url=https://e.com/x.user.js");
445467
const metadata = { name: ["URL脚本"], version: ["1.0.0"] };

src/pages/install/useInstallData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ export function useInstallData(): UseInstallData {
304304
});
305305
const metadata = parseMetadata(code);
306306
if (!metadata) throw new Error(t("install:script_info_load_failed"));
307-
await loadFromInfo(buildScriptInfo(uuidv4(), code, parsed.href, metadata), false, {});
307+
await loadFromInfo(buildScriptInfo(uuidv4(), code, parsed.href, metadata), false, {
308+
byWebRequest: byWebRequestRef.current,
309+
});
308310
} else if (fid) {
309311
const handle = await loadHandle(fid);
310312
if (!handle) throw new Error(t("install:script_info_load_failed"));

0 commit comments

Comments
 (0)