Skip to content

Commit

Permalink
Release v0.1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stuerp committed Jul 10, 2024
1 parent 0b617de commit cafe5fb
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 27 deletions.
49 changes: 30 additions & 19 deletions HostObjectImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** $VER: HostObjectImpl.cpp (2024.07.09) P. Stuer **/
/** $VER: HostObjectImpl.cpp (2024.07.10) P. Stuer **/

#include "pch.h"

Expand All @@ -18,7 +18,6 @@
#include <SDK/playlist.h>
#include <SDK/ui.h>
#include <SDK/contextmenu.h>
#include <SDK/album_art.h>

#include <pfc/string-conv-lite.h>

Expand Down Expand Up @@ -468,7 +467,7 @@ HRESULT HostObject::GetTrackIndex(t_size & playlistIndex, t_size & itemIndex) no
/// </summary>
STDMETHODIMP HostObject::GetArtwork(BSTR type, BSTR * image)
{
*image = nullptr;
*image = ::SysAllocString(L""); // Return an empty string by default and in case of an error.

if (type == nullptr)
return E_INVALIDARG;
Expand Down Expand Up @@ -500,7 +499,7 @@ STDMETHODIMP HostObject::GetArtwork(BSTR type, BSTR * image)
AlbumArtId = album_art_ids::artist;
}
else
return E_INVALIDARG;
return S_OK;

album_art_data::ptr aad;

Expand All @@ -509,68 +508,80 @@ STDMETHODIMP HostObject::GetArtwork(BSTR type, BSTR * image)
metadb_handle_ptr Handle;

if (!_PlaybackControl->get_now_playing(Handle))
return E_FAIL;
return S_OK;

metadb_handle_list Handles;

Handles.add_item(Handle);

pfc::list_t<GUID> GUIDs;
pfc::list_t<GUID> AlbumArtIds;

GUIDs.add_item(album_art_ids::cover_front);
AlbumArtIds.add_item(AlbumArtId);

static_api_ptr_t<album_art_manager_v3> Manager;

abort_callback_dummy AbortCallback;

album_art_extractor_instance_v2::ptr Extractor = Manager->open_v3(Handles, GUIDs, nullptr, AbortCallback);
album_art_extractor_instance_v2::ptr Extractor = Manager->open_v3(Handles, AlbumArtIds, nullptr, AbortCallback);

Extractor->query(AlbumArtId, aad, AbortCallback);
if (!Extractor->query(AlbumArtId, aad, AbortCallback))
return S_OK;
}
catch (...)
{
return E_FAIL;
return S_OK;
}

if (!aad.is_valid())
return E_FAIL;
return S_OK;

const WCHAR * MIMEType = nullptr;

const BYTE * p = (const BYTE *) aad->data();

if (p[0] == 0x89 && p[1] == 0x50 && p[2] == 0x4E && p[3] == 0x47)
MIMEType = L"image/png";
else
if (p[0] == 0xFF && p[1] == 0xD8)
if ((aad->size() > 2) && p[0] == 0xFF && p[1] == 0xD8)
MIMEType = L"image/jpeg";
else
if (p[0] == 0x47 && p[1] == 0x49 && p[2] == 0x46)
if ((aad->size() > 15) && (p[0] == 'R' && p[1] == 'I' && p[2] == 'F' && p[3] == 'F') && (::memcmp(p + 8, "WEBPVP8", 7) == 0))
MIMEType = L"image/webp";
else
if ((aad->size() > 4) && p[0] == 0x89 && p[1] == 0x50 && p[2] == 0x4E && p[3] == 0x47)
MIMEType = L"image/png";
else
if ((aad->size() > 3) && p[0] == 0x47 && p[1] == 0x49 && p[2] == 0x46)
MIMEType = L"image/gif";

if (MIMEType == nullptr)
return E_FAIL;
return S_OK;

// Convert the image data to base64.
const DWORD Flags = CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF;

DWORD Size = 0;

if (!::CryptBinaryToStringW(p, (DWORD) aad->size(), Flags, nullptr, &Size))
return E_FAIL;
return S_OK;

Size += 16 + (DWORD) ::wcslen(MIMEType);

WCHAR * Base64 = new WCHAR[Size];

if (Base64 == nullptr)
return S_OK;

::swprintf_s(Base64, Size, L"data:%s;base64,", MIMEType);

// Create the result.
if (::CryptBinaryToStringW(p, (DWORD) aad->size(), Flags, Base64 + ::wcslen(Base64), &Size))
{
::SysFreeString(*image); // Free the empty string.

*image = ::SysAllocString(Base64);
}

delete[] Base64;

return (*image != nullptr) ? S_OK : E_FAIL;
return S_OK;
}

#pragma region IDispatch
Expand Down
36 changes: 35 additions & 1 deletion HostObjectImpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** $VER: HostObjectImpl.h (2024.07.07) P. Stuer **/
/** $VER: HostObjectImpl.h (2024.07.10) P. Stuer **/

#pragma once

Expand All @@ -21,6 +21,7 @@
#include "HostObject_h.h"

#include <SDK/playback_control.h>
#include <SDK/album_art.h>

class HostObject : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IHostObject, IDispatch>
{
Expand Down Expand Up @@ -104,4 +105,37 @@ class HostObject : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeCl
RunCallbackAsync _RunCallbackAsync;

service_ptr_t<playback_control> _PlaybackControl;

/// <summary>
/// Represents an Album Art Manager configuration to allow overriding the default configuration in this component (see album_art_manager_v3::open_v3)
/// </summary>
class album_art_manager_config_t : public album_art_manager_config
{
public:
album_art_manager_config_t() { };

album_art_manager_config_t(const album_art_manager_config_t &) = delete;
album_art_manager_config_t(const album_art_manager_config_t &&) = delete;
album_art_manager_config_t & operator=(const album_art_manager_config_t &) = delete;
album_art_manager_config_t & operator=(album_art_manager_config_t &&) = delete;

virtual ~album_art_manager_config_t() { };

virtual bool get_external_pattern(pfc::string_base & out, const GUID & albumArtType) override
{
return false;
}

virtual bool use_embedded_pictures() override
{
return true;
}

virtual bool use_fallbacks() override
{
return true;
}
};

service_ptr_t<album_art_manager_config_t> _AlbumArtManagerConfig = new service_impl_t<album_art_manager_config_t>;
};
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ To create the component first build the x86 configuration and next the x64 confi

## Change Log

v0.1.6.1, 2024-07-09
v0.1.6.2, 2024-07-10

* New:
* Methods
* GetArtwork(): Gets the embedded artwork (front / back / disc / icon / artist) from the current playing item (alpha1).
* GetArtwork(): Gets the embedded artwork (front / back / disc / icon / artist) from the current playing item (alpha1).
* Fixed support for other artwork type (alpha2, regression).
* Added support for WebP images (alpha2).
* Always returns an empty data URI in case of an error or if the specified artwork type is not availabe.

v0.1.6.0, 2024-07-09

Expand Down
8 changes: 4 additions & 4 deletions Resources.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** $VER: Resources.h (2024.07.09) P. Stuer **/
/** $VER: Resources.h (2024.07.10) P. Stuer **/

#pragma once

Expand All @@ -9,17 +9,17 @@
#define NUM_FILE_MAJOR 0
#define NUM_FILE_MINOR 1
#define NUM_FILE_PATCH 6
#define NUM_FILE_PRERELEASE 1
#define NUM_FILE_PRERELEASE 2

#define NUM_PRODUCT_MAJOR 0
#define NUM_PRODUCT_MINOR 1
#define NUM_PRODUCT_PATCH 6
#define NUM_PRODUCT_PRERELEASE 1
#define NUM_PRODUCT_PRERELEASE 2

/** Component specific **/

#define STR_COMPONENT_NAME "WebView"
#define STR_COMPONENT_VERSION TOSTRING(NUM_FILE_MAJOR) "." TOSTRING(NUM_FILE_MINOR) "." TOSTRING(NUM_FILE_PATCH) "." TOSTRING(NUM_FILE_PRERELEASE) "-alpha1"
#define STR_COMPONENT_VERSION TOSTRING(NUM_FILE_MAJOR) "." TOSTRING(NUM_FILE_MINOR) "." TOSTRING(NUM_FILE_PATCH) "." TOSTRING(NUM_FILE_PRERELEASE) "-alpha2"
#define STR_COMPONENT_BASENAME "foo_uie_webview"
#define STR_COMPONENT_FILENAME STR_COMPONENT_BASENAME ".dll"
#define STR_COMPONENT_COMPANY_NAME ""
Expand Down
2 changes: 1 addition & 1 deletion SharedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <WebView2.h>

/// <summary>
/// Implements a shared buffer.
/// Implements a buffer shared between the component and the WebView2 control.
/// </summary>
class SharedBuffer
{
Expand Down

0 comments on commit cafe5fb

Please sign in to comment.