-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
29 lines (23 loc) · 873 Bytes
/
Copy pathpreload.js
File metadata and controls
29 lines (23 loc) · 873 Bytes
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
// 预加载脚本用于在渲染进程中安全地暴露Node.js API
const { contextBridge, ipcRenderer } = require('electron')
// 向渲染进程暴露安全的API
contextBridge.exposeInMainWorld('electronAPI', {
// 应用信息
getVersion: () => ipcRenderer.invoke('get-app-version'),
// 通知功能
showNotification: (title, body, options) => {
new Notification(title, { body, ...options })
},
// 消息框
showMessageBox: (options) => ipcRenderer.invoke('show-message-box', options),
// 系统信息
platform: process.platform,
arch: process.arch,
isDev: process.env.NODE_ENV === 'development'
})
// DOM加载完成后的处理
window.addEventListener('DOMContentLoaded', () => {
console.log('🚀 Electron 预加载脚本已执行')
console.log('📱 平台:', process.platform)
console.log('🏗️ 架构:', process.arch)
})