summaryrefslogtreecommitdiff
path: root/src/store/types.ts
blob: d12adaaedbce119b234f1b70abb52586865ce7a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type { ClashAPIConfig } from 'src/types';

export type ClashAPIConfigWithAddedAt = ClashAPIConfig & { addedAt?: number };
export type StateApp = {
  selectedClashAPIConfigIndex: number;
  clashAPIConfigs: ClashAPIConfigWithAddedAt[];

  latencyTestUrl: string;
  selectedChartStyleIndex: number;
  theme: string;

  collapsibleIsOpen: Record<string, boolean>;
  proxySortBy: string;
  hideUnavailableProxies: boolean;
  autoCloseOldConns: boolean;
  logStreamingPaused: boolean;
};

export type ClashGeneralConfig = {
  port: number;
  'socks-port': number;
  'redir-port': number;
  'allow-lan': boolean;
  mode: string;
  'log-level': string;
};

///// store.proxies

type LatencyHistory = Array<{ time: string; delay: number }>;
type PrimitiveProxyType = 'Shadowsocks' | 'Snell' | 'Socks5' | 'Http' | 'Vmess';
export type ProxyItem = {
  name: string;
  type: PrimitiveProxyType;
  history: LatencyHistory;
  all?: string[];
  now?: string;
};
export type ProxiesMapping = Record<string, ProxyItem>;
export type DelayMapping = Record<string, { number?: number }>;

export type ProxyProvider = {
  name: string;
  type: 'Proxy';
  updatedAt: string;
  vehicleType: 'HTTP' | 'File' | 'Compatible';
  proxies: Array<ProxyItem>;
};

export type FormattedProxyProvider = Omit<ProxyProvider, 'proxies'> & {
  proxies: string[];
};

export type SwitchProxyCtxItem = { groupName: string; itemName: string };
type SwitchProxyCtx = {
  to: SwitchProxyCtxItem;
};
export type StateProxies = {
  proxies: ProxiesMapping;
  delay: DelayMapping;
  groupNames: string[];
  proxyProviders?: FormattedProxyProvider[];
  dangleProxyNames?: string[];

  showModalClosePrevConns: boolean;
  switchProxyCtx?: SwitchProxyCtx;
};

///// store.logs

export type Log = {
  time: string;
  even: boolean;
  payload: string;
  type: string;
  id: string;
};

export type StateLogs = {
  searchText: string;
  logs: Log[];
  tail: number;
};

///// store.configs

export type StateConfigs = {
  configs: ClashGeneralConfig;
  haveFetchedConfig: boolean;
};

///// store.modals

export type StateModals = {
  apiConfig: boolean;
};

//////

export type State = {
  app: StateApp;
  configs: StateConfigs;
  proxies: StateProxies;
  logs: StateLogs;
  modals: StateModals;
};

export type GetStateFn = () => State;
export interface DispatchFn {
  (msg: string, change: (s: State) => void): void;
  (action: (dispatch: DispatchFn, getState: GetStateFn) => Promise<void>): ReturnType<
    typeof action
  >;
  (action: (dispatch: DispatchFn, getState: GetStateFn) => void): ReturnType<typeof action>;
}