mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Media (Windows): build winrt stuff statically
This commit is contained in:
+36
-7
@@ -115,9 +115,14 @@ set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=retu
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")
|
||||
|
||||
if(WIN32)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
elseif(ENABLE_DIRECTX_HEADERS)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
endif()
|
||||
|
||||
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")
|
||||
endif()
|
||||
|
||||
@@ -695,7 +700,7 @@ elseif(WIN32)
|
||||
src/detection/locale/locale_windows.c
|
||||
src/detection/localip/localip_windows.c
|
||||
src/detection/gamepad/gamepad_windows.c
|
||||
src/detection/media/media_windows.c
|
||||
src/detection/media/media_windows.cpp
|
||||
src/detection/memory/memory_windows.c
|
||||
src/detection/physicalmemory/physicalmemory_linux.c
|
||||
src/detection/monitor/monitor_windows.c
|
||||
@@ -1035,6 +1040,7 @@ elseif(WIN32)
|
||||
PRIVATE "setupapi"
|
||||
PRIVATE "hid"
|
||||
PRIVATE "wtsapi32"
|
||||
PRIVATE "RuntimeObject"
|
||||
)
|
||||
elseif(BSD)
|
||||
target_link_libraries(libfastfetch
|
||||
@@ -1091,11 +1097,34 @@ target_link_libraries(flashfetch
|
||||
PRIVATE libfastfetch
|
||||
)
|
||||
|
||||
# Prevent fastfetch from linking to libstdc++
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
|
||||
set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
|
||||
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
|
||||
if(NOT WIN32)
|
||||
# Prevent fastfetch from linking to libstdc++
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
|
||||
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
|
||||
set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
|
||||
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
|
||||
else()
|
||||
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(libfastfetch
|
||||
PRIVATE "libc++.a"
|
||||
)
|
||||
endif()
|
||||
|
||||
check_cxx_symbol_exists(__GLIBCXX__ ${header} GLIBCXX)
|
||||
if(GLIBCXX)
|
||||
target_link_libraries(libfastfetch
|
||||
PRIVATE "libstdc++.a"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(yyjson_FOUND)
|
||||
target_compile_definitions(fastfetch PRIVATE FF_USE_SYSTEM_YYJSON)
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/library.h"
|
||||
#include "util/windows/unicode.h"
|
||||
#include "media.h"
|
||||
|
||||
#define FF_MEDIA_WIN_RESULT_BUFLEN 256
|
||||
|
||||
typedef struct FFMediaWinResult
|
||||
{
|
||||
wchar_t playerId[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
wchar_t song[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
wchar_t artist[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
wchar_t album[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
char status[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
char error[FF_MEDIA_WIN_RESULT_BUFLEN];
|
||||
} FFMediaWinResult;
|
||||
|
||||
bool ffMediaWinDetectMedia(FFMediaWinResult* result);
|
||||
|
||||
static const char* getMedia(FFMediaResult* media)
|
||||
{
|
||||
FF_LIBRARY_LOAD(libffdll, NULL, "dlopen fastfetch-dll" FF_LIBRARY_EXTENSION " failed", "fastfetch-dll" FF_LIBRARY_EXTENSION, 0)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libffdll, ffMediaWinDetectMedia)
|
||||
libffdll = NULL; // Don't close libffdll or it may crash
|
||||
|
||||
FFMediaWinResult result = {};
|
||||
|
||||
if (!ffffMediaWinDetectMedia(&result))
|
||||
{
|
||||
ffStrbufAppendS(&media->error, result.error);
|
||||
ffStrbufAppendS(&media->error, " (DLL error)");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ffStrbufSetWS(&media->playerId, result.playerId);
|
||||
ffStrbufSet(&media->player, &media->playerId);
|
||||
if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe"))
|
||||
ffStrbufSubstrBefore(&media->player, media->player.length - 4);
|
||||
else
|
||||
ffStrbufSubstrAfterFirstC(&media->player, '!'); // UWP ID
|
||||
ffStrbufSetWS(&media->song, result.song);
|
||||
ffStrbufSetWS(&media->artist, result.artist);
|
||||
ffStrbufSetWS(&media->album, result.album);
|
||||
ffStrbufSetS(&media->status, result.status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ffDetectMediaImpl(FFMediaResult* media)
|
||||
{
|
||||
const char* error = getMedia(media);
|
||||
ffStrbufAppendS(&media->error, error);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "media.h"
|
||||
#include "util/windows/unicode.h"
|
||||
}
|
||||
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/windows.Media.Control.h>
|
||||
#include <winrt/Windows.Media.Playback.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static const char* getMedia(FFMediaResult* media)
|
||||
{
|
||||
using namespace winrt::Windows::Media::Control;
|
||||
auto manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
|
||||
if (!manager)
|
||||
return "GlobalSystemMediaTransportControlsSessionManager::RequestAsync() failed";
|
||||
|
||||
auto session = manager.GetCurrentSession();
|
||||
if (!session)
|
||||
return "GetCurrentSession() failed";
|
||||
|
||||
auto mediaProps = session
|
||||
.TryGetMediaPropertiesAsync()
|
||||
.get();
|
||||
if (!mediaProps)
|
||||
return "TryGetMediaPropertiesAsync() failed";
|
||||
|
||||
if (auto playbackInfo = session.GetPlaybackInfo())
|
||||
{
|
||||
switch (playbackInfo.PlaybackStatus())
|
||||
{
|
||||
#define FF_MEDIA_SET_STATUS(status_code) \
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::status_code: ffStrbufSetStatic(&media->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
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufSetNWS(&media->playerId, session.SourceAppUserModelId().size(), session.SourceAppUserModelId().data());
|
||||
ffStrbufSet(&media->player, &media->playerId);
|
||||
if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe"))
|
||||
ffStrbufSubstrBefore(&media->player, media->player.length - 4);
|
||||
else
|
||||
ffStrbufSubstrAfterFirstC(&media->player, '!'); // UWP ID
|
||||
|
||||
ffStrbufSetNWS(&media->song, mediaProps.Title().size(), mediaProps.Title().data());
|
||||
ffStrbufSetNWS(&media->artist, mediaProps.Artist().size(), mediaProps.Artist().data());
|
||||
ffStrbufSetNWS(&media->album, mediaProps.AlbumTitle().size(), mediaProps.AlbumTitle().data());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ffDetectMediaImpl(FFMediaResult* media)
|
||||
{
|
||||
const char* error = getMedia(media);
|
||||
ffStrbufAppendS(&media->error, error);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user