-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
195 lines (165 loc) · 6.18 KB
/
preload.js
File metadata and controls
195 lines (165 loc) · 6.18 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
* Preload Script for Meeting Recorder
*
* This script runs in the renderer process before the page loads.
* It provides a secure bridge between the renderer and main process via contextBridge.
*
* Security:
* - Only exposes specific whitelisted APIs
* - No direct access to Node.js or Electron APIs from renderer
* - All communication via IPC (Inter-Process Communication)
*/
const { contextBridge, ipcRenderer } = require('electron');
/**
* Exposed API for renderer process
*
* All methods return Promises for async operations
*/
contextBridge.exposeInMainWorld('meetingRecorder', {
// ============================================
// Recording Controls
// ============================================
/**
* Start audio recording
* @returns {Promise<{success: boolean, error?: string}>}
*/
startRecording: () => ipcRenderer.invoke('recording:start'),
/**
* Stop audio recording
* @returns {Promise<{success: boolean, filepath?: string, duration?: number, error?: string}>}
*/
stopRecording: () => ipcRenderer.invoke('recording:stop'),
/**
* Get current recording status
* @returns {Promise<{isRecording: boolean, duration?: number, fileSize?: number}>}
*/
getRecordingStatus: () => ipcRenderer.invoke('recording:status'),
// ============================================
// File Management
// ============================================
/**
* List all recordings
* @returns {Promise<Array<{filename: string, size: number, created: Date, transcribed: boolean, summarised: boolean}>>}
*/
listRecordings: () => ipcRenderer.invoke('files:list'),
/**
* Get storage statistics
* @returns {Promise<{totalSize: number, recordingsCount: number, transcriptsCount: number, notesCount: number}>}
*/
getStorageStats: () => ipcRenderer.invoke('files:stats'),
/**
* Delete a specific recording and its associated files
* @param {string} filename - The recording filename
* @returns {Promise<{success: boolean, deletedFiles: string[], error?: string}>}
*/
deleteRecording: (filename) => ipcRenderer.invoke('files:delete', filename),
/**
* Clean up old recordings based on retention policy
* @returns {Promise<{success: boolean, deletedCount: number, freedSpace: number}>}
*/
cleanupOldRecordings: () => ipcRenderer.invoke('files:cleanup'),
/**
* Open a file in the default application
* @param {string} filepath - Absolute path to file
* @returns {Promise<{success: boolean, error?: string}>}
*/
openFile: (filepath) => ipcRenderer.invoke('files:open', filepath),
// ============================================
// Processing
// ============================================
/**
* Transcribe a specific recording
* @param {string} wavPath - Path to WAV file
* @returns {Promise<{success: boolean, transcriptPath?: string, error?: string}>}
*/
transcribeRecording: (wavPath) => ipcRenderer.invoke('process:transcribe', wavPath),
/**
* Generate notes from a transcript
* @param {string} transcriptPath - Path to transcript file
* @returns {Promise<{success: boolean, notesPath?: string, error?: string}>}
*/
generateNotes: (transcriptPath) => ipcRenderer.invoke('process:summarise', transcriptPath),
/**
* Process a recording (transcribe + summarise)
* @param {string} wavPath - Path to WAV file
* @returns {Promise<{success: boolean, transcriptPath?: string, notesPath?: string, error?: string}>}
*/
processRecording: (wavPath) => ipcRenderer.invoke('process:full', wavPath),
// ============================================
// Settings
// ============================================
/**
* Get current application settings
* @returns {Promise<Object>} Settings object
*/
getSettings: () => ipcRenderer.invoke('settings:get'),
/**
* Update application settings
* @param {Object} settings - Settings to update
* @returns {Promise<{success: boolean, error?: string}>}
*/
updateSettings: (settings) => ipcRenderer.invoke('settings:update', settings),
/**
* Reset settings to defaults
* @returns {Promise<{success: boolean}>}
*/
resetSettings: () => ipcRenderer.invoke('settings:reset'),
// ============================================
// System Information
// ============================================
/**
* Check if all dependencies are installed
* @returns {Promise<{sox: boolean, whisper: boolean, ollama: boolean, blackhole: boolean}>}
*/
checkDependencies: () => ipcRenderer.invoke('system:dependencies'),
/**
* Get application version
* @returns {Promise<string>} Version string
*/
getVersion: () => ipcRenderer.invoke('system:version'),
/**
* Open output directory in Finder
* @returns {Promise<{success: boolean}>}
*/
openOutputDirectory: () => ipcRenderer.invoke('system:openOutputDir'),
// ============================================
// Event Listeners
// ============================================
/**
* Listen for recording status updates
* @param {Function} callback - Called with {isRecording: boolean, duration: number, fileSize: number}
*/
onRecordingUpdate: (callback) => {
ipcRenderer.on('recording:update', (event, data) => callback(data));
},
/**
* Listen for processing progress updates
* @param {Function} callback - Called with {stage: string, progress: number, message: string}
*/
onProcessingProgress: (callback) => {
ipcRenderer.on('processing:progress', (event, data) => callback(data));
},
/**
* Listen for errors
* @param {Function} callback - Called with {error: string, details: string}
*/
onError: (callback) => {
ipcRenderer.on('error', (event, data) => callback(data));
},
/**
* Listen for notifications
* @param {Function} callback - Called with {title: string, message: string, type: string}
*/
onNotification: (callback) => {
ipcRenderer.on('notification', (event, data) => callback(data));
},
/**
* Remove event listener
* @param {string} channel - Event channel name
* @param {Function} callback - The callback to remove
*/
removeListener: (channel, callback) => {
ipcRenderer.removeListener(channel, callback);
}
});
console.log('✅ Preload script loaded - API exposed to renderer');