aboutsummaryrefslogtreecommitdiff
path: root/src/shared/messages.ts
blob: 8b9e59889722200326e80695517767a1f3bb90b1 (plain) (blame)
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
import * as operations from "./operations";
import CompletionType from "./CompletionType";
import TabFlag from "./TabFlag";

export const BACKGROUND_OPERATION = "background.operation";

export const CONSOLE_UNFOCUS = "console.unfocus";
export const CONSOLE_ENTER_COMMAND = "console.enter.command";
export const CONSOLE_ENTER_FIND = "console.enter.find";
export const CONSOLE_SHOW_COMMAND = "console.show.command";
export const CONSOLE_SHOW_ERROR = "console.show.error";
export const CONSOLE_SHOW_INFO = "console.show.info";
export const CONSOLE_SHOW_FIND = "console.show.find";
export const CONSOLE_HIDE = "console.hide";
export const CONSOLE_GET_COMPLETION_TYPES = "console.get.completion.types";
export const CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE =
  "console.qresut.searchEngines";
export const CONSOLE_REQUEST_BOOKMARKS = "console.request.bookmarks";
export const CONSOLE_REQUEST_HISTORY = "console.request.history";
export const CONSOLE_REQUEST_TABS = "console.request.tabs";
export const CONSOLE_GET_PROPERTIES = "console.get.properties";
export const CONSOLE_RESIZE = "console.resize";

export const FOLLOW_START = "follow.start";
export const FOLLOW_REQUEST_COUNT_TARGETS = "follow.request.count.targets";
export const FOLLOW_RESPONSE_COUNT_TARGETS = "follow.response.count.targets";
export const FOLLOW_CREATE_HINTS = "follow.create.hints";
export const FOLLOW_SHOW_HINTS = "follow.update.hints";
export const FOLLOW_REMOVE_HINTS = "follow.remove.hints";
export const FOLLOW_ACTIVATE = "follow.activate";
export const FOLLOW_KEY_PRESS = "follow.key.press";

export const MARK_SET_GLOBAL = "mark.set.global";
export const MARK_JUMP_GLOBAL = "mark.jump.global";

export const TAB_SCROLL_TO = "tab.scroll.to";

export const FIND_NEXT = "find.next";
export const FIND_PREV = "find.prev";
export const FIND_CLEAR_SELECTION = "find.clear.selection";

export const ADDON_ENABLED_QUERY = "addon.enabled.query";
export const ADDON_ENABLED_RESPONSE = "addon.enabled.response";
export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled";

export const OPEN_URL = "open.url";

export const SETTINGS_CHANGED = "settings.changed";
export const SETTINGS_QUERY = "settings.query";

export const CONSOLE_FRAME_MESSAGE = "console.frame.message";

export const NAVIGATE_HISTORY_NEXT = "navigate.history.next";
export const NAVIGATE_HISTORY_PREV = "navigate.history.prev";
export const NAVIGATE_LINK_NEXT = "navigate.link.next";
export const NAVIGATE_LINK_PREV = "navigate.link.prev";

export interface BackgroundOperationMessage {
  type: typeof BACKGROUND_OPERATION;
  repeat: number;
  operation: operations.Operation;
}

export interface ConsoleUnfocusMessage {
  type: typeof CONSOLE_UNFOCUS;
}

export interface ConsoleEnterCommandMessage {
  type: typeof CONSOLE_ENTER_COMMAND;
  text: string;
}

export interface ConsoleEnterFindMessage {
  type: typeof CONSOLE_ENTER_FIND;
  keyword?: string;
}

export interface ConsoleShowCommandMessage {
  type: typeof CONSOLE_SHOW_COMMAND;
  command: string;
}

export interface ConsoleShowErrorMessage {
  type: typeof CONSOLE_SHOW_ERROR;
  text: string;
}

export interface ConsoleShowInfoMessage {
  type: typeof CONSOLE_SHOW_INFO;
  text: string;
}

export interface ConsoleShowFindMessage {
  type: typeof CONSOLE_SHOW_FIND;
}

export interface ConsoleHideMessage {
  type: typeof CONSOLE_HIDE;
}

export interface ConsoleGetCompletionTypesMessage {
  type: typeof CONSOLE_GET_COMPLETION_TYPES;
}

export interface ConsoleRequestSearchEnginesMessage {
  type: typeof CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE;
  query: string;
}

export interface ConsoleRequestBookmarksMessage {
  type: typeof CONSOLE_REQUEST_BOOKMARKS;
  query: string;
}

export interface ConsoleRequestHistoryMessage {
  type: typeof CONSOLE_REQUEST_HISTORY;
  query: string;
}

export interface ConsoleRequestTabsMessage {
  type: typeof CONSOLE_REQUEST_TABS;
  query: string;
  excludePinned: boolean;
}

export interface ConsoleGetPropertiesMessage {
  type: typeof CONSOLE_GET_PROPERTIES;
}

export interface ConsoleResizeMessage {
  type: typeof CONSOLE_RESIZE;
  width: number;
  height: number;
}

export type ConsoleRequestTabsResponse = {
  index: number;
  flag: TabFlag;
  title: string;
  url: string;
  faviconUrl?: string;
}[];

export type ConsoleGetCompletionTypesResponse = CompletionType[];

export type ConsoleRequestSearchEnginesResponse = {
  title: string;
}[];

export type ConsoleRequestBookmarksResponse = {
  title: string;
  url: string;
}[];

export type ConsoleRequestHistoryResponse = {
  title: string;
  url: string;
}[];

export type ConsoleGetPropertiesResponse = {
  name: string;
  type: "string" | "boolean" | "number";
}[];

export interface FollowStartMessage {
  type: typeof FOLLOW_START;
  newTab: boolean;
  background: boolean;
}

export interface FollowRequestCountTargetsMessage {
  type: typeof FOLLOW_REQUEST_COUNT_TARGETS;
  viewSize: { width: number; height: number };
  framePosition: { x: number; y: number };
}

export interface FollowResponseCountTargetsMessage {
  type: typeof FOLLOW_RESPONSE_COUNT_TARGETS;
  count: number;
}

export interface FollowCreateHintsMessage {
  type: typeof FOLLOW_CREATE_HINTS;
  tags: string[];
  viewSize: { width: number; height: number };
  framePosition: { x: number; y: number };
}

export interface FollowShowHintsMessage {
  type: typeof FOLLOW_SHOW_HINTS;
  prefix: string;
}

export interface FollowRemoveHintsMessage {
  type: typeof FOLLOW_REMOVE_HINTS;
}

export interface FollowActivateMessage {
  type: typeof FOLLOW_ACTIVATE;
  tag: string;
  newTab: boolean;
  background: boolean;
}

export interface FollowKeyPressMessage {
  type: typeof FOLLOW_KEY_PRESS;
  key: string;
  ctrlKey: boolean;
}

export interface MarkSetGlobalMessage {
  type: typeof MARK_SET_GLOBAL;
  key: string;
  x: number;
  y: number;
}

export interface MarkJumpGlobalMessage {
  type: typeof MARK_JUMP_GLOBAL;
  key: string;
}

export interface TabScrollToMessage {
  type: typeof TAB_SCROLL_TO;
  x: number;
  y: number;
}

export interface FindNextMessage {
  type: typeof FIND_NEXT;
  keyword: string;
}

export interface FindPrevMessage {
  type: typeof FIND_PREV;
  keyword: string;
}

export interface FindClearSelection {
  type: typeof FIND_CLEAR_SELECTION;
}

export interface AddonEnabledQueryMessage {
  type: typeof ADDON_ENABLED_QUERY;
}

export interface AddonEnabledResponseMessage {
  type: typeof ADDON_ENABLED_RESPONSE;
  enabled: boolean;
}

export interface AddonToggleEnabledMessage {
  type: typeof ADDON_TOGGLE_ENABLED;
}

export interface OpenUrlMessage {
  type: typeof OPEN_URL;
  url: string;
  newTab: boolean;
  background: boolean;
}

export interface SettingsChangedMessage {
  type: typeof SETTINGS_CHANGED;
}

export interface SettingsQueryMessage {
  type: typeof SETTINGS_QUERY;
}

export interface ConsoleFrameMessageMessage {
  type: typeof CONSOLE_FRAME_MESSAGE;
  message: any;
}

export interface NavigateHistoryNextMessage {
  type: typeof NAVIGATE_HISTORY_NEXT;
}

export interface NavigateHistoryPrevMessage {
  type: typeof NAVIGATE_HISTORY_PREV;
}

export interface NavigateLinkNext {
  type: typeof NAVIGATE_LINK_NEXT;
}

export interface NavigateLinkPrev {
  type: typeof NAVIGATE_LINK_PREV;
}

export type Message =
  | BackgroundOperationMessage
  | ConsoleUnfocusMessage
  | ConsoleEnterCommandMessage
  | ConsoleEnterFindMessage
  | ConsoleShowCommandMessage
  | ConsoleShowErrorMessage
  | ConsoleShowInfoMessage
  | ConsoleShowFindMessage
  | ConsoleHideMessage
  | ConsoleRequestBookmarksMessage
  | ConsoleRequestHistoryMessage
  | ConsoleRequestTabsMessage
  | ConsoleGetPropertiesMessage
  | ConsoleResizeMessage
  | ConsoleGetCompletionTypesMessage
  | ConsoleRequestSearchEnginesMessage
  | FollowStartMessage
  | FollowRequestCountTargetsMessage
  | FollowResponseCountTargetsMessage
  | FollowCreateHintsMessage
  | FollowShowHintsMessage
  | FollowRemoveHintsMessage
  | FollowActivateMessage
  | FollowKeyPressMessage
  | MarkSetGlobalMessage
  | MarkJumpGlobalMessage
  | TabScrollToMessage
  | FindNextMessage
  | FindPrevMessage
  | FindClearSelection
  | AddonEnabledQueryMessage
  | AddonEnabledResponseMessage
  | AddonToggleEnabledMessage
  | OpenUrlMessage
  | SettingsChangedMessage
  | SettingsQueryMessage
  | ConsoleFrameMessageMessage
  | NavigateHistoryNextMessage
  | NavigateHistoryPrevMessage
  | NavigateLinkNext
  | NavigateLinkPrev;

// eslint-disable-next-line complexity
export const valueOf = (o: any): Message => {
  switch (o.type) {
    case CONSOLE_UNFOCUS:
    case CONSOLE_ENTER_COMMAND:
    case CONSOLE_ENTER_FIND:
    case CONSOLE_SHOW_COMMAND:
    case CONSOLE_SHOW_ERROR:
    case CONSOLE_SHOW_INFO:
    case CONSOLE_SHOW_FIND:
    case CONSOLE_HIDE:
    case FOLLOW_START:
    case FOLLOW_REQUEST_COUNT_TARGETS:
    case FOLLOW_RESPONSE_COUNT_TARGETS:
    case FOLLOW_CREATE_HINTS:
    case FOLLOW_SHOW_HINTS:
    case FOLLOW_REMOVE_HINTS:
    case FOLLOW_ACTIVATE:
    case FOLLOW_KEY_PRESS:
    case MARK_SET_GLOBAL:
    case MARK_JUMP_GLOBAL:
    case TAB_SCROLL_TO:
    case FIND_NEXT:
    case FIND_PREV:
    case FIND_CLEAR_SELECTION:
    case ADDON_ENABLED_QUERY:
    case ADDON_ENABLED_RESPONSE:
    case ADDON_TOGGLE_ENABLED:
    case OPEN_URL:
    case SETTINGS_CHANGED:
    case SETTINGS_QUERY:
    case CONSOLE_FRAME_MESSAGE:
    case CONSOLE_RESIZE:
    case NAVIGATE_HISTORY_NEXT:
    case NAVIGATE_HISTORY_PREV:
    case NAVIGATE_LINK_NEXT:
    case NAVIGATE_LINK_PREV:
      return o;
  }
  throw new Error("unknown message type: " + o.type);
};