fix audio stream shutdown

This commit is contained in:
riqo 2021-04-26 07:22:38 -05:00
commit 7c2f3cad8c
2 changed files with 24 additions and 14 deletions

View file

@ -165,15 +165,24 @@ export function play(input: string): void {
// -------------------------------------------------------------
// Get's called on window close.
// export function stopStream() {
// console.log("AUDIO:Stopping audio stream.")
// if (ai) {
// ai.quit()
// }
// if (ao) {
// ao.quit()
// }
// console.log("AUDIO:Audio closed.")
// }
export async function stopStream() {
console.log("AUDIO:Stopping audio stream.")
if (ai) {
try {
await ai.quit()
} catch(e){
console.log('AUDIO: Failed to shutdown audio input.');
throw e;
}
}
if (ao) {
try {
await ao.quit()
} catch(e){
console.log('AUDIO: Failed to shutdown audio output.');
throw e;
}
}
}

View file

@ -4,7 +4,7 @@
import { app, dialog } from "electron";
import { createWindow } from './window';
import { initSession } from './session';
import { initAudioIO } from './audio';
import { initAudioIO, stopStream } from './audio';
import { backgroundMitt } from '@/modules/emitter';
let win: boolean;
@ -63,7 +63,8 @@ export function initApp(dev: boolean): void {
});
// Must keep to ensure app doesn't quit on close.
app.on("before-quit", () => {
app.on("before-quit", async () => {
await stopStream();
});
// Must keep to ensure app doesn't quit on close.