Add owner-aware Stable and Preview updates with explicit consent, verified release plans, protected process handoff and bounded service recovery. Keep configuration and conversations separate from program rollback. Include the compact About controls, Windows long-path support, native package recovery checks and optional macOS Dock lifecycle integration. Preserve documented guidance for installations owned by other managers. This code integration does not publish packages, enable signing or advance the public update channel. Co-authored-by: chengyongru <61816729+chengyongru@users.noreply.github.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useMemo,
|
|
useRef,
|
|
type ReactNode,
|
|
} from "react";
|
|
|
|
import type { NanobotClient } from "@/lib/nanobot-client";
|
|
import type { WebUIIngressLimits } from "@/lib/types";
|
|
import { VersionCheckProvider } from "@/providers/VersionCheckProvider";
|
|
import { UpdateFlowProvider } from "@/providers/UpdateFlowProvider";
|
|
|
|
interface ClientContextValue {
|
|
client: NanobotClient;
|
|
token: string;
|
|
getToken: () => string;
|
|
modelName: string | null;
|
|
ingressLimits: WebUIIngressLimits | null;
|
|
webuiCapabilities: string[];
|
|
}
|
|
|
|
const ClientContext = createContext<ClientContextValue | null>(null);
|
|
|
|
export function ClientProvider({
|
|
client,
|
|
token,
|
|
modelName = null,
|
|
ingressLimits = null,
|
|
webuiCapabilities = [],
|
|
checkUpdatesOnConnect = false,
|
|
allowUpdateFlow = true,
|
|
children,
|
|
}: {
|
|
client: NanobotClient;
|
|
token: string;
|
|
modelName?: string | null;
|
|
ingressLimits?: WebUIIngressLimits | null;
|
|
webuiCapabilities?: string[];
|
|
checkUpdatesOnConnect?: boolean;
|
|
allowUpdateFlow?: boolean;
|
|
children: ReactNode;
|
|
}) {
|
|
const tokenRef = useRef(token);
|
|
tokenRef.current = token;
|
|
const getToken = useCallback(() => tokenRef.current, []);
|
|
const value = useMemo(
|
|
() => ({ client, token, getToken, modelName, ingressLimits, webuiCapabilities }),
|
|
[client, getToken, ingressLimits, modelName, token, webuiCapabilities],
|
|
);
|
|
|
|
return (
|
|
<ClientContext.Provider value={value}>
|
|
<VersionCheckProvider token={token} client={client} autoCheck={checkUpdatesOnConnect}
|
|
channels={allowUpdateFlow && webuiCapabilities.includes("webui.update-channels.v1")}>
|
|
<UpdateFlowProvider client={client} token={token} enabled={allowUpdateFlow && webuiCapabilities.includes("webui.update-flow.v1")}
|
|
canSettleHandoff={webuiCapabilities.includes("webui.update-jobs.settle-handoff.v1")}>
|
|
{children}
|
|
</UpdateFlowProvider>
|
|
</VersionCheckProvider>
|
|
</ClientContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useClient(): ClientContextValue {
|
|
const ctx = useContext(ClientContext);
|
|
if (!ctx) {
|
|
throw new Error("useClient must be used within a ClientProvider");
|
|
}
|
|
return ctx;
|
|
}
|