-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
34 lines (28 loc) · 1.47 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
const { contextBridge, ipcRenderer, desktopCapturer } = require('electron');
contextBridge.exposeInMainWorld('darkMode', {
toggle: () => ipcRenderer.invoke('dark-mode:toggle'),
system: () => ipcRenderer.invoke('dark-mode:system')
})
contextBridge.exposeInMainWorld('electronAPI', {
onReceivedSourceId: (callback) => ipcRenderer.on('RECEIVED_SOURCE_ID', (event, sourceId) => callback(sourceId)),
send: (channel, data) => ipcRenderer.send(channel, data),
receive: (channel, callback) => {
ipcRenderer.on(channel, (event, ...args) => callback(...args));
},
sendAudioForTranscription: (audioBlob) => {
const reader = new FileReader();
reader.onload = () => {
const buffer = Buffer.from(reader.result);
ipcRenderer.send('transcribe-audio', buffer);
};
reader.readAsArrayBuffer(audioBlob);
},
requestSourceId: (sourceId, mode) => ipcRenderer.send('REQUEST_SOURCE_ID', { sourceId, mode }),
onReceivedSourceId: (callback) => ipcRenderer.on('RECEIVED_SOURCE_ID', (event, sourceId) => callback(sourceId)),
startSnipping: () => ipcRenderer.send('start-snipping'),
sendSnipComplete: (base64Data) => ipcRenderer.send('snip-complete', base64Data),
clearChatHistory: () => ipcRenderer.send('clear-history'),
onHistoryCleared: (callback) => ipcRenderer.on('history-cleared', callback),
closeModal: () => ipcRenderer.send('close-modal'),
saveSettings: (apiKey, selectedWindow) => ipcRenderer.send('save-settings', { apiKey, selectedWindow }),
});