diff --git a/main/main.js b/main/main.js index 168ed62..0e3a63b 100644 --- a/main/main.js +++ b/main/main.js @@ -1,5 +1,31 @@ const { app, BrowserWindow, ipcMain } = require("electron"); const path = require("path"); +const { spawn } = require('child_process') + +// 音效播放器 +function playAudioFile(filePath) { + if (process.platform === 'win32') { + spawn('cmd', ['/c', `start "" "${filePath}"`]) + } else if (process.platform === 'darwin') { + spawn('afplay', [filePath]) + } else { + spawn('aplay', [filePath]) + } +} + +ipcMain.on('play-sound', (_, soundFile) => { + const soundPath = path.join( + __dirname, + '../renderer/src/assets/sounds', + soundFile + ) + + if (require('fs').existsSync(soundPath)) { + playAudioFile(soundPath) + } else { + console.error('音效文件不存在:', soundPath) + } +}) let mainWindow; diff --git a/main/preload.js b/main/preload.js index f1c12f6..d6d8655 100644 --- a/main/preload.js +++ b/main/preload.js @@ -1,7 +1,13 @@ const { contextBridge, ipcRenderer } = require('electron') contextBridge.exposeInMainWorld('electronAPI', { - playSound: (soundFile) => ipcRenderer.send('play-sound', soundFile), + playSound: (soundFile) => { + try { + ipcRenderer.send('play-sound', soundFile) + } catch (err) { + console.error('播放音效失败:', err) + } + }, showTooltip: (text) => ipcRenderer.send('show-tooltip', text), onUpdatePosition: (callback) => { ipcRenderer.on('update-position', (_, position) => callback(position)) diff --git a/renderer/src/App.vue b/renderer/src/App.vue index 22ca06b..d1af811 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -9,7 +9,16 @@ const tooltips = [ "为什么不开大!!", "(凤鸣)", ]; -const soundFiles = ["example.mp3"]; +const soundFiles = [ + "cnmb.mp3", + "冲刺,冲.mp3", + "哎你怎么死了.mp3", + "哎,猪逼.mp3", + "啊啊啊我草你妈呀.mp3", + "嘟嘟嘟.mp3", + "韭菜盒子.mp3", + "哇袄.mp3" +]; // 状态管理 const showTooltip = ref(false); @@ -17,9 +26,15 @@ const currentTooltip = ref(""); const position = ref({ x: 0, y: 0 }); // 点击事件处理 -const handleClick = () => { +const handleClick = async () => { const randomSound = soundFiles[Math.floor(Math.random() * soundFiles.length)]; - window.electronAPI?.playSound(randomSound); + console.log('尝试播放:', randomSound) + + try { + window.electronAPI?.playSound(randomSound) + } catch (err) { + console.error('播放失败:', err) + } currentTooltip.value = tooltips[Math.floor(Math.random() * tooltips.length)]; showTooltip.value = true; diff --git a/renderer/src/assets/sounds/cnmb.mp3 b/renderer/src/assets/sounds/cnmb.mp3 new file mode 100644 index 0000000..dfaf8ab Binary files /dev/null and b/renderer/src/assets/sounds/cnmb.mp3 differ diff --git a/renderer/src/assets/sounds/冲刺,冲.mp3 b/renderer/src/assets/sounds/冲刺,冲.mp3 new file mode 100644 index 0000000..cccc627 Binary files /dev/null and b/renderer/src/assets/sounds/冲刺,冲.mp3 differ diff --git a/renderer/src/assets/sounds/哇袄.mp3 b/renderer/src/assets/sounds/哇袄.mp3 new file mode 100644 index 0000000..28eb275 Binary files /dev/null and b/renderer/src/assets/sounds/哇袄.mp3 differ diff --git a/renderer/src/assets/sounds/哎你怎么死了.mp3 b/renderer/src/assets/sounds/哎你怎么死了.mp3 new file mode 100644 index 0000000..6436a39 Binary files /dev/null and b/renderer/src/assets/sounds/哎你怎么死了.mp3 differ diff --git a/renderer/src/assets/sounds/哎,猪逼.mp3 b/renderer/src/assets/sounds/哎,猪逼.mp3 new file mode 100644 index 0000000..3778bc8 Binary files /dev/null and b/renderer/src/assets/sounds/哎,猪逼.mp3 differ diff --git a/renderer/src/assets/sounds/啊啊啊我草你妈呀.mp3 b/renderer/src/assets/sounds/啊啊啊我草你妈呀.mp3 new file mode 100644 index 0000000..e5b75ef Binary files /dev/null and b/renderer/src/assets/sounds/啊啊啊我草你妈呀.mp3 differ diff --git a/renderer/src/assets/sounds/嘟嘟嘟.mp3 b/renderer/src/assets/sounds/嘟嘟嘟.mp3 new file mode 100644 index 0000000..6d8839c Binary files /dev/null and b/renderer/src/assets/sounds/嘟嘟嘟.mp3 differ diff --git a/renderer/src/assets/sounds/韭菜盒子.mp3 b/renderer/src/assets/sounds/韭菜盒子.mp3 new file mode 100644 index 0000000..a0248cc Binary files /dev/null and b/renderer/src/assets/sounds/韭菜盒子.mp3 differ