make bluetooth service singleton
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "bar/bar.hpp"
|
||||
#include "services/bluetooth.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/notifications.hpp"
|
||||
#include "services/tray.hpp"
|
||||
@@ -23,7 +22,6 @@ class App {
|
||||
HyprlandService hyprlandService;
|
||||
NotificationService notificationService;
|
||||
TrayService trayService;
|
||||
BluetoothService bluetoothService;
|
||||
|
||||
void setupServices();
|
||||
};
|
||||
@@ -4,20 +4,19 @@
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "icons.hpp"
|
||||
#include "services/bluetooth.hpp"
|
||||
#include "services/hyprland.hpp"
|
||||
#include "services/tray.hpp"
|
||||
#include "widgets/bluetooth.hpp"
|
||||
#include "widgets/clock.hpp"
|
||||
#include "widgets/date.hpp"
|
||||
#include "widgets/tray.hpp"
|
||||
#include "widgets/volumeWidget.hpp"
|
||||
#include "widgets/webWidget.hpp"
|
||||
#include "widgets/workspaceIndicator.hpp"
|
||||
#include "widgets/controlCenter.hpp"
|
||||
|
||||
class Bar : public Gtk::Window {
|
||||
public:
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, BluetoothService &bluetoothService, int monitorId);
|
||||
Bar(GdkMonitor *monitor, HyprlandService &hyprlandService, TrayService &trayService, int monitorId);
|
||||
|
||||
protected:
|
||||
Gtk::CenterBox main_box{};
|
||||
@@ -31,15 +30,14 @@ class Bar : public Gtk::Window {
|
||||
Clock clock;
|
||||
Date date;
|
||||
WebWidget homeAssistant{ICON_HOME, "Home Assistant", "https://home.rivercry.com"};
|
||||
ControlCenter controlCenter{"\ue8bb", "Control Center"};
|
||||
|
||||
WorkspaceIndicator *workspaceIndicator = nullptr;
|
||||
TrayWidget *trayWidget = nullptr;
|
||||
VolumeWidget *volumeWidget = nullptr;
|
||||
BluetoothWidget *bluetoothWidget = nullptr;
|
||||
|
||||
TrayService &trayService;
|
||||
HyprlandService &hyprlandService;
|
||||
BluetoothService &bluetoothService;
|
||||
|
||||
void setup_ui();
|
||||
void setup_left_box();
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "sigc++/signal.h"
|
||||
|
||||
class BluetoothService {
|
||||
static BluetoothService *instance;
|
||||
|
||||
public:
|
||||
BluetoothService();
|
||||
|
||||
sigc::signal<void(bool)> powerStateChangedSignal;
|
||||
|
||||
sigc::signal<void(bool)> isDiscoveringChangedSignal;
|
||||
|
||||
bool getPowerState();
|
||||
@@ -19,10 +22,22 @@ class BluetoothService {
|
||||
void togglePowerState();
|
||||
void toggleIsDiscovering();
|
||||
|
||||
private:
|
||||
static BluetoothService *getInstance() {
|
||||
if (BluetoothService::instance == nullptr) {
|
||||
|
||||
BluetoothService::instance = new BluetoothService();
|
||||
}
|
||||
return BluetoothService::instance;
|
||||
}
|
||||
|
||||
private:
|
||||
BluetoothService();
|
||||
|
||||
GDBusProxy *adapter_proxy = nullptr;
|
||||
bool powerState = false;
|
||||
bool isDiscovering = false;
|
||||
|
||||
std::vector<std::string> getDeviceObjectPaths();
|
||||
bool powerState = false;
|
||||
bool isDiscovering = false;
|
||||
|
||||
void onPropertyChanged(GDBusProxy *proxy,
|
||||
GVariant *changed_properties,
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
|
||||
#include "components/popover.hpp"
|
||||
|
||||
#include "gtkmm/button.h"
|
||||
|
||||
class BluetoothWidget : public Popover {
|
||||
class BluetoothWidget : public Gtk::Box {
|
||||
public:
|
||||
BluetoothWidget(std::string icon, std::string title);
|
||||
BluetoothWidget();
|
||||
|
||||
void setPowerState(bool state);
|
||||
void setIsDiscovering(bool state);
|
||||
@@ -17,19 +14,16 @@ class BluetoothWidget : public Popover {
|
||||
sigc::signal<void()> onIsDiscoveringButtonClickedSignal;
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
bool isPowered = false;
|
||||
bool isPowered = false;
|
||||
bool isDiscovering = false;
|
||||
|
||||
Gtk::Box container;
|
||||
Gtk::Box statusArea;
|
||||
|
||||
Gtk::Box *deviceList = nullptr;
|
||||
|
||||
Gtk::Button *scanButton = nullptr;
|
||||
Gtk::Box *deviceList = nullptr;
|
||||
Gtk::Button *scanButton = nullptr;
|
||||
Gtk::Button *powerButton = nullptr;
|
||||
|
||||
|
||||
void onPowerButtonClicked();
|
||||
void onScanButtonClicked();
|
||||
|
||||
|
||||
17
include/widgets/controlCenter.hpp
Normal file
17
include/widgets/controlCenter.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/popover.hpp"
|
||||
#include "services/bluetooth.hpp"
|
||||
#include "widgets/bluetooth.hpp"
|
||||
#include "gtkmm/box.h"
|
||||
|
||||
class ControlCenter : public Popover {
|
||||
public:
|
||||
ControlCenter(std::string icon, std::string name);
|
||||
|
||||
private:
|
||||
Gtk::Box container;
|
||||
|
||||
BluetoothWidget *bluetoothWidget = nullptr;
|
||||
BluetoothService *bluetoothService = BluetoothService::getInstance();
|
||||
};
|
||||
Reference in New Issue
Block a user