Compare commits

...
4 Commits
Author SHA1 Message Date
Qiufeng a080f531cd release: 1.2.3
TallyNote release / linux-x64 (push) Successful in 6m47s
2026-09-05 10:31:29 +08:00
Qiufeng 1e87f25c2b fix: remove update page mock controls 2026-09-05 10:22:25 +08:00
Qiufeng 4c71861813 fix: prevent duplicate update submissions
TallyNote release / linux-x64 (push) Successful in 6m47s
2026-09-05 10:08:49 +08:00
Qiufeng 3a9f809f46 fix: show update rate limits as toast
TallyNote release / linux-x64 (push) Successful in 6m42s
2026-09-05 09:39:10 +08:00
4 changed files with 20 additions and 450 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "tallynote",
"version": "1.2.0",
"version": "1.2.3",
"private": true,
"type": "module",
"packageManager": "pnpm@9.0.6",
+19 -90
View File
@@ -21,19 +21,14 @@ import {
X,
FileCode,
HardDrive,
Terminal,
} from "lucide-react";
import { Button, Card, Dialog, RadioGroup, Radio, Steps, Tag, Tooltip } from "tdesign-react";
import { Button, Card, Dialog, Steps, Tag, Tooltip } from "tdesign-react";
import { Page, Surface } from "../common";
import { api } from "../../services/api";
import { api, ApiError } from "../../services/api";
import { dateText } from "../../utils/date";
import type { MockScenario, MockUpdateState } from "./mockData";
const { StepItem } = Steps;
// Enable mock preview in local development
const MOCK_PREVIEW_ENABLED = import.meta.env.DEV;
export type JobStatus =
| "queued"
| "downloading"
@@ -234,14 +229,8 @@ export default function UpdatePage({
timezone?: string;
notify?: (msg: string, type?: "success" | "info" | "error") => void;
}) {
// Mock mode switcher for local developer preview
const [mockScenario, setMockScenario] = useState<"live" | MockScenario>("live");
const mockTimer = useRef<number | null>(null);
const [mockCatalog, setMockCatalog] = useState<Record<MockScenario, MockUpdateState> | null>(null);
// Live state
const [liveInfo, setLiveInfo] = useState<UpdateInfo | null>(null);
const [mockInfoState, setMockInfoState] = useState<UpdateInfo | null>(null);
const [loading, setLoading] = useState(true);
const [checking, setChecking] = useState(false);
const [error, setError] = useState("");
@@ -262,46 +251,9 @@ export default function UpdatePage({
const disconnected = useRef(false);
const recoveredNotice = useRef(false);
// Active info depending on mock vs live
const isMock = MOCK_PREVIEW_ENABLED && mockScenario !== "live" && Boolean(mockCatalog);
const selectedMock = mockScenario !== "live" ? mockCatalog?.[mockScenario] : undefined;
const info = isMock && selectedMock ? (mockInfoState ?? selectedMock.info) : liveInfo;
// Handle mock scenario change
const handleScenarioChange = (scenario: "live" | MockScenario) => {
setMockScenario(scenario);
if (mockTimer.current !== null) {
window.clearTimeout(mockTimer.current);
mockTimer.current = null;
}
if (scenario !== "live") {
const next = mockCatalog?.[scenario];
if (!next) return;
setMockInfoState(JSON.parse(JSON.stringify(next.info)));
notify?.(`已切换至 Mock 场景:${next.title}`, "info");
} else {
setMockInfoState(null);
notify?.("已切回真实后端模式", "info");
}
};
useEffect(() => () => {
if (mockTimer.current !== null) window.clearTimeout(mockTimer.current);
}, []);
useEffect(() => {
if (!import.meta.env.DEV) return;
let disposed = false;
void import("./mockData").then(({ MOCK_SCENARIOS }) => {
if (!disposed) setMockCatalog(MOCK_SCENARIOS);
});
return () => {
disposed = true;
};
}, []);
const info = liveInfo;
const load = async () => {
if (isMock) return;
setLoading(true);
setError("");
try {
@@ -316,9 +268,8 @@ export default function UpdatePage({
};
useEffect(() => {
if (!isMock) void load();
else setLoading(false);
}, [isMock]);
void load();
}, []);
// Keep terminal jobs visible so operators can understand what happened and
// recover without guessing. The polling effect below only polls active jobs.
@@ -344,7 +295,6 @@ export default function UpdatePage({
// Live polling effect: only poll when active job exists
useEffect(() => {
if (isMock) return;
const shouldPoll = Boolean(
job && (pollableStatuses.has(job.status) || (job.status === "staged" && job.operation === "apply"))
);
@@ -400,18 +350,10 @@ export default function UpdatePage({
disposed = true;
if (timer !== undefined) window.clearTimeout(timer);
};
}, [isMock, job?.id, job?.status, job?.operation, notify]);
}, [job?.id, job?.status, job?.operation, notify]);
// Check update handler
const check = async () => {
if (isMock) {
setChecking(true);
window.setTimeout(() => {
setChecking(false);
notify?.("Mock:检查完成,已是最新配置状态", "success");
}, 600);
return;
}
if (checkInFlight.current) return;
checkInFlight.current = true;
setChecking(true);
@@ -420,7 +362,11 @@ export default function UpdatePage({
setLiveInfo(await api<UpdateInfo>("/api/update/check", { method: "POST" }));
notify?.("版本检查完成", "info");
} catch (e) {
setError((e as Error).message);
if (e instanceof ApiError && e.status === 429) {
notify?.((e as Error).message, "error");
} else {
setError((e as Error).message);
}
} finally {
setChecking(false);
checkInFlight.current = false;
@@ -446,7 +392,8 @@ export default function UpdatePage({
// Start download action
const startDownload = async () => {
if (!latest) return;
if (!latest || actionInFlight.current || hasActiveJob || canApply) return;
actionInFlight.current = true;
setActionBusy(true);
setError("");
setModalError("");
@@ -465,12 +412,14 @@ export default function UpdatePage({
notify?.(msg, "error");
} finally {
setActionBusy(false);
actionInFlight.current = false;
}
};
// Start apply action
const startApply = async () => {
if (!latest) return;
if (!latest || !job || job.status !== "staged" || job.operation !== "download" || actionInFlight.current) return;
actionInFlight.current = true;
setActionBusy(true);
setError("");
setModalError("");
@@ -488,6 +437,7 @@ export default function UpdatePage({
notify?.(msg, "error");
} finally {
setActionBusy(false);
actionInFlight.current = false;
}
};
@@ -718,7 +668,7 @@ export default function UpdatePage({
</div>
<div className="tn-ascii-info-item">
<span className="tn-ascii-info-label">下载策略:</span>
<span className="tn-ascii-info-val">应用内流式直连 (零调度等待)</span>
<span className="tn-ascii-info-val">系统更新服务接管</span>
</div>
</div>
@@ -991,7 +941,7 @@ export default function UpdatePage({
<div className="tn-modal-card-box" style={{ background: "rgba(47, 125, 92, 0.04)", border: "1px solid rgba(47, 125, 92, 0.25)" }}>
<div className="tn-modal-card-title" style={{ color: "#2f7d5c", display: "flex", alignItems: "center", gap: 8 }}>
<CheckCircle2 size={22} />
恭喜!系统已成功平滑升级至 v{latest?.version || info.currentVersion}。
恭喜!系统已成功平滑升级至 v{latest?.version || info?.currentVersion || "当前版本"}。
</div>
<p style={{ fontSize: "13.5px", color: "var(--tn-text)", margin: "8px 0 16px" }}>
服务健康检查已全部通过,所有账目数据与发票凭证均完好无损。请点击下方按钮完成控制台刷新。
@@ -1035,27 +985,6 @@ export default function UpdatePage({
)}
</div> </Dialog>
{/* Floating Mock Dock (Bottom-right, zero interference with main page) */}
{MOCK_PREVIEW_ENABLED && (
<aside className="tn-dev-mock-dock" aria-label="开发预览控制台">
<Terminal size={14} />
<strong>Mock:</strong>
<RadioGroup
variant="default-filled"
size="small"
value={mockScenario}
onChange={(value) => handleScenarioChange(value as "live" | MockScenario)}
>
<Radio.Button value="live">真实</Radio.Button>
{mockCatalog &&
Object.entries(mockCatalog).map(([key, item]) => (
<Radio.Button key={key} value={key}>
{item.title.split("(")[0]}
</Radio.Button>
))}
</RadioGroup>
</aside>
)}
</Page>
);
}
-283
View File
@@ -1,283 +0,0 @@
export type MockScenario =
| "latest" // 已是最新
| "available" // 发现新版本(待下载)
| "downloading_30" // 下载中 30%
| "downloading_85" // 下载中 85% + 高速
| "staged" // 下载完成已校验,待立即更新
| "backing_up" // 正在备份数据
| "applying" // 正在原子切换并重启中(倒计时)
| "completed" // 更新完成
| "failed_verify" // 完整性校验失败
| "disabled"; // 手动模式未配置源
export interface MockUpdateState {
info: any;
title: string;
description: string;
}
export const MOCK_SCENARIOS: Record<MockScenario, MockUpdateState> = {
latest: {
title: "版本健康(已是最新)",
description: "展示当前运行版本已是最新,各项指标正常,无待处理任务",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 600_000,
latest: {
version: "1.1.22",
tagName: "v1.1.22",
releaseName: "v1.1.22 稳定版",
publishedAt: new Date(Date.now() - 3600_000 * 24).toISOString(),
compatible: true,
integrityReady: true,
signatureReady: true,
isNewer: false,
assetName: "tallynote-1.1.22-linux-x64-glibc.tar.gz",
assetSize: 120540160,
notes: "### TallyNote 1.1.22\n\n- 优化反向代理下登录兼容性\n- 增强安全审计与防重放机制\n- 前端组件性能深度优化",
},
job: null,
},
},
available: {
title: "发现新版本(待下载)",
description: "检查到官方发布了更高版本,显示更新日志与文件校验信息,可点击下载",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 60_000,
latest: {
version: "1.1.23",
tagName: "v1.1.23",
releaseName: "v1.1.23 重大更新",
publishedAt: new Date(Date.now() - 1800_000).toISOString(),
compatible: true,
integrityReady: true,
signatureReady: true,
isNewer: true,
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
assetSize: 121000000,
notes: "### TallyNote 1.1.23\n\n- 【新功能】系统更新中心全面重构,支持动态速率流光进度条与平滑重启倒计时\n- 【交互】优化抽屉展开动效与手机端自适应导航\n- 【安全】发布包支持双重 Ed25519 签名与 SHA-256 清单交叉校验",
},
job: null,
},
},
downloading_30: {
title: "下载更新中(进度 38%)",
description: "展示真实下载速率、已下载字节数与动态流光进度条",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: {
version: "1.1.23",
tagName: "v1.1.23",
compatible: true,
integrityReady: true,
signatureReady: true,
isNewer: true,
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
assetSize: 121000000,
},
job: {
id: "mock-job-001",
operation: "download",
status: "downloading",
version: "1.1.23",
platform: "x64/glibc",
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
sizeBytes: 121000000,
downloadedBytes: 46200000,
downloadStartedAt: Date.now() - 10000,
downloadSpeedBps: 8800000, // 8.4 MB/s
createdAt: Date.now() - 10000,
updatedAt: Date.now(),
},
},
},
downloading_85: {
title: "下载冲刺中(进度 88%)",
description: "高速冲刺状态,即将触发 SHA-256 校验",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: {
version: "1.1.23",
tagName: "v1.1.23",
compatible: true,
integrityReady: true,
signatureReady: true,
isNewer: true,
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
assetSize: 121000000,
},
job: {
id: "mock-job-002",
operation: "download",
status: "downloading",
version: "1.1.23",
platform: "x64/glibc",
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
sizeBytes: 121000000,
downloadedBytes: 106480000,
downloadStartedAt: Date.now() - 15000,
downloadSpeedBps: 12500000, // 11.9 MB/s
createdAt: Date.now() - 15000,
updatedAt: Date.now(),
},
},
},
staged: {
title: "下载完成(待立即应用)",
description: "更新包与签名均已校验就绪,随时可以安全点击【立即更新】",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: {
version: "1.1.23",
tagName: "v1.1.23",
compatible: true,
integrityReady: true,
signatureReady: true,
isNewer: true,
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
assetSize: 121000000,
notes: "### TallyNote 1.1.23\n\n- 更新包已完整解压检验通过,具备升级条件。",
},
job: {
id: "mock-job-003",
operation: "download",
status: "staged",
version: "1.1.23",
platform: "x64/glibc",
assetName: "tallynote-1.1.23-linux-x64-glibc.tar.gz",
sizeBytes: 121000000,
downloadedBytes: 121000000,
createdAt: Date.now() - 60000,
updatedAt: Date.now() - 5000,
},
},
},
backing_up: {
title: "数据备份中(更新保护)",
description: "正在为系统数据生成安全快照备份",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: { version: "1.1.23", tagName: "v1.1.23", compatible: true, integrityReady: true, signatureReady: true, isNewer: true },
job: {
id: "mock-job-004",
operation: "apply",
status: "backing_up",
version: "1.1.23",
platform: "x64/glibc",
createdAt: Date.now() - 20000,
updatedAt: Date.now() - 2000,
},
},
},
applying: {
title: "服务平滑重启中(倒计时中)",
description: "已安全切换版本,服务正在热重启并检验状态",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: { version: "1.1.23", tagName: "v1.1.23", compatible: true, integrityReady: true, signatureReady: true, isNewer: true },
job: {
id: "mock-job-005",
operation: "apply",
status: "applying",
version: "1.1.23",
platform: "x64/glibc",
applyQueuedAt: Date.now() - 12000,
restartWindowSeconds: 30,
restartDeadline: Date.now() + 18000,
createdAt: Date.now() - 25000,
updatedAt: Date.now() - 2000,
},
},
},
completed: {
title: "更新成功完成",
description: "新版本健康检查通过,已平滑无感升级至最新",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.23",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 30_000,
latest: { version: "1.1.23", tagName: "v1.1.23", compatible: true, integrityReady: true, signatureReady: true, isNewer: false },
job: {
id: "mock-job-006",
operation: "apply",
status: "completed",
version: "1.1.23",
platform: "x64/glibc",
completedAt: Date.now() - 10000,
createdAt: Date.now() - 45000,
updatedAt: Date.now() - 10000,
},
},
},
failed_verify: {
title: "更新失败状态(安全拦截)",
description: "模拟签名不匹配或发布包篡改时的安全拦截展示与错误提示",
info: {
configured: true,
strategy: "systemd",
currentVersion: "1.1.22",
platform: { target: "x64/glibc", os: "linux", arch: "x64" },
checkedAt: Date.now() - 120_000,
latest: {
version: "1.1.23",
tagName: "v1.1.23",
compatible: true,
integrityReady: false,
signatureReady: false,
isNewer: true,
},
job: {
id: "mock-job-007",
operation: "download",
status: "failed",
version: "1.1.23",
platform: "x64/glibc",
errorMessage: "发布包 SHA-256 校验与清单不一致,系统已自动阻断并保护原有数据。",
createdAt: Date.now() - 30000,
updatedAt: Date.now() - 5000,
},
},
},
disabled: {
title: "手动源码模式",
description: "未启用后台守护时的更新提示与引导说明",
info: {
configured: false,
strategy: "disabled",
currentVersion: "1.1.22",
platform: { target: "macOS/darwin", os: "darwin", arch: "arm64" },
checkedAt: Date.now() - 3600_000,
latest: null,
job: null,
},
},
};
-76
View File
@@ -802,61 +802,6 @@ input:focus-visible, textarea:focus-visible, select:focus-visible {
TallyNote Update Center (Redesigned UI & Interactive Styles)
========================================================================== */
/* Mock Console Controller */
.tn-mock-console {
margin-bottom: 16px;
padding: 14px 18px;
background: #f8fbff;
border: 1px dashed var(--td-brand-color-3);
border-radius: 4px;
}
.tn-mock-console-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 12px;
}
.tn-mock-console-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: var(--tn-navy-900);
}
.tn-mock-console-tip {
font-size: 12px;
color: var(--tn-text-secondary);
}
.tn-mock-scenario-chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tn-scenario-chip {
padding: 5px 11px;
font-size: 12px;
border: 1px solid var(--tn-border);
border-radius: 3px;
background: #ffffff;
color: var(--tn-text-secondary);
cursor: pointer;
transition: all 0.16s ease;
}
.tn-scenario-chip:hover {
border-color: var(--td-brand-color-4);
color: var(--td-brand-color);
background: var(--td-brand-color-1);
}
.tn-scenario-chip.active {
background: var(--td-brand-color);
border-color: var(--td-brand-color);
color: #ffffff;
font-weight: 600;
box-shadow: 0 2px 6px rgba(23, 92, 211, 0.2);
}
/* Update Page Actions */
.tn-update-page-actions {
display: flex;
@@ -1272,10 +1217,6 @@ input:focus-visible, textarea:focus-visible, select:focus-visible {
.tn-update-metrics-grid {
grid-template-columns: 1fr;
}
.tn-mock-console-header {
flex-direction: column;
align-items: flex-start;
}
.tn-release-header {
flex-direction: column;
}
@@ -1651,23 +1592,6 @@ input:focus-visible, textarea:focus-visible, select:focus-visible {
gap: 6px;
}
/* Compact Floating Mock Switcher at bottom-right instead of giant top banner */
.tn-dev-mock-dock {
position: fixed;
bottom: 16px;
right: 16px;
z-index: 999;
background: #ffffff;
border: 1px solid var(--td-brand-color);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
border-radius: 4px;
padding: 8px 12px;
display: flex;
align-items: center;
gap: 10px;
font-size: 12px;
}
/* ============================================================
方案二:平滑极光光流条 (Beam Bar / Shimmer) 全局动效规范