Advisory, read-only update check: the core polls GitHub's latest stable release, compares it against the running build, and surfaces a notice in the sidebar footer plus a detailed card (changelog + download link + platform-matched asset hint) in Settings → About. SnowLuma never downloads or applies anything itself — cross-platform self-update is a minefield (Windows locks loaded .node/.dll, Docker bakes the app into image layers, bare installs have no supervisor), so the user downloads and applies manually. The backend caches results for 6h to stay under GitHub's unauthenticated rate limit, degrades silently on failure, and can be disabled via SNOWLUMA_UPDATE_CHECK=0.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { createContext, useContext, type ReactNode } from 'react';
|
|
import type { AccountConnections, HookProcessInfo, QQInfo, SystemInfo, UpdateInfo } from '@/types';
|
|
import type { HookProcessOps } from '@/hooks/use-hook-process-ops';
|
|
|
|
/**
|
|
* Live mutable state owned by AppLayout and shared with the child route
|
|
* components rendered inside its `<Outlet />`. Pages used to receive these
|
|
* via prop drilling — now they pull from context so adding a new page does
|
|
* not touch AppLayout.
|
|
*/
|
|
export interface AppStateValue {
|
|
qqList: QQInfo[];
|
|
processList: HookProcessInfo[];
|
|
systemInfo: SystemInfo | null;
|
|
connections: AccountConnections[];
|
|
/** Advisory update-availability info; null until the first check resolves. */
|
|
updateInfo: UpdateInfo | null;
|
|
selectedUin: string | null;
|
|
setSelectedUin: (uin: string | null) => void;
|
|
processOps: HookProcessOps;
|
|
refreshProcesses: () => void;
|
|
refreshSystem: () => void;
|
|
refreshConnections: () => void;
|
|
/** Re-run the update check; `force` bypasses the server-side cache. */
|
|
refreshUpdate: (force?: boolean) => Promise<void>;
|
|
/** Triggered from the topbar logout button. */
|
|
onLogout: () => void;
|
|
}
|
|
|
|
const AppStateContext = createContext<AppStateValue | null>(null);
|
|
|
|
export function AppStateProvider({
|
|
value,
|
|
children,
|
|
}: {
|
|
value: AppStateValue;
|
|
children: ReactNode;
|
|
}) {
|
|
return <AppStateContext.Provider value={value}>{children}</AppStateContext.Provider>;
|
|
}
|
|
|
|
export function useAppState(): AppStateValue {
|
|
const v = useContext(AppStateContext);
|
|
if (!v) throw new Error('useAppState must be used inside <AppStateProvider>');
|
|
return v;
|
|
}
|