From 8f45290bebcc6e856b4d0fbe2dbb21888f00adc4 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 18 Mar 2022 02:14:52 -0400 Subject: [PATCH] [client] audio: cancel confirm dialog when a new recording starts --- client/src/audio.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/client/src/audio.c b/client/src/audio.c index 3aacbe60..43e14b03 100644 --- a/client/src/audio.c +++ b/client/src/audio.c @@ -118,12 +118,16 @@ typedef struct struct { - bool started; - int volumeChannels; - uint16_t volume[8]; - bool mute; - int stride; - uint32_t time; + bool started; + int volumeChannels; + uint16_t volume[8]; + bool mute; + int stride; + uint32_t time; + MsgBoxHandle confirmHandle; + int confirmChannels; + int confirmSampleRate; + PSAudioFormat confirmFormat; } record; } @@ -767,14 +771,17 @@ static void recordConfirm(bool yes, void * opaque) { if (yes) { - struct AudioFormat * format = opaque; DEBUG_INFO("Microphone access granted"); - realRecordStart(format->channels, format->sampleRate, format->format); + realRecordStart( + audio.record.confirmChannels, + audio.record.confirmSampleRate, + audio.record.confirmFormat + ); } else DEBUG_INFO("Microphone access denied"); - free(opaque); + audio.record.confirmHandle = NULL; } void audio_recordStart(int channels, int sampleRate, PSAudioFormat format) @@ -803,15 +810,14 @@ void audio_recordStart(int channels, int sampleRate, PSAudioFormat format) } else { - struct AudioFormat * fmt = malloc(sizeof(*fmt)); - if (!format) - DEBUG_FATAL("Failed to allocate memory!"); + if (audio.record.confirmHandle) + app_msgBoxClose(audio.record.confirmHandle); - fmt->channels = channels; - fmt->sampleRate = sampleRate; - fmt->format = format; - - app_confirmMsgBox("Microphone", recordConfirm, fmt, + audio.record.confirmChannels = channels; + audio.record.confirmSampleRate = sampleRate; + audio.record.confirmFormat = format; + audio.record.confirmHandle = app_confirmMsgBox( + "Microphone", recordConfirm, NULL, "An application just opened the microphone!\n" "Do you want it to access your microphone?"); }