-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathpreload.js
More file actions
160 lines (146 loc) · 7.4 KB
/
Copy pathpreload.js
File metadata and controls
160 lines (146 loc) · 7.4 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
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
const { contextBridge, ipcRenderer } = require('electron')
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electronAPI', {
// Screenshot and OCR
takeScreenshot: () => ipcRenderer.invoke('take-screenshot'),
// Speech recognition
startSpeechRecognition: () => ipcRenderer.invoke('start-speech-recognition'),
stopSpeechRecognition: () => ipcRenderer.invoke('stop-speech-recognition'),
sendAudioChunk: (buffer) => ipcRenderer.send('audio-chunk', { buffer }),
getSpeechAvailability: () => ipcRenderer.invoke('get-speech-availability'),
// Window management
showAllWindows: () => ipcRenderer.invoke('show-all-windows'),
hideAllWindows: () => ipcRenderer.invoke('hide-all-windows'),
enableWindowInteraction: () => ipcRenderer.invoke('enable-window-interaction'),
disableWindowInteraction: () => ipcRenderer.invoke('disable-window-interaction'),
switchToChat: () => ipcRenderer.invoke('switch-to-chat'),
switchToSkills: () => ipcRenderer.invoke('switch-to-skills'),
resizeWindow: (width, height) => ipcRenderer.invoke('resize-window', { width, height }),
moveWindow: (deltaX, deltaY) => ipcRenderer.invoke('move-window', { deltaX, deltaY }),
getWindowStats: () => ipcRenderer.invoke('get-window-stats'),
// Session memory
getSessionHistory: () => ipcRenderer.invoke('get-session-history'),
getLLMSessionHistory: () => ipcRenderer.invoke('get-llm-session-history'),
clearSessionMemory: () => ipcRenderer.invoke('clear-session-memory'),
formatSessionHistory: () => ipcRenderer.invoke('format-session-history'),
sendChatMessage: (text) => ipcRenderer.invoke('send-chat-message', text),
getSkillPrompt: (skillName) => ipcRenderer.invoke('get-skill-prompt', skillName),
// Gemini LLM configuration
setGeminiApiKey: (apiKey) => ipcRenderer.invoke('set-gemini-api-key', apiKey),
getGeminiStatus: () => ipcRenderer.invoke('get-gemini-status'),
testGeminiConnection: () => ipcRenderer.invoke('test-gemini-connection'),
// Settings
showSettings: () => ipcRenderer.invoke('show-settings'),
hideSettings: () => ipcRenderer.invoke('hide-settings'),
getSettings: () => ipcRenderer.invoke('get-settings'),
saveSettings: (settings) => ipcRenderer.invoke('save-settings', settings),
// First-run onboarding
getFirstRunStatus: () => ipcRenderer.invoke('get-first-run-status'),
completeFirstRun: () => ipcRenderer.invoke('complete-first-run'),
openExternal: (url) => ipcRenderer.invoke('open-external', url),
closeOnboarding: () => ipcRenderer.invoke('close-onboarding'),
detectWhisper: () => ipcRenderer.invoke('detect-whisper'),
installWhisper: () => ipcRenderer.invoke('install-whisper'),
downloadWhisperModel: (modelName) => ipcRenderer.invoke('download-whisper-model', modelName),
onInstallProgress: (callback) => {
const wrapped = (_event, line) => {
try { callback(line); } catch (e) { console.error('onInstallProgress error:', e); }
};
ipcRenderer.on('install-progress', wrapped);
return () => ipcRenderer.removeListener('install-progress', wrapped);
},
updateAppIcon: (iconKey) => ipcRenderer.invoke('update-app-icon', iconKey),
updateActiveSkill: (skill) => ipcRenderer.invoke('update-active-skill', skill),
restartAppForStealth: () => ipcRenderer.invoke('restart-app-for-stealth'),
closeWindow: () => ipcRenderer.invoke('close-window'),
notifyMainWindowReady: () => {
try {
ipcRenderer.send('main-window-ready');
} catch (error) {
console.error('Error notifying main window ready:', error);
}
},
quit: () => {
try {
ipcRenderer.send('quit-app');
} catch (error) {
console.error('Error in quit:', error);
}
},
// LLM window specific methods
expandLlmWindow: (contentMetrics) => ipcRenderer.invoke('expand-llm-window', contentMetrics),
resizeLlmWindowForContent: (contentMetrics) => ipcRenderer.invoke('resize-llm-window-for-content', contentMetrics),
// Clipboard helper for reliable copy actions
copyToClipboard: (text) => {
try {
return ipcRenderer.invoke('copy-to-clipboard', String(text ?? ''));
} catch (e) {
console.error('copyToClipboard failed:', e);
return false;
}
},
// Display management
listDisplays: () => ipcRenderer.invoke('list-displays'),
captureArea: (options) => ipcRenderer.invoke('capture-area', options),
// Event listeners
onTranscriptionReceived: (callback) => ipcRenderer.on('transcription-received', callback),
onInterimTranscription: (callback) => ipcRenderer.on('interim-transcription', callback),
onSpeechStatus: (callback) => ipcRenderer.on('speech-status', callback),
onSpeechError: (callback) => ipcRenderer.on('speech-error', callback),
onSpeechAvailability: (callback) => ipcRenderer.on('speech-availability', callback),
onSessionEvent: (callback) => ipcRenderer.on('session-event', callback),
onSessionCleared: (callback) => ipcRenderer.on('session-cleared', callback),
onOcrCompleted: (callback) => ipcRenderer.on('ocr-completed', callback),
onOcrError: (callback) => ipcRenderer.on('ocr-error', callback),
onLlmResponse: (callback) => ipcRenderer.on('llm-response', callback),
onLlmError: (callback) => ipcRenderer.on('llm-error', callback),
onTranscriptionLlmResponse: (callback) => ipcRenderer.on('transcription-llm-response', callback),
onTranscriptionLlmResponseStart: (callback) => ipcRenderer.on('transcription-llm-response-start', callback),
onTranscriptionLlmResponseChunk: (callback) => ipcRenderer.on('transcription-llm-response-chunk', callback),
onOpenGeminiConfig: (callback) => ipcRenderer.on('open-gemini-config', callback),
onDisplayLlmResponse: (callback) => ipcRenderer.on('display-llm-response', callback),
onShowLoading: (callback) => ipcRenderer.on('show-loading', callback),
onSkillChanged: (callback) => ipcRenderer.on('skill-changed', callback),
onInteractionModeChanged: (callback) => ipcRenderer.on('interaction-mode-changed', callback),
onRecordingStarted: (callback) => ipcRenderer.on('recording-started', callback),
onRecordingStopped: (callback) => ipcRenderer.on('recording-stopped', callback),
onCodingLanguageChanged: (callback) => ipcRenderer.on('coding-language-changed', callback),
onMainWindowShown: (callback) => ipcRenderer.on('main-window-shown', callback),
// Generic receive method
receive: (channel, callback) => ipcRenderer.on(channel, callback),
// Remove listeners
removeAllListeners: (channel) => ipcRenderer.removeAllListeners(channel)
})
contextBridge.exposeInMainWorld('api', {
send: (channel, data) => {
let validChannels = [
'close-settings',
'quit-app',
'save-settings',
'toggle-recording',
'toggle-interaction-mode',
'update-skill',
'window-loaded'
];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
} else {
console.warn('Invalid IPC channel:', channel);
}
},
receive: (channel, func) => {
let validChannels = [
'load-settings',
'recording-state-changed',
'interaction-mode-changed',
'skill-updated',
'update-skill',
'recording-started',
'recording-stopped'
];
if (validChannels.includes(channel)) {
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
});