mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 16:00:09 +08:00
refactor(app-data): split monolithic context into focused SWR hooks (#5576)
* refactor(app-data): split monolithic context into focused SWR hooks * refactor(swr): unify polling and consolidate proxy/config/provider data flow
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import { createContext, use } from "react";
|
||||
import {
|
||||
BaseConfig,
|
||||
ProxyProvider,
|
||||
Rule,
|
||||
RuleProvider,
|
||||
} from "tauri-plugin-mihomo-api";
|
||||
|
||||
export interface AppDataContextType {
|
||||
proxies: any;
|
||||
clashConfig: BaseConfig;
|
||||
rules: Rule[];
|
||||
sysproxy: any;
|
||||
runningMode?: string;
|
||||
uptime: number;
|
||||
proxyProviders: Record<string, ProxyProvider>;
|
||||
ruleProviders: Record<string, RuleProvider>;
|
||||
systemProxyAddress: string;
|
||||
|
||||
refreshProxy: () => Promise<any>;
|
||||
refreshClashConfig: () => Promise<any>;
|
||||
refreshRules: () => Promise<any>;
|
||||
refreshSysproxy: () => Promise<any>;
|
||||
refreshProxyProviders: () => Promise<any>;
|
||||
refreshRuleProviders: () => Promise<any>;
|
||||
refreshAll: () => Promise<any>;
|
||||
}
|
||||
|
||||
export interface ConnectionWithSpeed extends IConnectionsItem {
|
||||
curUpload: number;
|
||||
curDownload: number;
|
||||
}
|
||||
|
||||
export interface ConnectionSpeedData {
|
||||
id: string;
|
||||
upload: number;
|
||||
download: number;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export const AppDataContext = createContext<AppDataContextType | null>(null);
|
||||
|
||||
export const useAppData = () => {
|
||||
const context = use(AppDataContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useAppData必须在AppDataProvider内使用");
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user