-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathpreload.js
91 lines (88 loc) · 2.55 KB
/
preload.js
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
const { ipcRenderer, contextBridge } = require('electron');
const apiObj = {
send: (channel, ...data) => {
// allow list channels SENDING to Main
const allowedChannels = [
'check-for-update',
'confirm-clear-history',
'export-collection',
'fatalError',
'import-collection',
'import-proto',
'import-openapi',
'open-http',
'close-http',
'open-gql',
'open-grpc',
'protoParserFunc-request',
'openapiParserFunc-request',
'quit-and-install',
'uncaughtException',
'introspect',
'open-ws',
'send-ws',
'set-cookie',
'close-ws',
'open-openapi',
'exportChatLog',
'start-mock-server',
'stop-mock-server',
'submit-mock-request',
'open-trpc',
'error',
];
if (allowedChannels.includes(channel)) {
ipcRenderer.send(channel, ...data);
} else {
console.log('Channel not allowed: ', channel);
}
},
receive: (channel, cb) => {
// allow list channels
const allowedChannels = [
'add-collections',
'clear-history-response',
'introspect-reply',
'message',
'openapi-info',
'openapiParserFunc-return',
'proto-info',
'protoParserFunc-return',
'reply-gql',
'reqResUpdate',
'set-cookie',
'update-connectionArray',
];
if (allowedChannels.includes(channel)) {
ipcRenderer.on(channel, (event, ...args) => cb(...args));
} else {
console.log('Channel not allowed: ', channel);
}
},
removeAllListeners: (channel, cb) => {
// allow list channels
const allowedChannels = [
'reqResUpdate',
'reply-gql',
'protoParserFunc-return',
'openapi-info',
];
if (allowedChannels.includes(channel)) {
ipcRenderer.removeAllListeners(channel, (event, ...args) => cb(...args));
} else {
console.log('Channel not allowed: ', channel);
}
},
versions: process.versions,
};
// this is because we need to have context isolation to be false for spectron
// tests to run, but context bridge only runs if context isolation is true
// basically we are assigning certain node functionality (require, ipcRenderer)
// to the window object in an UN-isolated context only for testing
// security is reduced for testing, but remains sturdy otherwise
if (process.env.NODE_ENV === 'test') {
window.electronRequire = require;
window.api = apiObj;
} else {
contextBridge.exposeInMainWorld('api', apiObj);
}