-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
128 lines (117 loc) · 3.43 KB
/
api.ts
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
export interface APIResponseBase {
code: number
body: any
}
export type ReceiveWSMessageAny =
| ReceiveWSMessagePlayURL
| ReceiveWSMessageRestart
| ReceiveWSMessageStop
| ReceiveWSMessageExecute
| ReceiveWSMessageList
export interface ReceiveWSMessages {
[ReceiveWSMessageType.PLAYURL]: [ReceiveWSMessagePlayURL, APIResponseDefault]
[ReceiveWSMessageType.RESTART]: [ReceiveWSMessageRestart, APIResponseDefault]
[ReceiveWSMessageType.STOP]: [ReceiveWSMessageStop, APIResponseDefault]
[ReceiveWSMessageType.EXECUTE]: [ReceiveWSMessageExecute, APIResponseDefault]
[ReceiveWSMessageType.LIST]: [ReceiveWSMessageList, APIResponseList]
}
export type ReceiveWSMessage<T extends ReceiveWSMessageType> = ReceiveWSMessages[T][0]
export type ReceiveWSMessageResponse<T extends ReceiveWSMessageType> = ReceiveWSMessages[T][1]
export interface ReceiveWSMessageBase {
type: ReceiveWSMessageType
msgId: number
apiKey?: string
}
export enum ReceiveWSMessageType {
PLAYURL = 'playurl',
RESTART = 'restart',
STOP = 'stop',
EXECUTE = 'execute',
LIST = 'list',
}
export interface APIResponseDefault extends APIResponseBase {
code: number
body: string
}
/** Command: Make a window play an URL. Responds with @APIResponseDefault */
export interface ReceiveWSMessagePlayURL extends ReceiveWSMessageBase {
type: ReceiveWSMessageType.PLAYURL
windowId: string
/** The URL to load in the window */
url: string
/** [optional] Execute javascript code after loading URL */
jsCode?: string
}
/** Command: Make a window restart (reload). Responds with @APIResponseDefault */
export interface ReceiveWSMessageRestart extends ReceiveWSMessageBase {
type: ReceiveWSMessageType.RESTART
windowId: string
}
/** Command: Make a window stop (unload). Responds with @APIResponseDefault */
export interface ReceiveWSMessageStop extends ReceiveWSMessageBase {
type: ReceiveWSMessageType.STOP
windowId: string
}
/** Command: Make a window execute javascript. Responds with @APIResponseDefault */
export interface ReceiveWSMessageExecute extends ReceiveWSMessageBase {
type: ReceiveWSMessageType.EXECUTE
windowId: string
jsCode: string
}
/** Command: List windows and their contents. Responds with @APIResponseList */
export interface ReceiveWSMessageList extends ReceiveWSMessageBase {
type: ReceiveWSMessageType.LIST
}
export interface APIResponseList extends APIResponseBase {
body: {
id: string
url: string | null
actualUrl: string
statusCode: string
statusMessage: string
}[]
}
export type SendWSMessageAny = SendWSMessageReply | SendWSMessageStatus
export enum SendWSMessageType {
REPLY = 'reply',
STATUS = 'status',
}
export interface SendWSMessageBase {
type: SendWSMessageType
}
export interface SendWSMessageReply extends SendWSMessageBase {
type: SendWSMessageType.REPLY
replyTo: number
error: string | undefined
result: APIResponseReply | undefined
}
export interface APIResponseReply extends APIResponseBase {
code: number
body: any
}
export interface SendWSMessageStatus extends SendWSMessageBase {
type: SendWSMessageType.STATUS
status: {
app: StatusObject
windows: {
[index: string]: StatusObject
}
}
}
export enum StatusCode {
GOOD = 'good',
WARNING = 'warning',
ERROR = 'error',
}
export interface StatusObject {
statusCode: StatusCode
message: string
}
export enum IpcMethods {
// Note: update this enum in lib/preload.ts when changed
ReportStatus = 'ReportStatus',
}
export interface ReportStatusIpcPayload {
status: StatusCode
message?: string
}