From 43dd0777a80be95736ae313b5b7d81a5946487fa Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Fri, 14 Jul 2023 19:46:27 +0200 Subject: [PATCH] Remove tmp files on SIGINT This allows the use of Ctrl-C without leaving stale files behind which need to be deleted --- src/gBar.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gBar.cpp b/src/gBar.cpp index cc2439c..ad497ae 100644 --- a/src/gBar.cpp +++ b/src/gBar.cpp @@ -33,8 +33,20 @@ void OpenAudioFlyin(Window& window, int32_t monitor, AudioFlyin::Type type) } } +void CloseTmpFiles(int sig) +{ + if (tmpFileOpen) + { + remove(audioTmpFilePath); + remove(bluetoothTmpFilePath); + } + if (sig != 0) + exit(1); +} + int main(int argc, char** argv) { + signal(SIGINT, CloseTmpFiles); System::Init(); int32_t monitor = -1; @@ -92,11 +104,6 @@ int main(int argc, char** argv) window.Run(); System::FreeResources(); - if (tmpFileOpen) - { - remove(audioTmpFilePath); - LOG("Remove bt"); - remove(bluetoothTmpFilePath); - } + CloseTmpFiles(0); return 0; }