- seek support

- about button implementation
- cleaned up cmake config
This commit is contained in:
EinTim23 2024-11-04 17:00:29 +01:00
parent 1756c9e368
commit 8cf3fe8cea
2 changed files with 29 additions and 8 deletions

View File

@ -1,19 +1,28 @@
cmake_minimum_required (VERSION 3.8) cmake_minimum_required (VERSION 3.8)
include("cmake/create_resources.cmake") include("cmake/create_resources.cmake")
#enable objective c support on mac os, needed for wxwidgets and compile for both intel macs and apple sillicon macs
if(APPLE) if(APPLE)
project ("globalRPC" LANGUAGES C CXX OBJCXX) set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
project ("PlayerLink" LANGUAGES C CXX OBJCXX)
else() else()
project ("globalRPC" LANGUAGES C CXX) project ("PlayerLink" LANGUAGES C CXX)
endif() endif()
create_resources("rsrc" "src/rsrc.hpp") create_resources("rsrc" "src/rsrc.hpp")
file(GLOB_RECURSE SOURCES "src/*.cpp") file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable (rpc ${SOURCES}) add_executable (PlayerLink ${SOURCES})
set_property(TARGET rpc PROPERTY CXX_STANDARD 20) set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 20)
add_subdirectory("vendor") add_subdirectory("vendor")
set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono) set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono)
#use windows subsystem to disable console window and link winrt
if(WIN32) if(WIN32)
list(APPEND LIBRARIES WindowsApp) list(APPEND LIBRARIES WindowsApp)
target_link_options(PlayerLink PRIVATE "/SUBSYSTEM:WINDOWS" "/ENTRY:mainCRTStartup")
endif() endif()
#search directories for the autogenerated wxwidgets setup.h file for all plattforms
file(GLOB wx_setup_dir file(GLOB wx_setup_dir
"${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/mswu" "${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/mswu"
"${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/gtk3u" "${CMAKE_BINARY_DIR}/vendor/wxWidgets/lib/*/gtk3u"
@ -21,8 +30,8 @@ file(GLOB wx_setup_dir
) )
if(wx_setup_dir) if(wx_setup_dir)
message(STATUS "wxWidgets setup.h directory found: ${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}) target_include_directories(PlayerLink PRIVATE vendor vendor/wxWidgets/include ${wx_setup_dir})
else() else()
message(FATAL_ERROR "wx/setup.h not found. Please check your wxWidgets build configuration.") message(FATAL_ERROR "wx/setup.h not found. Please check your wxWidgets build configuration.")
endif() endif()
target_link_libraries(rpc PUBLIC ${LIBRARIES}) target_link_libraries(PlayerLink PUBLIC ${LIBRARIES})

View File

@ -37,6 +37,7 @@ void handleRPCTasks() {
} }
void handleMediaTasks() { void handleMediaTasks() {
int64_t lastMs = 0;
while (true) { while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
auto mediaInformation = backend::getMediaInformation(); auto mediaInformation = backend::getMediaInformation();
@ -47,6 +48,7 @@ void handleMediaTasks() {
} }
if (mediaInformation->paused) { if (mediaInformation->paused) {
lastMs = 0;
lastPlayingSong = ""; lastPlayingSong = "";
currentSongTitle = ""; currentSongTitle = "";
Discord_ClearPresence(); Discord_ClearPresence();
@ -55,8 +57,13 @@ void handleMediaTasks() {
std::string currentlyPlayingSong = mediaInformation->songTitle + mediaInformation->songArtist + std::string currentlyPlayingSong = mediaInformation->songTitle + mediaInformation->songArtist +
mediaInformation->songAlbum + std::to_string(mediaInformation->songDuration); mediaInformation->songAlbum + std::to_string(mediaInformation->songDuration);
int64_t currentMs = mediaInformation->songElapsedTime;
if (currentlyPlayingSong == lastPlayingSong) bool shouldContinue =
currentlyPlayingSong == lastPlayingSong && (lastMs <= currentMs) && (lastMs + 3000 >= currentMs);
lastMs = currentMs;
if (shouldContinue)
continue; continue;
lastPlayingSong = currentlyPlayingSong; lastPlayingSong = currentlyPlayingSong;
@ -122,10 +129,14 @@ public:
void OnMenuExit(wxCommandEvent& evt) { settingsFrame->Close(true); } void OnMenuExit(wxCommandEvent& evt) { settingsFrame->Close(true); }
void OnMenuAbout(wxCommandEvent& evt) {
wxMessageBox(_("Made with <3 by EinTim"), _("PlayerLink"), wxOK | wxICON_INFORMATION);
}
protected: protected:
virtual wxMenu* CreatePopupMenu() override { virtual wxMenu* CreatePopupMenu() override {
wxMenu* menu = new wxMenu; wxMenu* menu = new wxMenu;
menu->Append(10004, _(currentSongTitle == "" ? "Not Playing" : currentSongTitle)); // TODO: make this dynamic menu->Append(10004, _(currentSongTitle == "" ? "Not Playing" : currentSongTitle));
menu->Enable(10004, false); menu->Enable(10004, false);
menu->AppendSeparator(); menu->AppendSeparator();
menu->Append(10001, _("Settings")); menu->Append(10001, _("Settings"));
@ -134,6 +145,7 @@ protected:
menu->Append(10002, _("Quit PlayerLink...")); menu->Append(10002, _("Quit PlayerLink..."));
Bind(wxEVT_MENU, &PlayerLinkIcon::OnMenuOpen, this, 10001); Bind(wxEVT_MENU, &PlayerLinkIcon::OnMenuOpen, this, 10001);
Bind(wxEVT_MENU, &PlayerLinkIcon::OnMenuExit, this, 10002); Bind(wxEVT_MENU, &PlayerLinkIcon::OnMenuExit, this, 10002);
Bind(wxEVT_MENU, &PlayerLinkIcon::OnMenuAbout, this, 10003);
return menu; return menu;
} }