From 3e770368b5ebeba8f5e8e640f655bee47ffd8290 Mon Sep 17 00:00:00 2001 From: Kisechan Date: Fri, 22 Aug 2025 13:59:36 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E8=87=AA=E5=8A=A8=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E9=9F=B3=E6=95=88=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E7=B4=A0=E6=9D=90=E9=9A=8F=E6=9C=BA=E6=92=AD=E6=94=BE=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E9=85=8D=E5=A4=87=E5=AF=B9=E5=BA=94=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.js | 17 ++++++++++++++ main/preload.js | 1 + renderer/src/App.vue | 53 ++++++++++++++++++++++++++------------------ 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/main/main.js b/main/main.js index ab8cca6..32dc9d9 100644 --- a/main/main.js +++ b/main/main.js @@ -1,6 +1,7 @@ const { app, BrowserWindow, ipcMain } = require("electron"); const path = require("path"); const { spawn } = require('child_process') +const fs = require("fs"); // 音效播放器 function playAudioFile(filePath) { @@ -52,6 +53,22 @@ ipcMain.handle('get-sound-path', (_, soundFile) => { } }); +ipcMain.handle('get-sound-files', async () => { + const soundDir = process.env.NODE_ENV === 'development' + ? path.join(__dirname, '../renderer/public/assets/sounds') + : path.join(__dirname, '../renderer/dist/assets/sounds'); + + try { + // 读取目录下的所有文件名 + const files = await fs.promises.readdir(soundDir); + // 筛选出 .mp3 文件并返回 + return files.filter(file => file.endsWith('.mp3')); + } catch (error) { + console.error('无法读取声音目录:', error); + return []; // 如果出错则返回空数组 + } +}); + let mainWindow; function createWindow() { diff --git a/main/preload.js b/main/preload.js index 55f4551..e078257 100644 --- a/main/preload.js +++ b/main/preload.js @@ -9,6 +9,7 @@ contextBridge.exposeInMainWorld('electronAPI', { } }, getSoundPath: (soundFile) => ipcRenderer.invoke('get-sound-path', soundFile), + getSoundFiles: () => ipcRenderer.invoke('get-sound-files'), 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 2c664e7..5fe61c1 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -1,34 +1,44 @@