forked from doctly/switchboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
71 lines (65 loc) · 3.56 KB
/
preload.js
File metadata and controls
71 lines (65 loc) · 3.56 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
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('api', {
// Invoke (request-response)
getPlans: () => ipcRenderer.invoke('get-plans'),
readPlan: (filename) => ipcRenderer.invoke('read-plan', filename),
savePlan: (filePath, content) => ipcRenderer.invoke('save-plan', filePath, content),
getStats: () => ipcRenderer.invoke('get-stats'),
getMemories: () => ipcRenderer.invoke('get-memories'),
readMemory: (filePath) => ipcRenderer.invoke('read-memory', filePath),
getProjects: (showArchived) => ipcRenderer.invoke('get-projects', showArchived),
getActiveSessions: () => ipcRenderer.invoke('get-active-sessions'),
getActiveTerminals: () => ipcRenderer.invoke('get-active-terminals'),
stopSession: (id) => ipcRenderer.invoke('stop-session', id),
toggleStar: (id) => ipcRenderer.invoke('toggle-star', id),
renameSession: (id, name) => ipcRenderer.invoke('rename-session', id, name),
archiveSession: (id, archived) => ipcRenderer.invoke('archive-session', id, archived),
openTerminal: (id, projectPath, isNew, sessionOptions) => ipcRenderer.invoke('open-terminal', id, projectPath, isNew, sessionOptions),
search: (type, query) => ipcRenderer.invoke('search', type, query),
readSessionJsonl: (sessionId) => ipcRenderer.invoke('read-session-jsonl', sessionId),
// Settings
getSetting: (key) => ipcRenderer.invoke('get-setting', key),
setSetting: (key, value) => ipcRenderer.invoke('set-setting', key, value),
deleteSetting: (key) => ipcRenderer.invoke('delete-setting', key),
getEffectiveSettings: (projectPath) => ipcRenderer.invoke('get-effective-settings', projectPath),
browseFolder: () => ipcRenderer.invoke('browse-folder'),
addProject: (projectPath) => ipcRenderer.invoke('add-project', projectPath),
removeProject: (projectPath) => ipcRenderer.invoke('remove-project', projectPath),
openExternal: (url) => ipcRenderer.invoke('open-external', url),
// Send (fire-and-forget)
sendInput: (id, data) => ipcRenderer.send('terminal-input', id, data),
resizeTerminal: (id, cols, rows) => ipcRenderer.send('terminal-resize', id, cols, rows),
closeTerminal: (id) => ipcRenderer.send('close-terminal', id),
// Listeners (main → renderer)
onTerminalData: (callback) => {
ipcRenderer.on('terminal-data', (_event, sessionId, data) => callback(sessionId, data));
},
onSessionDetected: (callback) => {
ipcRenderer.on('session-detected', (_event, tempId, realId) => callback(tempId, realId));
},
onProcessExited: (callback) => {
ipcRenderer.on('process-exited', (_event, sessionId, exitCode) => callback(sessionId, exitCode));
},
onProgressState: (callback) => {
ipcRenderer.on('progress-state', (_event, sessionId, state, percent) => callback(sessionId, state, percent));
},
onTerminalNotification: (callback) => {
ipcRenderer.on('terminal-notification', (_event, sessionId, message) => callback(sessionId, message));
},
onSessionForked: (callback) => {
ipcRenderer.on('session-forked', (_event, oldId, newId) => callback(oldId, newId));
},
onProjectsChanged: (callback) => {
ipcRenderer.on('projects-changed', () => callback());
},
onStatusUpdate: (callback) => {
ipcRenderer.on('status-update', (_event, text, type) => callback(text, type));
},
// Auto-updater
updaterCheck: () => ipcRenderer.invoke('updater-check'),
updaterDownload: () => ipcRenderer.invoke('updater-download'),
updaterInstall: () => ipcRenderer.invoke('updater-install'),
onUpdaterEvent: (callback) => {
ipcRenderer.on('updater-event', (_event, type, data) => callback(type, data));
},
});