Merge pull request #1 from SKATTKOOKIE/feature/voice-connect-sounds

Add voice channel connect/disconnect sounds
This commit is contained in:
Brandon 2026-02-26 16:55:07 +00:00 committed by GitHub
commit b8a2e13f05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12030 additions and 0 deletions

11966
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

60
src/native/sounds.ts Normal file
View File

@ -0,0 +1,60 @@
export function injectSounds(webContents: Electron.WebContents) {
webContents.on("did-finish-load", () => {
webContents.executeJavaScript(`
(function() {
if (window.__soundsInjected) return;
window.__soundsInjected = true;
let ctx = null;
function getAudioContext() {
if (!ctx) ctx = new AudioContext();
return ctx;
}
function playTone(frequency, duration, volume = 0.1) {
try {
const audio = getAudioContext();
const oscillator = audio.createOscillator();
const gain = audio.createGain();
oscillator.connect(gain);
gain.connect(audio.destination);
oscillator.type = "sine";
oscillator.frequency.value = frequency;
gain.gain.setValueAtTime(volume, audio.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, audio.currentTime + duration);
oscillator.start(audio.currentTime);
oscillator.stop(audio.currentTime + duration);
} catch(e) {}
}
function playConnectSound() {
playTone(660, 0.15);
setTimeout(() => playTone(880, 0.2), 150);
}
function playDisconnectSound() {
playTone(880, 0.15);
setTimeout(() => playTone(440, 0.3), 150);
}
const OriginalWebSocket = window.WebSocket;
window.WebSocket = class extends OriginalWebSocket {
constructor(...args) {
super(...args);
this.addEventListener("message", (event) => {
try {
const data = JSON.parse(event.data);
if (data.type === "VoiceChannelJoin") playConnectSound();
if (data.type === "VoiceChannelLeave") playDisconnectSound();
} catch {}
});
}
};
})();
`);
});
}

View File

@ -1,4 +1,5 @@
import { join } from "node:path";
import { injectSounds } from "./sounds";
import {
BrowserWindow,
@ -86,6 +87,9 @@ export function createMainWindow() {
// load the entrypoint
mainWindow.loadURL(BUILD_URL.toString());
// Load connect and disconnect sounds
injectSounds(mainWindow.webContents);
// minimise window to tray
mainWindow.on("close", (event) => {
if (!shouldQuit && config.minimiseToTray) {