From b63d00ebff1de0c97d07c17179c268faa2983c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 15 Nov 2024 03:30:21 +0800 Subject: [PATCH] fix --- cpp/winsharedutils/CMakeLists.txt | 2 +- cpp/winsharedutils/webview2_extra.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cpp/winsharedutils/CMakeLists.txt b/cpp/winsharedutils/CMakeLists.txt index 649e9f41..c08266d7 100644 --- a/cpp/winsharedutils/CMakeLists.txt +++ b/cpp/winsharedutils/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(winsharedutils MODULE mp3enc.cpp webview2_extra.cpp AreoAcrylic.cpp applicationloopbackaudio/runer.cpp applicationloopbackaudio/LoopbackCapture.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo}) target_precompile_headers(winsharedutils REUSE_FROM pch) -target_link_libraries(winsharedutils tinymp3 Shcore rapidfuzz wil webview2 Mfplat mfuuid Mmdevapi ${YY_Thunks_for_WinXP}) +target_link_libraries(winsharedutils tinymp3 rapidfuzz wil webview2 Mfplat mfuuid Mmdevapi ${YY_Thunks_for_WinXP}) target_link_options(winsharedutils PRIVATE "/DELAYLOAD:Mmdevapi.dll") target_link_options(winsharedutils PRIVATE "/DELAYLOAD:Mfplat.dll") if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) diff --git a/cpp/winsharedutils/webview2_extra.cpp b/cpp/winsharedutils/webview2_extra.cpp index 65cbe56a..960c8e6b 100644 --- a/cpp/winsharedutils/webview2_extra.cpp +++ b/cpp/winsharedutils/webview2_extra.cpp @@ -11,8 +11,10 @@ using namespace Microsoft::WRL; if (FAILED((x))) \ return x; +#endif DECLARE_API void set_transparent_background(void *m_host) { +#ifndef WINXP COREWEBVIEW2_COLOR color; ZeroMemory(&color, sizeof(color)); wil::com_ptr m_controller(reinterpret_cast(m_host)); @@ -22,10 +24,12 @@ DECLARE_API void set_transparent_background(void *m_host) { coreWebView2->put_DefaultBackgroundColor(color); } +#endif } DECLARE_API void put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_COLOR_SCHEME scheme) { +#ifndef WINXP wil::com_ptr m_controller(reinterpret_cast(m_host)); wil::com_ptr coreWebView2; [&]() @@ -40,9 +44,11 @@ DECLARE_API void put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_C } return S_OK; }(); +#endif } DECLARE_API void *add_ZoomFactorChanged(void *m_host, void (*signal)(double)) { +#ifndef WINXP EventRegistrationToken *m_zoomFactorChangedToken = new EventRegistrationToken; // Register a handler for the ZoomFactorChanged event. // This handler just announces the new level of zoom on the window's title bar. @@ -61,26 +67,38 @@ DECLARE_API void *add_ZoomFactorChanged(void *m_host, void (*signal)(double)) .Get(), m_zoomFactorChangedToken); return m_zoomFactorChangedToken; +#else + return NULL; +#endif } DECLARE_API void remove_ZoomFactorChanged(void *m_host, void *m_zoomFactorChangedToken) { +#ifndef WINXP auto token = reinterpret_cast(m_zoomFactorChangedToken); reinterpret_cast(m_host)->remove_ZoomFactorChanged(*token); delete token; +#endif } DECLARE_API double get_ZoomFactor(void *m_host) { +#ifndef WINXP double zoomFactor; reinterpret_cast(m_host)->get_ZoomFactor(&zoomFactor); return zoomFactor; +#else + return 1; +#endif } DECLARE_API void put_ZoomFactor(void *m_host, double zoomFactor) { +#ifndef WINXP reinterpret_cast(m_host)->put_ZoomFactor(zoomFactor); +#endif } // https://github.com/MicrosoftEdge/WebView2Feedback/blob/main/specs/WebMessageObjects.md DECLARE_API void remove_WebMessageReceived(void *m_host, void *m_webMessageReceivedToken) { +#ifndef WINXP auto token = reinterpret_cast(m_webMessageReceivedToken); wil::com_ptr m_controller(reinterpret_cast(m_host)); wil::com_ptr m_webView; @@ -91,10 +109,12 @@ DECLARE_API void remove_WebMessageReceived(void *m_host, void *m_webMessageRecei return S_OK; }(); delete token; +#endif } DECLARE_API void *add_WebMessageReceived(void *m_host, void (*callback)(const wchar_t *)) { +#ifndef WINXP wil::com_ptr m_controller(reinterpret_cast(m_host)); wil::com_ptr coreWebView4 = m_controller.try_query(); @@ -159,6 +179,7 @@ DECLARE_API void *add_WebMessageReceived(void *m_host, void (*callback)(const wc return S_OK; }(); return m_webMessageReceivedToken; +#else + return NULL; +#endif } - -#endif \ No newline at end of file