-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathplugins.d.ts
More file actions
418 lines (397 loc) · 13.9 KB
/
plugins.d.ts
File metadata and controls
418 lines (397 loc) · 13.9 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
type Recordable<T = any> = { [x: string]: T }
type MaybePromise<T> = T | Promise<T>
type Vue = typeof import('vue')
type UseModalOptions = Partial<{
open: boolean
title?: string
footer?: boolean
maxHeight?: string
maxWidth?: string
minWidth?: string
minHeight?: string
width?: string
height?: string
cancel?: boolean
submit?: boolean
cancelText?: string
submitText?: string
maskClosable?: boolean
onOk?: () => MaybePromise<boolean | void>
onCancel?: () => MaybePromise<boolean | void>
beforeClose?: (isOk: boolean) => MaybePromise<boolean | void>
afterClose?: (isOk: boolean) => void
}>
interface UseModalSlots {
title?: () => any
toolbar?: () => any
action?: () => any
cancel?: () => any
submit?: () => any
default?: () => any
}
// Custom Action
interface CustomActionApi {
h: Vue['h']
ref: Vue['ref']
}
type CustomActionProps = Recordable
type CustomActionSlots = Recordable<((api: CustomActionApi) => VNode | string | number | boolean) | VNode | string | number | boolean>
interface CustomAction<P = CustomActionProps, S = CustomActionSlots> {
id?: string
component: string
componentProps?: P | ((api: CustomActionApi) => P)
componentSlots?: S | ((api: CustomActionApi) => S)
}
type CustomActionFn = ((api: CustomActionApi) => CustomAction) & {
id?: string
}
interface Plugins {
APP_TITLE: string
APP_VERSION: string
YAML: {
parse(text: string): any
stringify(obj: any): string
}
SubStoreCache?: {
data: Record<string, any>
sync: () => void
get(key: string): any
set(key: string, value: any): void
remove(key: string): void
}
alert(title: string, content: string, options?: { type?: 'text' | 'markdown' }): Promise<void>
prompt(title: string, initialValue?: string, options?: { placeholder?: string; type?: string }): Promise<string>
confirm(
title: string,
content: string,
options?: {
type?: 'text' | 'markdown'
okText?: string
cancelText?: string
}
): Promise<boolean>
modal(
options?: UseModalOptions,
slots?: UseModalSlots
): {
destroy: () => void
} & {
open: () => void
close: () => void
setProps: (options: UseModalOptions) => void
patchProps: (options: Partial<UseModalOptions>) => void
setSlots: (slots: UseModalSlots) => void
patchSlots: (slots: UseModalSlots) => void
setComponent: (component: any) => void
setContent<C = any>(Comp: C, _props?: InstanceType<C>['$props'], _slots?: InstanceType<C>['$slots'], replace = true)
}
picker: {
multi(title: string, options: Array<{ label: string; value: any }>, initialValue?: any[]): Promise<any[]>
single(
title: string,
options: Array<{
label: string
value: any
description?: string
background?: string
onSelect?: (item: { value: any }) => void
}>,
initialValue?: any[]
): Promise<any>
}
message: {
success(msg: string, duration?: number): void
warn(msg: string, duration?: number): void
info(
msg: string,
duration?: number,
onClose?: () => void
): {
id: string | number
update: (msg: string, type?: string) => void
destroy: () => void
success: (msg: string) => void
error: (msg: string) => void
}
update(id: string | number, msg: string, type?: string): void
destroy(id: string | number): void
error(msg: string): void
}
OpenDir(path: string): Promise<void>
OpenURI(uri: string): Promise<void>
AbsolutePath(relativePath: string): Promise<string>
CopyFile(src: string, dest: string): Promise<void>
MakeDir(path: string): Promise<void>
ReadDir(path: string): Promise<Array<{ name: string; isDir: boolean; size: number }>>
FileExists(path: string): Promise<boolean>
RemoveFile(path: string): Promise<void>
MoveFile(src: string, dest: string): Promise<void>
ReadFile(path: string, options?: { Mode?: 'Binary' | 'Text'; Range?: string }): Promise<string>
WriteFile(path: string, content: string, options?: { Mode?: 'Binary' | 'Text'; Range?: string }): Promise<void>
UnzipGZFile(gzPath: string, destPath: string): Promise<void>
UnzipZIPFile(zipPath: string, destPath: string): Promise<void>
UnzipTarGZFile(targzPath: string, destPath: string): Promise<void>
ListServer(): Promise<string[]>
StopServer(id: string): Promise<void>
StartServer(
address: string,
serverId: string,
onRequest: (
req: {
url: string
method: string
headers: Record<string, string>
body: string
},
res: {
end: (status: number, headers: Record<string, string>, body: string, options?: { Mode: 'Binary' | 'Text' }) => void
}
) => void,
options?: {
StaticPath?: string
StaticRoute?: string
StaticHeaders?: Recordable
UploadPath?: string
UploadRoute?: string
UploadHeaders?: Recordable
MaxUploadSize?: number
}
): Promise<{ close: () => Promise<void> }>
ProcessInfo(pid: number): Promise<string>
ProcessMemory(pid: number): Promise<number>
KillProcess(pid: number, timeout?: number): Promise<void>
Exec(cmd: string, args?: string[], options?: { Convert?: boolean }): Promise<string>
ExecBackground(
cmd: string,
args: string[],
onOut: (out: string) => void,
onExit: () => void,
options?: { Env?: Record<string, string>; Convert?: boolean; StopOutputKeyword?: string; WorkingDirectory?: string; PidFile?: string }
): Promise<number>
HttpGet(
url: string,
headers?: Record<string, string>,
options?: { Timeout?: number; Insecure?: boolean; Redirect?: boolean }
): Promise<{ status: number; headers: Record<string, string>; body: any }>
HttpPost(
url: string,
headers: Record<string, string>,
data: any,
options?: { Timeout?: number; Insecure?: boolean; Redirect?: boolean }
): Promise<{ status: number; headers: Record<string, string>; body: any }>
HttpPut(
url: string,
headers: Record<string, string>,
data: any,
options?: { Timeout?: number; Insecure?: boolean; Redirect?: boolean }
): Promise<{ status: number; headers: Record<string, string>; body: any }>
HttpDelete(
url: string,
headers: Record<string, string>,
options?: { Timeout?: number; Insecure?: boolean; Redirect?: boolean }
): Promise<{ status: number; headers: Record<string, string>; body: any }>
HttpPatch(url: string, headers: Record<string, string>, data: any): Promise<{ status: number; headers: Record<string, string>; body: any }>
Requests(options: {
method: string
url: string
headers?: Record<string, string>
body?: string
autoTransformBody?: boolean
options?: {
Timeout?: number
Insecure?: boolean
Redirect?: boolean
}
}): Promise<{ status: number; body: any }>
Download(
url: string,
path: string,
headers?: Record<string, string>,
progressCallback?: (progress: number, total: number) => void,
options?: {
Method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
}
): Promise<void>
GetInterfaces(): Promise<string[]>
CheckPermissions(): Promise<boolean>
RestartApp(): Promise<void>
BrowserOpenURL(url: string): void
WindowReloadApp(): Promise<void>
WindowHide(): Promise<void>
WindowShow(): Promise<void>
WindowSetAlwaysOnTop(v: boolean): Promise<void>
ClipboardSetText(text: string): Promise<void>
ClipboardGetText(): Promise<string>
OpenMMDB(path: string, id: string): Promise<void>
CloseMMDB(path: string, id: string): Promise<void>
QueryMMDB(path: string, ip: string, type?: 'ASN' | 'AnonymousIP' | 'City' | 'ConnectionType' | 'Country' | 'Domain' | 'Enterprise'): Promise<any>
useAppStore(): {
showAbout: boolean
addCustomActions: (
target: 'core_state' | 'title_bar' | 'profiles_header' | 'subscriptions_header',
actions: CustomAction | CustomAction[] | CustomActionFn | CustomActionFn[]
) => () => void
removeCustomActions: (target: 'core_state' | 'title_bar' | 'profiles_header' | 'subscriptions_header', id: string | string[]) => void
}
useKernelApiStore(): {
startCore: (profile?: Recordable) => Promise<void>
stopCore: () => Promise<void>
restartCore: (cleanupTask?: () => Promise<any>, keepRuntimeProfile = true) => Promise<void>
pid: number
running: boolean
needRestart: boolean
config: Recordable
proxies: Recordable[]
onLogs: (handler: (data: { type: string; payload: string }) => void) => () => void
onMemory: (handler: (data: { inuse: number; oslimit: number }) => void) => () => void
onTraffic: (handler: (data: { down: number; up: number }) => void) => () => void
onConnections: (handler: (data: Recordable) => void) => () => void
updateConfig(field: string, value: any): Promise<void>
}
usePluginsStore(): {
plugins: Recordable[]
pluginHub: Recordable[]
manualTrigger: (id: string, event: string, ...args: any[]) => Promise<void>
addPlugin(plugin: Recordable): Promise<void>
getPluginById(id: string): Recordable
editPlugin(id: string, plugin: Recordable): Promise<void>
deletePlugin(id: string): Promise<void>
updatePlugin(id: string): Promise<void>
}
useRulesetsStore(): {
rulesets: Recordable[]
updateRuleset(id: string): Promise<void>
updateRulesets(): Promise<void>
addRuleset(ruleset: Recordable): Promise<void>
getRulesetById(id: string): Recordable
editRuleset(id: string, ruleset: Recordable): Promise<void>
deleteRuleset(id: string): Promise<void>
}
useSubscribesStore(): {
subscribes: Recordable[]
updateSubscribe(id: string): Promise<void>
updateSubscribes(): Promise<void>
getSubscribeById(id: string): Recordable
addSubscribe(subscription: Recordable): Promise<void>
editSubscribe(id: string, subscription: Recordable): Promise<void>
deleteSubscribe(id: string): Promise<void>
getSubscribeTemplate(name: string, options: { url: string }): Recordable
}
useEnvStore(): {
env: {
appName: string
appVersion: string
basePath: string
appPath: string
os: string
arch: string
}
systemProxy(): Promise<void>
setSystemProxy(): Promise<void>
clearSystemProxy(): Promise<void>
switchSystemProxy: (enable: boolean) => Promise<void>
}
useAppSettingsStore(): {
app: Recordable
themeMode: 'light' | 'dark'
}
useProfilesStore(): {
profiles: Recordable[]
currentProfile: Recordable
getProfileById: (id: string) => Recordable
addProfile(profile: Recordable): Promise<void>
editProfile(id: string, profile: Recordable): Promise<void>
deleteProfile(id: string): Promise<void>
getProfileTemplate(name: string): Recordable
}
useScheduledTasksStore(): {
scheduledtasks: Recordable[]
getScheduledTaskById(id: string): Recordable
addScheduledTask(task: Recordable): Promise<void>
editScheduledTask(id: string, task: Recordable): Promise<void>
deleteScheduledTask(id: string): Promise<void>
runScheduledTask(id: string): Promise<any>
}
generateSecureKey(): string
setIntervalImmediately(fn: () => void, delay: number): number
formatRelativeTime(dateString: string): string
base64Decode(encoded: string): string
base64Encode(text: string): string
deepClone<T>(obj: T): T
deepAssign<T, U>(target: T, source: U): T & U
asyncPool: <T>(poolLimit: number, array: T[], iteratorFn: (item: T, array: T[]) => Promise<any>) => Promise<any[]>
sampleID(): string
isValidIPv4(ip: string): boolean
generateConfig(profile: any, stable?: boolean): Promise<Record<string, any>>
formatBytes(bytes: number): string
formatDate(date: string | number, format: string): string
handleUseProxy(group: any, proxy: Recordable): Promise<void>
handleChangeMode(mode: 'direct' | 'global' | 'rule'): Promise<void>
debounce(fn: (...args: any[]) => void, delay: number): (...args: any[]) => void
getKernelFileName(isAlpha: boolean): Promise<string>
getUserAgent(): Promise<string>
GetSystemProxy(): Promise<string>
getGitHubApiAuthorization?(): string
sleep(ms: number): Promise<void>
ignoredError<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T> | undefined>
exitApp(): Promise<void>
}
declare namespace globalThis {
var Plugins: Plugins
var Vue: Vue
var AsyncFunction: FunctionConstructor
}
type PluginMetadata = {
[k: string]: any
id: string
name: string
version: string
description: string
tags: string[]
type: 'Http' | 'File'
url: string
path: string
triggers: string[]
hasUI: boolean
menus: Recordable<string>
context: {
profiles: Recordable<string>
subscriptions: Recordable<string>
rulesets: Recordable<string>
plugins: Recordable<string>
scheduledtasks: Recordable<string>
}
status: 0 | 1 | 2
configuration: {
id: string
title: string
description: string
key: string
component: string
value: any
options: string[]
}[]
}
type PluginStatus = number | void
type PluginExposed = {
onRun?: () => MaybePromise<PluginStatus>
onEnabled?: () => MaybePromise<PluginStatus>
onDisabled?: () => MaybePromise<PluginStatus>
onDispose?: () => MaybePromise<PluginStatus>
onInstall?: () => MaybePromise<PluginStatus>
onUninstall?: () => MaybePromise<PluginStatus>
onTrayUpdate?: (tray, menus) => MaybePromise<{ tray; menus }>
onSubscribe?: (proxies, subscription) => MaybePromise<proxies>
onGenerate?: (config, profile) => MaybePromise<config>
onStartup?: () => MaybePromise<PluginStatus>
onShutdown?: () => MaybePromise<PluginStatus>
onCoreStarted?: () => MaybePromise<PluginStatus>
onCoreStopped?: () => MaybePromise<PluginStatus>
onBeforeCoreStart?: (config, profile) => MaybePromise<Recordable>
onBeforeCoreStop?: () => MaybePromise<PluginStatus>
onReady?: () => MaybePromise<PluginStatus>
onReload?: () => MaybePromise<PluginStatus>
onTask?: () => MaybePromise<PluginStatus>
onConfigure?: (config, old) => MaybePromise<PluginStatus>
}
type EsmPlugin = PluginExposed | ((Plugin: PluginMetadata) => MaybePromise<PluginExposed>)