From 1f954aad35bf0310de4d0201f8e318cc68768100 Mon Sep 17 00:00:00 2001 From: Kisechan Date: Fri, 8 Aug 2025 20:06:52 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20=E4=BD=BF=E7=94=A8=20howler=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9F=B3=E6=95=88=E6=92=AD=E6=94=BE=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.js | 19 +++++++++++++++++++ main/preload.js | 1 + renderer/src/App.vue | 20 ++++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/main/main.js b/main/main.js index 4fc5268..daea768 100644 --- a/main/main.js +++ b/main/main.js @@ -34,6 +34,24 @@ ipcMain.on('play-sound', (_, soundFile) => { } }); +ipcMain.handle('get-sound-path', (_, soundFile) => { + let soundPath; + + if (process.env.NODE_ENV === 'development') { + soundPath = path.join(__dirname, '../renderer/public/assets/sounds', soundFile); + } else { + soundPath = path.join(__dirname, '../renderer/dist/assets/sounds', soundFile); + } + + if (require('fs').existsSync(soundPath)) { + // 返回一个可供 web 环境使用的 file 协议 URL + return `file://${soundPath}`; + } else { + console.error('Sound file not found:', soundPath); + return null; + } +}); + let mainWindow; function createWindow() { @@ -46,6 +64,7 @@ function createWindow() { webPreferences: { preload: path.join(__dirname, "preload.js"), contextIsolation: true, + webSecurity: false, // 信任应用,并允许加载本地资源 }, }); diff --git a/main/preload.js b/main/preload.js index d6d8655..55f4551 100644 --- a/main/preload.js +++ b/main/preload.js @@ -8,6 +8,7 @@ contextBridge.exposeInMainWorld('electronAPI', { console.error('播放音效失败:', err) } }, + getSoundPath: (soundFile) => ipcRenderer.invoke('get-sound-path', soundFile), 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 d1af811..67e1b34 100644 --- a/renderer/src/App.vue +++ b/renderer/src/App.vue @@ -1,6 +1,7 @@