-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.ts
More file actions
44 lines (43 loc) · 1.77 KB
/
preload.ts
File metadata and controls
44 lines (43 loc) · 1.77 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
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', {
getVideoInfo: (url: unknown) => {
if (typeof url !== 'string') {
return Promise.reject(new Error('URL must be a string'));
}
return ipcRenderer.invoke('get-video-info', { url });
},
openFileDialog: () => ipcRenderer.invoke('open-file-dialog'),
getLocalFileInfo: (filePath: unknown) => {
if (typeof filePath !== 'string') {
return Promise.reject(new Error('filePath must be a string'));
}
return ipcRenderer.invoke('get-local-file-info', { filePath });
},
downloadMP3: (params: unknown) => {
if (params == null || typeof params !== 'object' || Array.isArray(params)) {
return Promise.reject(new Error('Params must be an object'));
}
const { url, sourceFilePath, title, startTime, endTime, playbackSpeed } = params as Record<string, unknown>;
return ipcRenderer.invoke('download-mp3', {
url: url != null ? url : undefined,
sourceFilePath: sourceFilePath != null ? sourceFilePath : undefined,
title: title != null ? title : undefined,
startTime: startTime != null ? startTime : undefined,
endTime: endTime != null ? endTime : undefined,
playbackSpeed: playbackSpeed != null ? playbackSpeed : undefined,
});
},
showItemInFolder: (filePath: unknown) => {
if (typeof filePath !== 'string') {
return Promise.reject(new Error('filePath must be a string'));
}
return ipcRenderer.invoke('show-item-in-folder', { filePath });
},
onProcessingPhase: (callback: (phase: 'downloading' | 'converting') => void) => {
const listener = (_event: unknown, phase: 'downloading' | 'converting') => callback(phase);
ipcRenderer.on('processing-phase', listener);
return () => {
ipcRenderer.removeListener('processing-phase', listener);
};
},
});