From 75c61fe1937661e3cc554eccc4396be0bf87eb33 Mon Sep 17 00:00:00 2001 From: EinTim23 Date: Sat, 2 Nov 2024 11:25:56 +0100 Subject: [PATCH] added experimental wxwidgets implementation --- .gitmodules | 3 +++ CMakeLists.txt | 15 ++++++++++++--- src/backends/darwin.cpp | 5 +++++ src/backends/linux.cpp | 5 +++++ src/main.cpp | 26 ++++++++++++++++++++++---- vendor/CMakeLists.txt | 5 +++++ vendor/wxWidgets | 1 + 7 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/backends/darwin.cpp create mode 100644 src/backends/linux.cpp create mode 160000 vendor/wxWidgets diff --git a/.gitmodules b/.gitmodules index 2a85b6c..c8c6969 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "vendor/mbedtls"] path = vendor/mbedtls url = https://github.com/Mbed-TLS/mbedtls.git +[submodule "vendor/wxWidgets"] + path = vendor/wxWidgets + url = https://github.com/wxWidgets/wxWidgets.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a99ee5..bba9d5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,18 @@ file(GLOB_RECURSE SOURCES "src/*.cpp") add_executable (rpc ${SOURCES}) set_property(TARGET rpc PROPERTY CXX_STANDARD 20) add_subdirectory("vendor") -set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls) +set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono) if(WIN32) list(APPEND LIBRARIES WindowsApp) endif() -target_link_libraries(rpc PUBLIC ${LIBRARIES}) -target_include_directories(rpc PRIVATE vendor) \ No newline at end of file +file(GLOB wx_setup_dir + "${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/mswu" + "${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/gtk3u" +) +if(wx_setup_dir) + message(STATUS "wxWidgets setup.h directory found: ${wx_setup_dir}") + target_include_directories(rpc PRIVATE vendor vendor/wxWidgets/include ${wx_setup_dir}) +else() + message(FATAL_ERROR "wx/setup.h not found. Please check your wxWidgets build configuration.") +endif() +target_link_libraries(rpc PUBLIC ${LIBRARIES}) \ No newline at end of file diff --git a/src/backends/darwin.cpp b/src/backends/darwin.cpp new file mode 100644 index 0000000..fa4904e --- /dev/null +++ b/src/backends/darwin.cpp @@ -0,0 +1,5 @@ +#ifdef __APPLE__ + +std::shared_ptr backend::getMediaInformation() { return nullptr; } + +#endif \ No newline at end of file diff --git a/src/backends/linux.cpp b/src/backends/linux.cpp new file mode 100644 index 0000000..3935c86 --- /dev/null +++ b/src/backends/linux.cpp @@ -0,0 +1,5 @@ +#if !defined(_WIN32) && !defined(__APPLE__) + +std::shared_ptr backend::getMediaInformation() { return nullptr; } + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 7347d89..098bcda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -7,6 +8,7 @@ #include "backend.hpp" #include "utils.hpp" + std::string lastPlayingSong = ""; std::string lastMediaSource = ""; @@ -26,10 +28,7 @@ void handleRPCTasks() { handleRPCTasks(); // this could theoretically cause a stack overflow if discord is restarted often enough } -int main() { - std::thread rpcThread(handleRPCTasks); - rpcThread.detach(); - +void handleMediaTasks() { while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); auto mediaInformation = backend::getMediaInformation(); @@ -98,4 +97,23 @@ int main() { Discord_UpdatePresence(&activity); } +} +class MyApp : public wxApp { +public: + virtual bool OnInit() override { + wxFrame* frame = new wxFrame(nullptr, wxID_ANY, "Hello wxWidgets", wxDefaultPosition, wxSize(400, 300)); + wxStaticText* text = new wxStaticText(frame, wxID_ANY, "Hello World", wxPoint(150, 130)); + frame->Show(true); + return true; + } +}; + +wxIMPLEMENT_APP_NO_MAIN(MyApp); + +int main(int argc, char** argv) { + std::thread rpcThread(handleRPCTasks); + rpcThread.detach(); + std::thread mediaThread(handleMediaTasks); + mediaThread.detach(); + return wxEntry(argc, argv); } \ No newline at end of file diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 2b0a195..91ff1a1 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -11,3 +11,8 @@ SET(MBEDTLS_INCLUDE_DIRS ../mbedtls/include) file(REMOVE curl/CMake/FindMbedTLS.cmake) #replace curls FindMbedTLS that expects mbedtls to be prebuilt with a dummy set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dummy ${CMAKE_MODULE_PATH}) add_subdirectory("curl") +set(wxBUILD_SHARED OFF) +set(wxBUILD_MONOLITHIC ON) +set(wxUSE_GUI ON) +set(wxUSE_WEBVIEW OFF) +add_subdirectory("wxWidgets") \ No newline at end of file diff --git a/vendor/wxWidgets b/vendor/wxWidgets new file mode 160000 index 0000000..5ff2532 --- /dev/null +++ b/vendor/wxWidgets @@ -0,0 +1 @@ +Subproject commit 5ff25322553c1870cf20a2e1ba6f20ed50d9fe9a