diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7614a2e4..3278fbe83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -522,7 +522,7 @@ jobs: with: msystem: CLANG32 update: true - install: git p7zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-vulkan-headers mingw-w64-clang-i686-opencl-icd mingw-w64-clang-i686-cppwinrt + install: git p7zip mingw-w64-clang-i686-cmake mingw-w64-clang-i686-clang mingw-w64-clang-i686-vulkan-loader mingw-w64-clang-i686-vulkan-headers mingw-w64-clang-i686-opencl-icd - name: print msys version run: uname -a diff --git a/CMakeLists.txt b/CMakeLists.txt index b530f8223..575b6b108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointe if(WIN32 OR ENABLE_DIRECTX_HEADERS) enable_language(CXX) set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -fno-exceptions -fno-rtti") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}") endif() if(WIN32) @@ -1067,37 +1067,22 @@ target_link_libraries(libfastfetch PRIVATE ${CMAKE_DL_LIBS} ) +target_compile_options(libfastfetch PRIVATE + $<$:-fno-exceptions -fno-rtti>) + if(WIN32) set(CMAKE_CXX_STANDARD 20) include(CheckIncludeFileCXX) - CHECK_INCLUDE_FILE_CXX("winrt/Windows.Media.Control.h" HAVE_WINRT) + CHECK_INCLUDE_FILE_CXX("winrt/Windows.Foundation.h" HAVE_WINRT) if(HAVE_WINRT) add_library(ffwinrt SHARED src/detection/media/media_windows.dll.cpp) target_link_libraries(ffwinrt PRIVATE "RuntimeObject") - - include(CheckCXXSymbolExists) - if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) - set(header version) - else() - set(header ciso646) - endif() - - check_cxx_symbol_exists(_LIBCPP_VERSION ${header} LIBCPP) - if(LIBCPP) - target_link_libraries(ffwinrt - PRIVATE "libc++.a" - ) - endif() - - check_cxx_symbol_exists(__GLIBCXX__ ${header} GLIBCXX) - if(GLIBCXX) - target_link_libraries(ffwinrt - PRIVATE "libstdc++.a" - ) - endif() - else() - set(CMAKE_CXX_STANDARD 17) + target_compile_definitions(ffwinrt PRIVATE WIN32_LEAN_AND_MEAN=1 WINRT_LEAN_AND_MEAN=1) + target_link_options(ffwinrt + PRIVATE "-static" # stdc++, winpthread, gcc_s, etc. + ) endif() + set(CMAKE_CXX_STANDARD 17) endif() ###################### diff --git a/src/detection/media/media_windows.dll.cpp b/src/detection/media/media_windows.dll.cpp index 53877d29f..71c3226c4 100644 --- a/src/detection/media/media_windows.dll.cpp +++ b/src/detection/media/media_windows.dll.cpp @@ -8,46 +8,53 @@ extern "C" const char* ffWinrtDetectMedia(FFWinrtMediaResult* result) { - // C++/WinRT requires Windows 8.1 or later and C++ runtime (std::string and other stuff) + // C++/WinRT requires Windows 8.1+ and C++ runtime (std::string, exceptions and other stuff) // Make it a separate dll in order not to break Windows 7 support using namespace winrt::Windows::Media::Control; - auto manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get(); - if (!manager) - return "winrt: GlobalSystemMediaTransportControlsSessionManager::RequestAsync() failed"; - - auto session = manager.GetCurrentSession(); - if (!session) - return "winrt: GetCurrentSession() failed"; - - auto mediaProps = session - .TryGetMediaPropertiesAsync() - .get(); - if (!mediaProps) - return "winrt: TryGetMediaPropertiesAsync() failed"; - - if (auto playbackInfo = session.GetPlaybackInfo()) + try { - switch (playbackInfo.PlaybackStatus()) + auto manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get(); + if (!manager) + return "winrt: GlobalSystemMediaTransportControlsSessionManager::RequestAsync() failed"; + + auto session = manager.GetCurrentSession(); + if (!session) + return "winrt: GetCurrentSession() failed"; + + auto mediaProps = session + .TryGetMediaPropertiesAsync() + .get(); + if (!mediaProps) + return "winrt: TryGetMediaPropertiesAsync() failed"; + + if (auto playbackInfo = session.GetPlaybackInfo()) { -#define FF_MEDIA_SET_STATUS(status_code) \ -case GlobalSystemMediaTransportControlsSessionPlaybackStatus::status_code: result->status = #status_code; break - FF_MEDIA_SET_STATUS(Closed); - FF_MEDIA_SET_STATUS(Opened); - FF_MEDIA_SET_STATUS(Changing); - FF_MEDIA_SET_STATUS(Stopped); - FF_MEDIA_SET_STATUS(Playing); - FF_MEDIA_SET_STATUS(Paused); -#undef FF_MEDIA_SET_STATUS + switch (playbackInfo.PlaybackStatus()) + { + #define FF_MEDIA_SET_STATUS(status_code) \ + case GlobalSystemMediaTransportControlsSessionPlaybackStatus::status_code: result->status = #status_code; break + FF_MEDIA_SET_STATUS(Closed); + FF_MEDIA_SET_STATUS(Opened); + FF_MEDIA_SET_STATUS(Changing); + FF_MEDIA_SET_STATUS(Stopped); + FF_MEDIA_SET_STATUS(Playing); + FF_MEDIA_SET_STATUS(Paused); + #undef FF_MEDIA_SET_STATUS + } } + + ::wcsncpy(result->playerId, session.SourceAppUserModelId().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + ::wcsncpy(result->song, mediaProps.Title().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + ::wcsncpy(result->artist, mediaProps.Artist().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + ::wcsncpy(result->album, mediaProps.AlbumTitle().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + + return NULL; + } + catch (...) + { + return "A C++ exception is thrown"; } - - ::wcsncpy(result->playerId, session.SourceAppUserModelId().data(), FF_MEDIA_WIN_RESULT_BUFLEN); - ::wcsncpy(result->song, mediaProps.Title().data(), FF_MEDIA_WIN_RESULT_BUFLEN); - ::wcsncpy(result->artist, mediaProps.Artist().data(), FF_MEDIA_WIN_RESULT_BUFLEN); - ::wcsncpy(result->album, mediaProps.AlbumTitle().data(), FF_MEDIA_WIN_RESULT_BUFLEN); - - return NULL; } } // extern "C"