-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreload.mjs
More file actions
25 lines (22 loc) · 1.05 KB
/
preload.mjs
File metadata and controls
25 lines (22 loc) · 1.05 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
import { contextBridge, ipcRenderer } from 'electron'
import path from 'node:path'
contextBridge.exposeInMainWorld('electronAPI', {
selectFiles: () => ipcRenderer.invoke('select-files'),
renderTemplates: (data) => ipcRenderer.invoke('render-templates', data),
calculateCRC32: (filePath) => ipcRenderer.invoke('calculateCRC32', filePath),
createTorrent: (files, pieceLength) => ipcRenderer.invoke('createTorrent', files, pieceLength),
basename: (filePath) => path.basename(filePath),
calculateTotalSize: (files) => ipcRenderer.invoke('calculateTotalSize', files),
getSystemInfo: () => ipcRenderer.invoke('get-system-info'),
handleDrop: (filePaths) => ipcRenderer.invoke('handle-drop', filePaths) // 添加 handleDrop 方法
})
// 安全警告
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type])
}
})