From 78d10f5717e5766db064086697849bfe1d0b8ebd Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:11:36 +0800 Subject: [PATCH 1/3] Windows GUI: Use Edge WebView2 for HTML/Graph view Use Edge WebView2 for HTML and Graph view when available else fallback to IE. --- Source/GUI/VCL/GUI_Main.cpp | 13 ++++++++++--- Source/GUI/VCL/GUI_Main.dfm | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/GUI/VCL/GUI_Main.cpp b/Source/GUI/VCL/GUI_Main.cpp index fd86a449c..811bb28ac 100644 --- a/Source/GUI/VCL/GUI_Main.cpp +++ b/Source/GUI/VCL/GUI_Main.cpp @@ -255,12 +255,19 @@ __fastcall TMainF::TMainF(TComponent* Owner) if (I == NULL) I = new MediaInfoList; - // Intitialize views for HTML output (prevent graphviz plugin from reading invalid metrics) - Page_Custom_HTML->Navigate(L"about:blank"); - //Load GUI preferences GUI_Configure(); + //Set Edge WebView2 UDF directory environment variable + Ztring UserDataDir=Prefs->BaseFolder; + UserDataDir.resize(UserDataDir.size()-1); + UserDataDir=UserDataDir.substr(0, UserDataDir.rfind(__T("\\"))+1); + UserDataDir+=__T("WebView2"); + SetEnvironmentVariable(__T("WEBVIEW2_USER_DATA_FOLDER"), UserDataDir.c_str()); + + // Intitialize views for HTML output (prevent graphviz plugin from reading invalid metrics) + Page_Custom_HTML->Navigate(L"about:blank"); + //File(s) in command line #ifdef UNICODE if (IsWin9X()) diff --git a/Source/GUI/VCL/GUI_Main.dfm b/Source/GUI/VCL/GUI_Main.dfm index 8ffed1fd7..9a3a962c7 100644 --- a/Source/GUI/VCL/GUI_Main.dfm +++ b/Source/GUI/VCL/GUI_Main.dfm @@ -587,6 +587,7 @@ object MainF: TMainF Width = 300 Height = 150 TabOrder = 0 + SelectedEngine = EdgeIfAvailable ControlData = { 4C000000021F0000810F00000000000000000000000000000000000000000000 000000004C000000000000000000000001000000E0D057007335CF11AE690800 @@ -627,6 +628,7 @@ object MainF: TMainF Width = 300 Height = 369 TabOrder = 1 + SelectedEngine = EdgeIfAvailable ControlData = { 4C000000021F0000232600000000000000000000000000000000000000000000 000000004C000000000000000000000001000000E0D057007335CF11AE690800 From c3b58107ddf221a8fea99d1001cac56eac9788e4 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:13:29 +0800 Subject: [PATCH 2/3] Windows GUI: Enable WebView2 native dark mode Enable use of WebView2 native dark mode for HTML and Graph views. --- Source/GUI/VCL/GUI_Main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/GUI/VCL/GUI_Main.cpp b/Source/GUI/VCL/GUI_Main.cpp index 811bb28ac..cb293023a 100644 --- a/Source/GUI/VCL/GUI_Main.cpp +++ b/Source/GUI/VCL/GUI_Main.cpp @@ -164,6 +164,13 @@ std::wstring __fastcall TMainF::InjectHTMLStyle(const wchar_t* HTMLDocument) { std::wstring modifiedHTML(HTMLDocument); const wchar_t* StyleContent = L""; + //WebView2 Engine theme switching overrides + if (Prefs->Config(__T("Theme")).To_int32s()==1) //always light mode + StyleContent = L""; + if (Prefs->Config(__T("Theme")).To_int32s()==2) //always dark mode + StyleContent = L""; + modifiedHTML = InsertText(modifiedHTML, L"", StyleContent); + //IE Engine workarounds if (TStyleManager::ActiveStyle == TStyleManager::Style[DARK_MODE_STYLE]) //app is currently in dark mode StyleContent = L""; @@ -979,7 +986,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page) { Ztring TempA; TempA=Prefs->Translate(__T("At least one file")); Ztring Temp; - Temp+=L"
"; + Temp+=L""; Temp+=TempA.To_Unicode(); Temp+=L""; Temp=InjectHTMLStyle(Temp.c_str()); @@ -1105,7 +1112,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page) S1 = State; } - if (S1.size()>1 && S1[0]=='<' && S1[1]=='h') + if (S1.size()>1 && ( !wcsncmp(S1.c_str(),L"",15-1) || !wcsncmp(S1.c_str(),L"",6-1) )) { //Supposing this is HTML Page_Custom_Text->Visible=false; @@ -1119,6 +1126,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page) FileName_Temp+=__T(".html"); } F.Create(FileName_Temp, true); + S1=InjectHTMLStyle(S1.c_str()); F.Write(S1); F.Close(); //Navigate From 99458329513d4202b30f90831bcb76ef6a101e6d Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:13:50 +0800 Subject: [PATCH 3/3] Windows GUI: Bundle WebView2Loader.dll --- Release/Release_GUI_Windows_i386.bat | 1 + Release/Release_GUI_Windows_x64.bat | 1 + Source/Install/MediaInfo_GUI_Windows.nsi | 4 ++++ Source/Install/MediaInfo_GUI_Windows_i386.nsi | 3 +++ Source/Install/MediaInfo_GUI_Windows_x64.nsi | 3 +++ 5 files changed, 12 insertions(+) diff --git a/Release/Release_GUI_Windows_i386.bat b/Release/Release_GUI_Windows_i386.bat index e5fb3867c..fe71b09e2 100644 --- a/Release/Release_GUI_Windows_i386.bat +++ b/Release/Release_GUI_Windows_i386.bat @@ -29,6 +29,7 @@ copy BCB\GUI\MediaInfo_GUI.exe BCB\GUI\MediaInfo.exe copy ..\Project\BCB\GUI\Win32\Release\MediaInfo_GUI.exe MediaInfo_GUI_Windows_i386\MediaInfo.exe xcopy ..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo.dll MediaInfo_GUI_Windows_i386\ /S xcopy ..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo_InfoTip.dll MediaInfo_GUI_Windows_i386\ /S +xcopy "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win32\WebView2Loader.dll" MediaInfo_GUI_Windows_i386\ @rem --- Copying : Plugins --- xcopy ..\Source\Resource\Plugin\* MediaInfo_GUI_Windows_i386\Plugin\ /S diff --git a/Release/Release_GUI_Windows_x64.bat b/Release/Release_GUI_Windows_x64.bat index 90bc91196..4bad46868 100644 --- a/Release/Release_GUI_Windows_x64.bat +++ b/Release/Release_GUI_Windows_x64.bat @@ -26,6 +26,7 @@ mkdir MediaInfo_GUI_Windows_x64 copy ..\Project\BCB\GUI\Win64\Release\MediaInfo_GUI.exe MediaInfo_GUI_Windows_x64\MediaInfo.exe xcopy ..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo.dll MediaInfo_GUI_Windows_x64\ /S xcopy ..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo_InfoTip.dll MediaInfo_GUI_Windows_x64\ /S +xcopy "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win64\WebView2Loader.dll" MediaInfo_GUI_Windows_x64\ @rem --- Copying : Plugins --- xcopy ..\Source\Resource\Plugin\* MediaInfo_GUI_Windows_x64\Plugin\ /S diff --git a/Source/Install/MediaInfo_GUI_Windows.nsi b/Source/Install/MediaInfo_GUI_Windows.nsi index 675589634..dbfbcac70 100644 --- a/Source/Install/MediaInfo_GUI_Windows.nsi +++ b/Source/Install/MediaInfo_GUI_Windows.nsi @@ -136,11 +136,13 @@ Section "SectionPrincipale" SEC01 File "/oname=MediaInfo.exe" "..\..\Project\BCB\GUI\Win64\Release\MediaInfo_GUI.exe" File "..\..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo_InfoTip.dll" File "..\..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo.dll" + File "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win64\WebView2Loader.dll" File "$%BPATH%\Windows\libcurl\x64\Release\LIBCURL.DLL" ${Else} File "/oname=MediaInfo.exe" "..\..\Project\BCB\GUI\Win32\Release\MediaInfo_GUI.exe" File "..\..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo_InfoTip.dll" File "..\..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo.dll" + File "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win32\WebView2Loader.dll" File "$%BPATH%\Windows\libcurl\Win32\Release\LIBCURL.DLL" ${EndIf} File "$%BPATH%\Windows\libcurl\curl-ca-bundle.crt" @@ -211,6 +213,7 @@ Section Uninstall !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.exe" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.dll" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo_i386.dll" + !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\WebView2Loader.dll" Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\MediaInfo_InfoTip.dll" @@ -237,6 +240,7 @@ Section Uninstall RMDir "$INSTDIR\Plugin\Sheet" RMDir "$INSTDIR\Plugin\Tree" RMDir "$INSTDIR\Plugin" + RMDir /r "$INSTDIR\WebView2" RMDir "$INSTDIR" SetRegView 64 diff --git a/Source/Install/MediaInfo_GUI_Windows_i386.nsi b/Source/Install/MediaInfo_GUI_Windows_i386.nsi index 9dc026fa5..d1922d7c1 100644 --- a/Source/Install/MediaInfo_GUI_Windows_i386.nsi +++ b/Source/Install/MediaInfo_GUI_Windows_i386.nsi @@ -129,6 +129,7 @@ Section "SectionPrincipale" SEC01 File "/oname=MediaInfo.exe" "..\..\Project\BCB\GUI\Win32\Release\MediaInfo_GUI.exe" File "..\..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo_InfoTip.dll" File "..\..\..\MediaInfoLib\Project\MSVC2019\Win32\Release\MediaInfo.dll" + File "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win32\WebView2Loader.dll" File "$%BPATH%\Windows\libcurl\Win32\Release\LIBCURL.DLL" File "$%BPATH%\Windows\libcurl\curl-ca-bundle.crt" File "/oname=History.txt" "..\..\History_GUI.txt" @@ -197,6 +198,7 @@ Section Uninstall !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.exe" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.dll" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo_i386.dll" + !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\WebView2Loader.dll" Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\MediaInfo_InfoTip.dll" @@ -223,6 +225,7 @@ Section Uninstall RMDir "$INSTDIR\Plugin\Sheet" RMDir "$INSTDIR\Plugin\Tree" RMDir "$INSTDIR\Plugin" + RMDir /r "$INSTDIR\WebView2" RMDir "$INSTDIR" DeleteRegKey HKLM "${PRODUCT_REGISTRY}" diff --git a/Source/Install/MediaInfo_GUI_Windows_x64.nsi b/Source/Install/MediaInfo_GUI_Windows_x64.nsi index 913bb185a..eeec355c7 100644 --- a/Source/Install/MediaInfo_GUI_Windows_x64.nsi +++ b/Source/Install/MediaInfo_GUI_Windows_x64.nsi @@ -138,6 +138,7 @@ Section "SectionPrincipale" SEC01 File "/oname=MediaInfo.exe" "..\..\Project\BCB\GUI\Win64\Release\MediaInfo_GUI.exe" File "..\..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo_InfoTip.dll" File "..\..\..\MediaInfoLib\Project\MSVC2019\x64\Release\MediaInfo.dll" + File "C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\win64\WebView2Loader.dll" File "$%BPATH%\Windows\libcurl\x64\Release\LIBCURL.DLL" File "$%BPATH%\Windows\libcurl\curl-ca-bundle.crt" File "/oname=History.txt" "..\..\History_GUI.txt" @@ -207,6 +208,7 @@ Section Uninstall !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.exe" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo.dll" !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\MediaInfo_i386.dll" + !insertmacro UnInstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$INSTDIR\WebView2Loader.dll" Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\MediaInfo_InfoTip.dll" @@ -233,6 +235,7 @@ Section Uninstall RMDir "$INSTDIR\Plugin\Sheet" RMDir "$INSTDIR\Plugin\Tree" RMDir "$INSTDIR\Plugin" + RMDir /r "$INSTDIR\WebView2" RMDir "$INSTDIR" SetRegView 64