Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions src_desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdio>
#include <memory>
#include <string>
#include <vector>

// Project includes
#include "shared/desktop/WebsocketClient.h"
Expand Down Expand Up @@ -47,7 +48,7 @@
std::string get_noto_color_emoji_path() {
std::string result;
const char *cmd = "fc-list :family=file | grep -i 'Noto Color Emoji' | awk -F: '{print $1}' | head -n 1";
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);

Check warning on line 51 in src_desktop/main.cpp

View workflow job for this annotation

GitHub Actions / build (desktop-linux, ubuntu-latest, desktop-linux, desktop-linux-build, desktop_build/led-matrix...

ignoring attributes on template argument ‘int (*)(FILE*)’ [-Wignored-attributes]
if (!pipe)
return result;
char buffer[512];
Expand Down Expand Up @@ -193,9 +194,9 @@
HelloImGui::SetAssetsFolder((get_exec_dir() / ".." / "assets").string());

// Single instance manager
SingleInstanceManager *instanceManager = nullptr;
std::unique_ptr<SingleInstanceManager> instanceManager;
try {
instanceManager = new SingleInstanceManager("LedMatrixController", [] {
instanceManager = std::make_unique<SingleInstanceManager>("LedMatrixController", [] {
spdlog::info("Focus request received, showing main window.");
showMainWindow = true;
});
Expand All @@ -217,7 +218,7 @@
g_shutdown_port = generalCfgRef.getPort();
g_should_turn_off_on_exit = generalCfgRef.isTurnMatrixOffOnExit();

static WebsocketClient *ws;
static std::unique_ptr<WebsocketClient> ws;
static UpdateChecker::UpdateManager updateManager;
static MatrixVersionChecker::MatrixVersionManager matrixVersionManager;

Expand Down Expand Up @@ -262,12 +263,13 @@
}

bool somethingInvalid = false;
if (hostname.empty()) {
const auto mark_last_item_invalid = [] {
const ImVec2 min = ImGui::GetItemRectMin();
const ImVec2 max = ImGui::GetItemRectMax();
ImDrawList *draw_list = ImGui::GetWindowDrawList();

draw_list->AddRect(min, max, IM_COL32(255, 0, 0, 255), 0.0f, 0, 2.0f); // 2.0f = thickness
ImGui::GetWindowDrawList()->AddRect(min, max, IM_COL32(255, 0, 0, 255), 0.0f, 0, 2.0f);
};
if (hostname.empty()) {
mark_last_item_invalid();
somethingInvalid = true;
}

Expand All @@ -278,11 +280,7 @@
}

if (port < 1 || port > 65535) {
const ImVec2 min = ImGui::GetItemRectMin();
const ImVec2 max = ImGui::GetItemRectMax();
ImDrawList *draw_list = ImGui::GetWindowDrawList();

draw_list->AddRect(min, max, IM_COL32(255, 0, 0, 255), 0.0f, 0, 2.0f); // 2.0f = thickness
mark_last_item_invalid();
somethingInvalid = true;
}

Expand All @@ -296,10 +294,7 @@
HelloImGui::GetRunnerParams()->fpsIdling.fpsIdle = fpsLimit;
}
if (fpsLimit < 1 || fpsLimit > 360) {
const ImVec2 min = ImGui::GetItemRectMin();
const ImVec2 max = ImGui::GetItemRectMax();
ImDrawList *draw_list = ImGui::GetWindowDrawList();
draw_list->AddRect(min, max, IM_COL32(255, 0, 0, 255), 0.0f, 0, 2.0f);
mark_last_item_invalid();
somethingInvalid = true;
}

Expand Down Expand Up @@ -351,7 +346,7 @@
const std::string stateStr = ws->getReadyStateString();
std::string statusText = "WebSocket is currently: " + stateStr;

ImGui::Text(statusText.c_str());

Check warning on line 349 in src_desktop/main.cpp

View workflow job for this annotation

GitHub Actions / build (desktop-linux, ubuntu-latest, desktop-linux, desktop-linux-build, desktop_build/led-matrix...

format not a string literal and no format arguments [-Wformat-security]
if (state != ix::ReadyState::Open) {
if (ImGui::Button("Connect", ImVec2(0, 0))) {
ws->setUrl(fmt::format("ws://{}:{}/desktopWebsocket", hostname, port));
Expand All @@ -373,7 +368,7 @@
}
}

ImGui::Text(("Active Scene: " + ws->getActiveScene()).c_str());

Check warning on line 371 in src_desktop/main.cpp

View workflow job for this annotation

GitHub Actions / build (desktop-linux, ubuntu-latest, desktop-linux, desktop-linux-build, desktop_build/led-matrix...

format not a string literal and no format arguments [-Wformat-security]
auto last = ws->getLastError();
if (!last.empty()) {
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Last Error: %s", last.c_str());
Expand Down Expand Up @@ -577,8 +572,8 @@
plugin->post_init();
}
// Only now create the WebsocketClient, so the UDP thread starts after the window is set
ws = new WebsocketClient();
WebsocketClient::setInstance(ws);
ws = std::make_unique<WebsocketClient>();
WebsocketClient::setInstance(ws.get());
// Check for updates on startup
updateManager.checkForUpdatesAsync();
};
Expand Down Expand Up @@ -608,10 +603,9 @@
}
}

delete ws;
ws.reset();
delete cfg;
pl->destroy_plugins();
delete instanceManager;
spdlog::info("Exited cleanly.");
return 0;
}
Expand All @@ -627,23 +621,34 @@
LPWSTR *argv_w = CommandLineToArgvW(fullCmdLine, &argc);
if (!argv_w)
return -1;
char **argv = new char *[argc];

std::vector<std::string> argv_storage;
argv_storage.reserve(argc);
std::vector<char *> argv;
argv.reserve(argc);

for (int i = 0; i < argc; ++i) {
const int len = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, nullptr, 0, nullptr, nullptr);
if (len <= 0) {
for (int j = 0; j < i; ++j)
delete[] argv[j];
delete[] argv;
LocalFree(argv_w);
return -1;
}
argv[i] = new char[len];
WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, argv[i], len, nullptr, nullptr);

std::string arg(static_cast<size_t>(len), '\0');
const int written = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, arg.data(), len, nullptr, nullptr);
if (written <= 0) {
LocalFree(argv_w);
return -1;
}
arg.resize(static_cast<size_t>(written) - 1);
argv_storage.push_back(std::move(arg));
}

for (auto &arg: argv_storage) {
argv.push_back(arg.data());
}
const int result = inner_main(argc, argv);
for (int i = 0; i < argc; ++i)
delete[] argv[i];
delete[] argv;

const int result = inner_main(argc, argv.data());
LocalFree(argv_w);
return result;
}
Expand Down
Loading