调整项目结构:前端和 Electron 核心

This commit is contained in:
2025-08-06 07:44:19 +08:00
parent 499f6205fa
commit cbe3f72d1c
19 changed files with 3836 additions and 1329 deletions

View File

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
let mainWindow
@ -10,16 +10,21 @@ function createWindow() {
transparent: true,
frame: false,
webPreferences: {
preload: path.join(__dirname, '../renderer/src/preload.js'),
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true
}
})
mainWindow.loadURL(
process.env.NODE_ENV === 'development'
? 'http://localhost:5173'
: `file://${path.join(__dirname, '../renderer/dist/index.html')}`
)
// 开发模式加载Vite服务器
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:5173')
} else {
mainWindow.loadFile(path.join(__dirname, '../renderer/dist/index.html'))
}
mainWindow.setIgnoreMouseEvents(true, {
forward: true
})
}
app.whenReady().then(createWindow)

6
main/preload.js Normal file
View File

@ -0,0 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
playSound: (file) => ipcRenderer.send('play-sound', file),
showTooltip: (text) => ipcRenderer.send('show-tooltip', text)
})