[client] audio: cancel confirm dialog when a new recording starts

This commit is contained in:
Quantum 2022-03-18 02:14:52 -04:00 committed by Geoffrey McRae
parent 9afe170413
commit 8f45290beb

View File

@ -118,12 +118,16 @@ typedef struct
struct struct
{ {
bool started; bool started;
int volumeChannels; int volumeChannels;
uint16_t volume[8]; uint16_t volume[8];
bool mute; bool mute;
int stride; int stride;
uint32_t time; uint32_t time;
MsgBoxHandle confirmHandle;
int confirmChannels;
int confirmSampleRate;
PSAudioFormat confirmFormat;
} }
record; record;
} }
@ -767,14 +771,17 @@ static void recordConfirm(bool yes, void * opaque)
{ {
if (yes) if (yes)
{ {
struct AudioFormat * format = opaque;
DEBUG_INFO("Microphone access granted"); DEBUG_INFO("Microphone access granted");
realRecordStart(format->channels, format->sampleRate, format->format); realRecordStart(
audio.record.confirmChannels,
audio.record.confirmSampleRate,
audio.record.confirmFormat
);
} }
else else
DEBUG_INFO("Microphone access denied"); DEBUG_INFO("Microphone access denied");
free(opaque); audio.record.confirmHandle = NULL;
} }
void audio_recordStart(int channels, int sampleRate, PSAudioFormat format) void audio_recordStart(int channels, int sampleRate, PSAudioFormat format)
@ -803,15 +810,14 @@ void audio_recordStart(int channels, int sampleRate, PSAudioFormat format)
} }
else else
{ {
struct AudioFormat * fmt = malloc(sizeof(*fmt)); if (audio.record.confirmHandle)
if (!format) app_msgBoxClose(audio.record.confirmHandle);
DEBUG_FATAL("Failed to allocate memory!");
fmt->channels = channels; audio.record.confirmChannels = channels;
fmt->sampleRate = sampleRate; audio.record.confirmSampleRate = sampleRate;
fmt->format = format; audio.record.confirmFormat = format;
audio.record.confirmHandle = app_confirmMsgBox(
app_confirmMsgBox("Microphone", recordConfirm, fmt, "Microphone", recordConfirm, NULL,
"An application just opened the microphone!\n" "An application just opened the microphone!\n"
"Do you want it to access your microphone?"); "Do you want it to access your microphone?");
} }