feat: add sound resource handling and IPC for sound URL retrieval
Some checks failed
Build / increment-version (push) Successful in 7s
Build / build-linux (push) Successful in 1m56s
Build / build-windows (push) Successful in 5m16s
Build Paarrot Windows / start-vm (push) Failing after 5m33s
Build Paarrot Windows / build (push) Has been skipped
Build / create-release (push) Successful in 17s

This commit is contained in:
2026-04-03 21:14:01 +11:00
parent 7857e42c5a
commit 1cb8fd6e49
4 changed files with 19 additions and 3 deletions

2
cinny

Submodule cinny updated: fe193bb062...f64ce6168d

View File

@@ -28,6 +28,11 @@
"from": "icons",
"to": "icons",
"filter": ["**/*"]
},
{
"from": "cinny/public/sound",
"to": "sound",
"filter": ["**/*"]
}
],
"linux": {

View File

@@ -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) {

View File

@@ -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: {