diff --git a/src/background/audio.ts b/src/background/audio.ts index 6dd3bdd..0a98206 100644 --- a/src/background/audio.ts +++ b/src/background/audio.ts @@ -40,7 +40,7 @@ const onRecordingEnd = async (_event: any, payload: any) => { try { resolve(audioContainer.input); - record = false; + record = false; } catch (e) { reject() } @@ -120,7 +120,7 @@ export function play(input: string): void { // Format the audio. const audio = bufSplit( - Buffer.from(input as string, 'hex'), + Buffer.from(input as string, 'hex'), 8192 ); @@ -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; + } + } +} diff --git a/src/background/helpers.ts b/src/background/helpers.ts index bd3d279..f0074fb 100644 --- a/src/background/helpers.ts +++ b/src/background/helpers.ts @@ -1,7 +1,9 @@ import fs from 'fs'; import { backgroundMitt } from "@/modules/emitter"; import { SessionState, WindowState } from "@/types"; +import { app } from "electron"; +const configPath = app.getPath("userData"); export const ipcEmit = (channel: string, payload: any) => { backgroundMitt.emit('ipc-renderer', { @@ -14,7 +16,7 @@ export const loadState = (fileName: string): SessionState => { let state: SessionState; try { - state = JSON.parse(fs.readFileSync(fileName).toString()); + state = JSON.parse(fs.readFileSync(configPath + fileName).toString()); } catch (error) { @@ -32,7 +34,7 @@ export const loadWinState = (fileName: string): WindowState => { let state: WindowState; try { - state = JSON.parse(fs.readFileSync(fileName).toString()); + state = JSON.parse(fs.readFileSync(configPath + fileName).toString()); } catch (error) { @@ -51,7 +53,7 @@ export const loadWinState = (fileName: string): WindowState => { // Save session or window state. export const saveToJson = (fileName: string, data: any) => { - fs.writeFile(fileName, JSON.stringify(data), (err) => { + fs.writeFile(configPath + fileName, JSON.stringify(data), (err) => { if (err) { console.log("Error when saving to json.") } diff --git a/src/background/init.ts b/src/background/init.ts index 22f0cbe..f251246 100644 --- a/src/background/init.ts +++ b/src/background/init.ts @@ -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. diff --git a/src/components/settings.vue b/src/components/settings.vue index a70b797..51347b2 100644 --- a/src/components/settings.vue +++ b/src/components/settings.vue @@ -1,8 +1,8 @@ @@ -27,7 +29,7 @@ import { defineComponent, ref } from "vue"; import { useIpc } from "@/modules/ipc"; - import { logoutRequest } from '@/modules/message'; + import { logoutRequest } from '@/modules/message'; export default defineComponent({ name: "Settings", @@ -58,7 +60,7 @@ } return { - onActive, + onActive, toggleSettings, onLogout } @@ -141,6 +143,11 @@ border: none; outline: none; text-decoration: none; + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + z-index: 5; } .settingsOption:hover {