2023-01-13 15:13:56 +00:00
|
|
|
#include "Window.h"
|
|
|
|
#include "Common.h"
|
|
|
|
#include "System.h"
|
|
|
|
#include "Bar.h"
|
|
|
|
#include "AudioFlyin.h"
|
2023-01-14 22:18:34 +00:00
|
|
|
#include "BluetoothDevices.h"
|
2023-01-28 14:07:07 +00:00
|
|
|
#include "Plugin.h"
|
2023-01-30 15:57:15 +00:00
|
|
|
#include "Config.h"
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-07-14 17:36:23 +00:00
|
|
|
const char* audioTmpFilePath = "/tmp/gBar__audio";
|
|
|
|
const char* bluetoothTmpFilePath = "/tmp/gBar__bluetooth";
|
|
|
|
|
|
|
|
static bool tmpFileOpen = false;
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-02-22 15:45:29 +00:00
|
|
|
void OpenAudioFlyin(Window& window, int32_t monitor, AudioFlyin::Type type)
|
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
tmpFileOpen = true;
|
|
|
|
if (access(audioTmpFilePath, F_OK) != 0)
|
2023-02-22 15:45:29 +00:00
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
FILE* audioTempFile = fopen(audioTmpFilePath, "w");
|
2023-02-22 15:45:29 +00:00
|
|
|
AudioFlyin::Create(window, monitor, type);
|
|
|
|
fclose(audioTempFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Already open, close
|
2023-07-14 17:36:23 +00:00
|
|
|
LOG("Audio flyin already open (/tmp/gBar__audio exists)! Exiting...");
|
2023-02-22 15:45:29 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 17:46:27 +00:00
|
|
|
void CloseTmpFiles(int sig)
|
|
|
|
{
|
|
|
|
if (tmpFileOpen)
|
|
|
|
{
|
|
|
|
remove(audioTmpFilePath);
|
|
|
|
remove(bluetoothTmpFilePath);
|
|
|
|
}
|
|
|
|
if (sig != 0)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2023-07-14 17:46:27 +00:00
|
|
|
signal(SIGINT, CloseTmpFiles);
|
2023-01-13 15:13:56 +00:00
|
|
|
System::Init();
|
|
|
|
|
|
|
|
int32_t monitor = -1;
|
|
|
|
if (argc >= 3)
|
|
|
|
{
|
|
|
|
monitor = atoi(argv[2]);
|
|
|
|
}
|
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
Window window(monitor);
|
|
|
|
window.Init(argc, argv);
|
2023-01-13 15:13:56 +00:00
|
|
|
ASSERT(argc >= 2, "Too little arguments!");
|
|
|
|
if (strcmp(argv[1], "bar") == 0)
|
|
|
|
{
|
|
|
|
Bar::Create(window, monitor);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "audio") == 0)
|
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Speaker);
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "mic") == 0)
|
|
|
|
{
|
|
|
|
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Microphone);
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-01-30 15:57:15 +00:00
|
|
|
#ifdef WITH_BLUEZ
|
2023-01-14 22:18:34 +00:00
|
|
|
else if (strcmp(argv[1], "bluetooth") == 0)
|
|
|
|
{
|
2023-01-30 15:57:15 +00:00
|
|
|
if (RuntimeConfig::Get().hasBlueZ)
|
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-01-30 15:57:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG("Blutooth disabled, cannot open bluetooth widget!");
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-01-14 22:18:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2023-01-28 14:07:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Plugin::LoadWidgetFromPlugin(argv[1], window, monitor);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
window.Run();
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
System::FreeResources();
|
2023-07-14 17:46:27 +00:00
|
|
|
CloseTmpFiles(0);
|
2023-01-13 15:13:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|