-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
77 lines (74 loc) · 2.08 KB
/
index.ts
File metadata and controls
77 lines (74 loc) · 2.08 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
import { contextBridge, ipcRenderer } from 'electron';
const ALLOWED_INVOKE_CHANNELS = new Set([
'app:get-settings',
'app:set-settings',
'app:check-birda',
'app:get-log',
'birda:analyze',
'birda:cancel-analysis',
'birda:config-show',
'birda:config-path',
'birda:models-list',
'birda:models-available',
'birda:models-install',
'birda:models-info',
'birda:extract-clip',
'clip:save-spectrogram',
'clip:get-spectrogram',
'clip:export-region',
'catalog:get-runs',
'catalog:delete-run',
'catalog:get-detections',
'catalog:search-species',
'catalog:get-species-summary',
'catalog:species-locations',
'catalog:location-species',
'catalog:get-locations',
'catalog:get-locations-with-counts',
'catalog:stats',
'catalog:clear-database',
'labels:resolve-all',
'labels:search-by-common-name',
'labels:available-languages',
'fs:open-file-dialog',
'fs:open-executable-dialog',
'fs:open-folder-dialog',
'fs:read-coordinates',
'fs:scan-source',
'fs:open-in-explorer',
'app:get-licenses',
]);
const ALLOWED_RECEIVE_CHANNELS = new Set([
'birda:analysis-progress',
'birda:models-install-progress',
'app:log',
'menu:open-file',
'menu:open-folder',
'menu:switch-tab',
'menu:focus-search',
'menu:toggle-log',
'menu:setup-wizard',
'menu:show-licenses',
]);
contextBridge.exposeInMainWorld('birda', {
invoke: (channel: string, ...args: unknown[]) => {
if (!ALLOWED_INVOKE_CHANNELS.has(channel)) {
return Promise.reject(new Error(`IPC channel not allowed: ${channel}`));
}
return ipcRenderer.invoke(channel, ...args);
},
on: (channel: string, callback: (...args: unknown[]) => void) => {
if (!ALLOWED_RECEIVE_CHANNELS.has(channel)) {
throw new Error(`IPC receive channel not allowed: ${channel}`);
}
ipcRenderer.on(channel, (_event, ...args: unknown[]) => {
callback(...args);
});
},
removeAllListeners: (channel: string) => {
if (!ALLOWED_RECEIVE_CHANNELS.has(channel)) {
throw new Error(`IPC receive channel not allowed: ${channel}`);
}
ipcRenderer.removeAllListeners(channel);
},
});