系统配置页新增「版本与更新」卡片,顶栏版本号旁在有新版时亮出提示胶囊。 更新链路:下载发布包 → 比对 SHA256SUMS → -h 冒烟测试 → 暂存 artex.new → 以退出码 75 退出 → 守护脚本重新拉起并完成换装,页面轮询 /api/health 等版本号变化后自动刷新。 新增 start.sh / start.bat 作为正式启动入口,只按退出码决定是否重新拉起 (0 停止 / 75 应用新版 / 其余崩溃退避)。校验、冒烟、换装、回滚全部收在 selfupdate 包里而不写进脚本:这些逻辑在 sh 和 bat 上要写两套,而它们恰恰 最不能出错——换上跑不起来的二进制后守护进程会反复拉起它,只能上机器手工救。 Docker 的 ENTRYPOINT 一并改为该脚本,并由它转发 SIGTERM,否则 docker stop 只发给 PID 1,artex 做不了优雅关闭会被 SIGKILL 硬杀。 失败保护两道闸门互补:无法 exec 由换装前的冒烟挡住,能执行但初始化崩溃 由启动计数兜住(连续 3 次失败自动回滚 artex.old,坏的留作 artex.failed)。 GitHub 查询结果后端缓存 30 分钟(失败 2 分钟)。未认证 API 是每 IP 每小时 60 次,且这 60 次是服务器 IP 上所有用户共用的,顶栏每次整页加载都查一次, 不缓存会很快耗光配额导致真想更新时反而查不动。手动「检查更新」带 force=1 绕过缓存。 安全:只认 GitHub 域名且强制 HTTPS(逐跳校验重定向),发布源写死不可配置; 升级文件挂在可执行文件所在目录而非 CWD(服务化运行时 CWD 可能是 /); 开发构建版本号不可比较,禁用一键更新。 走完整 zip 而非裸二进制,因为现有 Release 的 SHA256SUMS 只覆盖 zip, 这样无需改 CI,也兼容已发布的历史版本。 已知限制:Docker 下只换程序不换镜像(工具链不同步、重建容器会退回镜像 版本);不同步发布包里的 skills/;更新即重启会中断运行中的任务。
81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
"use client";
|
|
|
|
import { type ReactNode, useEffect, useState } from "react";
|
|
|
|
import { usePathname } from "next/navigation";
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
|
import { SidebarTrigger } from "@/components/ui/sidebar";
|
|
import { useCurrentUser } from "@/hooks/use-current-user";
|
|
import { api } from "@/lib/api";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
import { AccountSwitcher } from "./sidebar/account-switcher";
|
|
import { LayoutControls } from "./sidebar/layout-controls";
|
|
import { SearchDialog } from "./sidebar/search-dialog";
|
|
import { ThemeSwitcher } from "./sidebar/theme-switcher";
|
|
import { UpdateBadge } from "./update-badge";
|
|
|
|
// 任务详情页保持原样:它自带头部/Tabs 与内边距,这里不再叠加全局头部和 padding。
|
|
function isFullBleed(pathname: string) {
|
|
const p = (() => {
|
|
try {
|
|
return decodeURIComponent(pathname);
|
|
} catch {
|
|
return pathname;
|
|
}
|
|
})();
|
|
return p.startsWith("/function/tasks/");
|
|
}
|
|
|
|
export function MainContent({ children }: { children: ReactNode }) {
|
|
const currentUser = useCurrentUser();
|
|
const pathname = usePathname();
|
|
const [version, setVersion] = useState("");
|
|
|
|
useEffect(() => {
|
|
api
|
|
.health()
|
|
.then((h) => setVersion((h.version ?? "").replace(/^v(?=\d)/, "")))
|
|
.catch(() => setVersion(""));
|
|
}, []);
|
|
|
|
if (isFullBleed(pathname)) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<header
|
|
className={cn(
|
|
"flex h-12 shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12",
|
|
"[html[data-navbar-style=sticky]_&]:sticky [html[data-navbar-style=sticky]_&]:top-0 [html[data-navbar-style=sticky]_&]:z-50 [html[data-navbar-style=sticky]_&]:overflow-hidden [html[data-navbar-style=sticky]_&]:rounded-t-[inherit] [html[data-navbar-style=sticky]_&]:bg-background/50 [html[data-navbar-style=sticky]_&]:backdrop-blur-md",
|
|
)}
|
|
>
|
|
<div className="flex w-full items-center justify-between px-4 lg:px-6">
|
|
<div className="flex items-center gap-1 lg:gap-2">
|
|
<SidebarTrigger className="-ml-1" />
|
|
<Separator
|
|
orientation="vertical"
|
|
className="mx-2 data-[orientation=vertical]:h-4 data-[orientation=vertical]:self-center"
|
|
/>
|
|
<SearchDialog />
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
{version && (
|
|
<span className="font-medium text-muted-foreground text-xs tabular-nums">版本 · {version}</span>
|
|
)}
|
|
<UpdateBadge />
|
|
<LayoutControls />
|
|
<ThemeSwitcher />
|
|
<AccountSwitcher users={[currentUser]} />
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<div className="min-h-0 min-w-0 flex-1 overflow-x-hidden p-4 has-data-[content-padding=false]:p-0 md:p-6 md:has-data-[content-padding=false]:p-0">
|
|
{children}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|