forked from johannesjo/parallel-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.cjs
More file actions
112 lines (109 loc) · 2.93 KB
/
preload.cjs
File metadata and controls
112 lines (109 loc) · 2.93 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
const { contextBridge, ipcRenderer } = require('electron');
// Allowlist of valid IPC channels.
// IMPORTANT: This list MUST stay in sync with the IPC enum in electron/ipc/channels.ts.
// The main process verifies this at startup — a mismatch will log a warning in dev.
const ALLOWED_CHANNELS = new Set([
// Agent/PTY
'spawn_agent',
'write_to_agent',
'resize_agent',
'pause_agent',
'resume_agent',
'kill_agent',
'count_running_agents',
'kill_all_agents',
'list_agents',
// Task
'create_task',
'delete_task',
// Git
'get_changed_files',
'get_changed_files_from_branch',
'get_file_diff',
'get_file_diff_from_branch',
'get_all_file_diffs',
'get_all_file_diffs_from_branch',
'get_gitignored_dirs',
'get_worktree_status',
'commit_all',
'discard_uncommitted',
'check_merge_status',
'merge_task',
'get_branch_log',
'push_task',
'rebase_task',
'get_main_branch',
'get_current_branch',
// Persistence
'save_app_state',
'load_app_state',
// Window
'__window_is_focused',
'__window_is_maximized',
'__window_minimize',
'__window_toggle_maximize',
'__window_close',
'__window_force_close',
'__window_hide',
'__window_maximize',
'__window_unmaximize',
'__window_set_size',
'__window_set_position',
'__window_get_position',
'__window_get_size',
'__window_focus',
'__window_blur',
'__window_resized',
'__window_moved',
'__window_close_requested',
// Dialog
'__dialog_confirm',
'__dialog_open',
// Shell
'__shell_reveal',
'__shell_open_file',
'__shell_open_in_editor',
// Arena
'save_arena_data',
'load_arena_data',
'create_arena_worktree',
'remove_arena_worktree',
'check_path_exists',
// Remote access
'start_remote_server',
'stop_remote_server',
'get_remote_status',
// Plan
'plan_content',
// Ask about code
'ask_about_code',
'cancel_ask_about_code',
// Notifications
'show_notification',
'notification_clicked',
]);
function isAllowedChannel(channel) {
return ALLOWED_CHANNELS.has(channel) || channel.startsWith('channel:');
}
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
invoke: (channel, ...args) => {
if (!isAllowedChannel(channel)) throw new Error(`Blocked IPC channel: ${channel}`);
return ipcRenderer.invoke(channel, ...args);
},
send: (channel, ...args) => {
if (!isAllowedChannel(channel)) throw new Error(`Blocked IPC channel: ${channel}`);
ipcRenderer.send(channel, ...args);
},
on: (channel, listener) => {
if (!isAllowedChannel(channel)) throw new Error(`Blocked IPC channel: ${channel}`);
const wrapped = (_event, ...eventArgs) => listener(...eventArgs);
ipcRenderer.on(channel, wrapped);
return () => ipcRenderer.removeListener(channel, wrapped);
},
removeAllListeners: (channel) => {
if (!isAllowedChannel(channel)) throw new Error(`Blocked IPC channel: ${channel}`);
ipcRenderer.removeAllListeners(channel);
},
},
});