Skip to content

Commit 16c104c

Browse files
committed
feat(version): remove mock function
1 parent 90ce6c8 commit 16c104c

1 file changed

Lines changed: 5 additions & 77 deletions

File tree

web/src/components/layout/update-chip.tsx

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -48,64 +48,16 @@ type UpdateState =
4848
const COUNTDOWN_SECONDS = 15;
4949
const LAST_CHECK_KEY = "nodepass-last-update-check";
5050

51-
// ─── Mock mode (visual QA) ──────────────────────────────────────────
52-
// 在 URL 上加 ?mock-update=has-update | update-complete | restarting
53-
// 可在不触发后端的情况下预览 chip + popover 各状态。
54-
// 例如:http://localhost:3000/dashboard?mock-update=has-update
55-
function readMockState(): UpdateState | null {
56-
if (typeof window === "undefined") return null;
57-
const sp = new URLSearchParams(window.location.search);
58-
const v = sp.get("mock-update");
59-
if (!v) return null;
60-
if (
61-
v === "has-update" ||
62-
v === "updating" ||
63-
v === "update-complete" ||
64-
v === "restarting" ||
65-
v === "error"
66-
) {
67-
return v as UpdateState;
68-
}
69-
return null;
70-
}
71-
72-
const MOCK_CURRENT = "v0.1.119";
73-
const MOCK_LATEST = "v0.1.121";
74-
7551
export function UpdateChip() {
7652
const { t } = useTranslation("settings");
7753
const { settings } = useSettings();
7854

79-
const mockState = useMemo(() => readMockState(), []);
80-
const isMock = mockState !== null;
81-
82-
const [currentVersion, setCurrentVersion] = useState<string>(
83-
isMock ? MOCK_CURRENT : "",
84-
);
85-
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(
86-
isMock
87-
? {
88-
current: { current: MOCK_CURRENT, os: "linux", arch: "amd64" },
89-
stable: {
90-
tag_name: MOCK_LATEST,
91-
name: MOCK_LATEST,
92-
body: "",
93-
published_at: new Date().toISOString(),
94-
html_url: "https://github.com/NodePassProject/NodePassDash/releases/latest",
95-
prerelease: false,
96-
draft: false,
97-
},
98-
hasStableUpdate: true,
99-
hasBetaUpdate: false,
100-
}
101-
: null,
102-
);
103-
const [state, setState] = useState<UpdateState>(mockState ?? "idle");
104-
const [errorMsg, setErrorMsg] = useState<string>(
105-
isMock && mockState === "error" ? "模拟错误信息" : "",
106-
);
55+
const [currentVersion, setCurrentVersion] = useState<string>("");
56+
const [updateInfo, setUpdateInfo] = useState<UpdateInfo | null>(null);
57+
const [state, setState] = useState<UpdateState>("idle");
58+
const [errorMsg, setErrorMsg] = useState<string>("");
10759
const [countdown, setCountdown] = useState<number>(COUNTDOWN_SECONDS);
108-
const [popoverOpen, setPopoverOpen] = useState(isMock);
60+
const [popoverOpen, setPopoverOpen] = useState(false);
10961
const [checking, setChecking] = useState(false);
11062

11163
const countdownRef = useRef<ReturnType<typeof setInterval> | null>(null);
@@ -135,11 +87,6 @@ export function UpdateChip() {
13587
// 检查更新逻辑(供按钮和初次加载共用)
13688
const runCheck = useCallback(
13789
async (opts?: { force?: boolean }) => {
138-
if (isMock) {
139-
setChecking(true);
140-
setTimeout(() => setChecking(false), 700); // 仅做 loading 动画演示
141-
return;
142-
}
14390
setChecking(true);
14491
try {
14592
const cur = await fetchCurrent();
@@ -177,7 +124,6 @@ export function UpdateChip() {
177124
// 初次加载:总是请求当前版本(发现 restartPending 时立刻进入完成状态);
178125
// 如开启自动检查 + 当天未检查,顺便拉一次远端
179126
useEffect(() => {
180-
if (isMock) return; // mock 模式跳过真实请求
181127
let cancelled = false;
182128
(async () => {
183129
const cur = await fetchCurrent();
@@ -227,11 +173,6 @@ export function UpdateChip() {
227173
const handleUpdate = async () => {
228174
setState("updating");
229175
setErrorMsg("");
230-
if (isMock) {
231-
// 模拟 2s 下载/替换,然后进入"待重启"状态
232-
setTimeout(() => setState("update-complete"), 2000);
233-
return;
234-
}
235176
try {
236177
const type = updateInfo?.hasStableUpdate ? "stable" : "beta";
237178
const res = await fetch(buildApiUrl("/api/version/auto-update"), {
@@ -283,11 +224,6 @@ export function UpdateChip() {
283224
};
284225

285226
const triggerRestart = async () => {
286-
if (isMock) {
287-
// 倒计时归零后,mock 模式回到 has-update 让你重新试
288-
setTimeout(() => setState("has-update"), 1500);
289-
return;
290-
}
291227
try {
292228
await fetch(buildApiUrl("/api/version/restart"), { method: "POST" });
293229
} catch {
@@ -320,14 +256,6 @@ export function UpdateChip() {
320256
[],
321257
);
322258

323-
// mock=restarting 时自动启动倒计时,方便预览
324-
useEffect(() => {
325-
if (isMock && mockState === "restarting") {
326-
startCountdown();
327-
}
328-
// eslint-disable-next-line react-hooks/exhaustive-deps
329-
}, []);
330-
331259
const showChip = state !== "idle";
332260
if (!showChip) return null;
333261

0 commit comments

Comments
 (0)