diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a4da82..1f8ec4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required (VERSION 3.8) include("cmake/create_resources.cmake") +file(GLOB_RECURSE SOURCES "src/*.cpp") + #enable objective c support on mac os, needed for wxwidgets and compile for both intel macs and apple sillicon macs if(APPLE) + list(APPEND SOURCES "src/backends/darwin.mm") set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) project ("PlayerLink" LANGUAGES C CXX OBJCXX) else() @@ -10,7 +13,7 @@ else() endif() create_resources("rsrc" "src/rsrc.hpp") -file(GLOB_RECURSE SOURCES "src/*.cpp") + add_executable (PlayerLink ${SOURCES}) set_property(TARGET PlayerLink PROPERTY CXX_STANDARD 20) add_subdirectory("vendor") @@ -20,6 +23,15 @@ set(LIBRARIES discord-rpc libcurl_static mbedcrypto mbedx509 mbedtls wxmono) if(WIN32) list(APPEND LIBRARIES WindowsApp) target_link_options(PlayerLink PRIVATE "/SUBSYSTEM:WINDOWS" "/ENTRY:mainCRTStartup") +elseif(APPLE) + set(MEDIAREMOTE_FRAMEWORK_PATH "/System/Library/PrivateFrameworks") + find_library(MEDIAREMOTE_LIBRARY MediaRemote PATHS ${MEDIAREMOTE_FRAMEWORK_PATH}) + if (MEDIAREMOTE_LIBRARY) + message(STATUS "Found MediaRemote: ${MEDIAREMOTE_LIBRARY}") + list(APPEND LIBRARIES ${MEDIAREMOTE_LIBRARY}) + else() + message(FATAL_ERROR "MediaRemote framework not found.") + endif() endif() #search directories for the autogenerated wxwidgets setup.h file for all plattforms diff --git a/src/MediaRemote.hpp b/src/MediaRemote.hpp new file mode 100644 index 0000000..3d5486a --- /dev/null +++ b/src/MediaRemote.hpp @@ -0,0 +1,25 @@ +// +// MediaRemote.h +// MusicRPC +// +// Created by Alexandra Aurora Göttlicher +// + +#import + +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoDidChangeNotification; + +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoTitle; +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoAlbum; +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoArtist; +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoDuration; +FOUNDATION_EXPORT CFStringRef _Nullable kMRMediaRemoteNowPlayingInfoElapsedTime; + +typedef void (^ MRMediaRemoteGetNowPlayingInfoCompletion)(CFDictionaryRef _Nullable information); +typedef void (^ MRMediaRemoteGetNowPlayingApplicationPIDCompletion)(int PID); +typedef void (^ MRMediaRemoteGetNowPlayingApplicationIsPlayingCompletion)(Boolean isPlaying); + +FOUNDATION_EXPORT void MRMediaRemoteRegisterForNowPlayingNotifications(dispatch_queue_t _Nullable queue); +FOUNDATION_EXPORT void MRMediaRemoteGetNowPlayingApplicationPID(dispatch_queue_t _Nullable queue, MRMediaRemoteGetNowPlayingApplicationPIDCompletion _Nullable completion); +FOUNDATION_EXPORT void MRMediaRemoteGetNowPlayingInfo(dispatch_queue_t _Nullable queue, MRMediaRemoteGetNowPlayingInfoCompletion _Nullable completion); +FOUNDATION_EXPORT void MRMediaRemoteGetNowPlayingApplicationIsPlaying(dispatch_queue_t _Nullable queue, MRMediaRemoteGetNowPlayingApplicationIsPlayingCompletion _Nullable completion); diff --git a/src/backends/darwin.cpp b/src/backends/darwin.cpp deleted file mode 100644 index 1098a03..0000000 --- a/src/backends/darwin.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef __APPLE__ -#include "../backend.hpp" -std::shared_ptr backend::getMediaInformation() { return nullptr; } -bool backend::toggleAutostart(bool enabled) { return false, } -#endif \ No newline at end of file diff --git a/src/backends/darwin.mm b/src/backends/darwin.mm new file mode 100644 index 0000000..93a6802 --- /dev/null +++ b/src/backends/darwin.mm @@ -0,0 +1,16 @@ +#ifdef __APPLE__ +#include +#include "../MediaRemote.hpp" +#include "../backend.hpp" + +std::shared_ptr backend::getMediaInformation() { + MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(CFDictionaryRef result) { + if (result) { + NSDictionary *playingInfo = (__bridge NSDictionary *)(result); + NSLog(@"Now Playing Info: %@", playingInfo); + } + }); + return nullptr; +} +bool backend::toggleAutostart(bool enabled) { return false; } +#endif \ No newline at end of file diff --git a/src/backends/linux.cpp b/src/backends/linux.cpp index 2bad487..9333c19 100644 --- a/src/backends/linux.cpp +++ b/src/backends/linux.cpp @@ -1,5 +1,5 @@ #if !defined(_WIN32) && !defined(__APPLE__) #include "../backend.hpp" std::shared_ptr backend::getMediaInformation() { return nullptr; } -bool backend::toggleAutostart(bool enabled) { return false, } +bool backend::toggleAutostart(bool enabled) { return false; } #endif \ No newline at end of file diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 3ba85c8..5ebbc38 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -4,6 +4,8 @@ SET(ENABLE_TESTING OFF FORCE) add_subdirectory("mbedtls") SET(CURL_USE_MBEDTLS ON) SET(CURL_USE_LIBPSL OFF) +SET(CURL_USE_LIBSSH2 OFF) +SET(USE_NGHTTP2 OFF) SET(USE_LIBIDN2 OFF) SET(BUILD_STATIC_LIBS ON) SET(BUILD_SHARED_LIBS OFF)