Skip to content

Commit f6143cf

Browse files
code refactor
1 parent c21c5dd commit f6143cf

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Build
5454
run: |
5555
rm -rf build
56-
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=ON -DBUILD_EXECUTABLE=OFF
56+
cmake -B build . -G Ninja -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -DENABLE_ASAN=OFF -DBUILD_EXECUTABLE=OFF
5757
cmake --build build
5858
cd build && ctest --output-on-failure --verbose
5959

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
88

99
# Testing option
1010
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
11-
option(ENABLE_TESTS "Build tests" OFF)
12-
option(BUILD_EXECUTABLE "Build the main executable" ON)
11+
option(ENABLE_TESTS "Enable Tests" OFF)
12+
option(BUILD_EXECUTABLE "Build The Main Executable" ON)
13+
14+
# UI type option
15+
set(BITCHAT_GUI "CONSOLE" CACHE STRING "UI Type: CONSOLE or DUMMY")
16+
set_property(CACHE BITCHAT_GUI PROPERTY STRINGS "CONSOLE" "DUMMY")
1317

1418
if(ENABLE_TESTS)
1519
enable_testing()
@@ -140,6 +144,9 @@ if(BUILD_EXECUTABLE)
140144
${CMAKE_CURRENT_SOURCE_DIR}/vendor
141145
)
142146

147+
# Add UI macro
148+
target_compile_definitions(bitchat PRIVATE BITCHAT_GUI_${BITCHAT_GUI})
149+
143150
# Link libraries
144151
target_link_libraries(bitchat ${COMMON_LIBRARIES})
145152
endif()

src/main.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "bitchat/services/message_service.h"
88
#include "bitchat/services/network_service.h"
99
#include "bitchat/services/noise_service.h"
10-
#include "bitchat/ui/console_ui.h"
1110
#include <chrono>
1211
#include <ctime>
1312
#include <iostream>
@@ -16,6 +15,14 @@
1615
#include <string>
1716
#include <thread>
1817

18+
// clang-format off
19+
#ifdef BITCHAT_GUI_CONSOLE
20+
#include "bitchat/ui/console_ui.h"
21+
#elif defined(BITCHAT_GUI_DUMMY)
22+
#include "bitchat/ui/dummy_ui.h"
23+
#endif
24+
// clang-format on
25+
1926
using namespace bitchat;
2027

2128
int main()
@@ -48,14 +55,22 @@ int main()
4855
auto bluetoothAnnounceRunner = std::make_shared<bitchat::BluetoothAnnounceRunner>();
4956
auto cleanupRunner = std::make_shared<bitchat::CleanupRunner>();
5057

58+
// clang-format off
5159
// Create UI
52-
auto consoleUserInterface = std::make_shared<bitchat::ConsoleUserInterface>();
60+
#ifdef BITCHAT_GUI_CONSOLE
61+
auto userInterface = std::make_shared<bitchat::ConsoleUserInterface>();
62+
#elif defined(BITCHAT_GUI_DUMMY)
63+
auto userInterface = std::make_shared<bitchat::DummyUserInterface>();
64+
#else
65+
#error "No valid BITCHAT_GUI macro defined"
66+
#endif
67+
// clang-format on
5368

5469
// Create and initialize manager
5570
auto manager = std::make_shared<BitchatManager>();
5671

5772
// Initialize manager
58-
if (!manager->initialize(consoleUserInterface, bluetoothNetworkInterface, networkService, messageService, cryptoService, noiseService, bluetoothAnnounceRunner, cleanupRunner))
73+
if (!manager->initialize(userInterface, bluetoothNetworkInterface, networkService, messageService, cryptoService, noiseService, bluetoothAnnounceRunner, cleanupRunner))
5974
{
6075
spdlog::error("Failed to initialize BitchatManager");
6176
return EXIT_FAILURE;

0 commit comments

Comments
 (0)