mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Only allow one instance of the bluetooth widget
This works analogous to the audio flyin Fixes https://github.com/scorpion-26/gBar/issues/21
This commit is contained in:
parent
18f3e123ed
commit
fcf4d75ea0
1 changed files with 25 additions and 9 deletions
34
src/gBar.cpp
34
src/gBar.cpp
|
@ -11,22 +11,24 @@
|
|||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
|
||||
const char* audioTmpFileOpen = "/tmp/gBar__audio";
|
||||
const char* audioTmpFilePath = "/tmp/gBar__audio";
|
||||
const char* bluetoothTmpFilePath = "/tmp/gBar__bluetooth";
|
||||
|
||||
static bool tmpFileOpen = false;
|
||||
|
||||
static bool flyin = false;
|
||||
void OpenAudioFlyin(Window& window, int32_t monitor, AudioFlyin::Type type)
|
||||
{
|
||||
flyin = true;
|
||||
if (access(audioTmpFileOpen, F_OK) != 0)
|
||||
tmpFileOpen = true;
|
||||
if (access(audioTmpFilePath, F_OK) != 0)
|
||||
{
|
||||
FILE* audioTempFile = fopen(audioTmpFileOpen, "w");
|
||||
FILE* audioTempFile = fopen(audioTmpFilePath, "w");
|
||||
AudioFlyin::Create(window, monitor, type);
|
||||
fclose(audioTempFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already open, close
|
||||
LOG("Audio flyin already open");
|
||||
LOG("Audio flyin already open (/tmp/gBar__audio exists)! Exiting...");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +63,19 @@ int main(int argc, char** argv)
|
|||
{
|
||||
if (RuntimeConfig::Get().hasBlueZ)
|
||||
{
|
||||
BluetoothDevices::Create(window, monitor);
|
||||
if (access(bluetoothTmpFilePath, F_OK) != 0)
|
||||
{
|
||||
tmpFileOpen = true;
|
||||
FILE* bluetoothTmpFile = fopen(bluetoothTmpFilePath, "w");
|
||||
BluetoothDevices::Create(window, monitor);
|
||||
fclose(bluetoothTmpFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already open, close
|
||||
LOG("Bluetooth widget already open (/tmp/gBar__bluetooth exists)! Exiting...");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -78,9 +92,11 @@ int main(int argc, char** argv)
|
|||
window.Run();
|
||||
|
||||
System::FreeResources();
|
||||
if (flyin)
|
||||
if (tmpFileOpen)
|
||||
{
|
||||
remove(audioTmpFileOpen);
|
||||
remove(audioTmpFilePath);
|
||||
LOG("Remove bt");
|
||||
remove(bluetoothTmpFilePath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue