From 1cb8fd6e49d4a3bc1254c9081ed16b3c40876b31 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Fri, 3 Apr 2026 21:14:01 +1100 Subject: [PATCH] feat: add sound resource handling and IPC for sound URL retrieval --- cinny | 2 +- electron-builder.json5 | 5 +++++ electron/main.js | 12 +++++++++++- electron/preload.js | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cinny b/cinny index fe193bb..f64ce61 160000 --- a/cinny +++ b/cinny @@ -1 +1 @@ -Subproject commit fe193bb0622b6f974602fe143406f0bbecbb2ac5 +Subproject commit f64ce6168d6e22143e81cf7a572ca645dbf40f44 diff --git a/electron-builder.json5 b/electron-builder.json5 index 94d6fa1..28e0d66 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -28,6 +28,11 @@ "from": "icons", "to": "icons", "filter": ["**/*"] + }, + { + "from": "cinny/public/sound", + "to": "sound", + "filter": ["**/*"] } ], "linux": { diff --git a/electron/main.js b/electron/main.js index b537409..9d527af 100644 --- a/electron/main.js +++ b/electron/main.js @@ -841,6 +841,11 @@ ipcMain.handle('write-clipboard-text', async (event, text) => { } }); +ipcMain.handle('get-sound-base-url', () => { + if (isDev) return null; // renderer uses ./sound/ relative path in dev + return `file://${path.join(process.resourcesPath, 'sound').replace(/\\/g, '/')}`; +}); + // Play notification sound via the renderer's Chromium audio engine. // Chromium has native OGG support on all platforms, so this is always reliable. ipcMain.handle('play-notification-sound', async (event, soundType = 'message') => { @@ -848,9 +853,14 @@ ipcMain.handle('play-notification-sound', async (event, soundType = 'message') = return { success: false, error: 'No main window' }; } const soundFile = soundType === 'invite' ? 'invite.ogg' : 'notification.ogg'; + // In dev, Vite serves sounds via HTTP so relative path works. + // In production, sounds are in resources/sound/ as plain files (extraResources). + const audioSrc = isDev + ? `./sound/${soundFile}` + : `file://${path.join(process.resourcesPath, 'sound', soundFile).replace(/\\/g, '/')}`; try { await mainWindow.webContents.executeJavaScript( - `new Audio('./sound/${soundFile}').play().catch(() => {}); true;` + `new Audio('${audioSrc}').play().catch(() => {}); true;` ); return { success: true }; } catch (error) { diff --git a/electron/preload.js b/electron/preload.js index ab61dd5..571b8fb 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -105,7 +105,8 @@ contextBridge.exposeInMainWorld('electron', { }, // Audio audio: { - playNotificationSound: (soundType = 'message') => ipcRenderer.invoke('play-notification-sound', soundType) + playNotificationSound: (soundType = 'message') => ipcRenderer.invoke('play-notification-sound', soundType), + getSoundBaseUrl: () => ipcRenderer.invoke('get-sound-base-url'), }, // External URLs shell: {