Skip to content

Commit

Permalink
Fixed behavior with brain-dead CUI tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
stuerp committed Jul 6, 2024
1 parent bed89c9 commit 7e4f13f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ To create the component first build the x86 configuration and next the x64 confi

## Change Log

v0.1.5.0-alpha3, 2024-07-05
v0.1.5.0-alpha4, 2024-07-06

* New: Each instance of the component can have a name to easier distinguish between them.
* New: The location of the WebView user data folder can be specified in the Preferences dialog.
Expand All @@ -113,6 +113,7 @@ v0.1.5.0-alpha3, 2024-07-05
* Fixed: Javascript example code (alpha2)
* Fixed: Support for tracks with more than 2 channels was not implemented correctly (alpha2).
* Fixed: The background color of the WebView is now correctly and dynamically set (alpha3).
* Fixed: WebView not appearing in CUI tabs (alpha4, Regression).

v0.1.4.0, 2024-06-12

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.05) P. Stuer **/
/** $VER: Resources.h (2024.07.06) P. Stuer **/

#pragma once

Expand All @@ -19,7 +19,7 @@
/** 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) "-alpha3"
#define STR_COMPONENT_VERSION TOSTRING(NUM_FILE_MAJOR) "." TOSTRING(NUM_FILE_MINOR) "." TOSTRING(NUM_FILE_PATCH) "." TOSTRING(NUM_FILE_PRERELEASE) "-alpha4"
#define STR_COMPONENT_BASENAME "foo_uie_webview"
#define STR_COMPONENT_FILENAME STR_COMPONENT_BASENAME ".dll"
#define STR_COMPONENT_COMPANY_NAME ""
Expand All @@ -36,11 +36,11 @@
#define STR_COPYRIGHT TEXT(STR_COMPONENT_COPYRIGHT)

#define STR_FILE_NAME TEXT(STR_COMPONENT_FILENAME)
#define STR_FILE_VERSION TOSTRING(NUM_FILE_MAJOR) TEXT(".") TOSTRING(NUM_FILE_MINOR) TEXT(".") TOSTRING(NUM_FILE_PATCH) TEXT(".") TOSTRING(NUM_FILE_PRERELEASE) "-alpha3"
#define STR_FILE_VERSION TOSTRING(NUM_FILE_MAJOR) TEXT(".") TOSTRING(NUM_FILE_MINOR) TEXT(".") TOSTRING(NUM_FILE_PATCH) TEXT(".") TOSTRING(NUM_FILE_PRERELEASE) "-alpha4"
#define STR_FILE_DESCRIPTION TEXT(STR_COMPONENT_DESCRIPTION)

#define STR_PRODUCT_NAME STR_INTERNAL_NAME
#define STR_PRODUCT_VERSION TOSTRING(NUM_PRODUCT_MAJOR) TEXT(".") TOSTRING(NUM_PRODUCT_MINOR) TEXT(".") TOSTRING(NUM_PRODUCT_PATCH) TEXT(".") TOSTRING(NUM_PRODUCT_PRERELEASE) "-alpha3"
#define STR_PRODUCT_VERSION TOSTRING(NUM_PRODUCT_MAJOR) TEXT(".") TOSTRING(NUM_PRODUCT_MINOR) TEXT(".") TOSTRING(NUM_PRODUCT_PATCH) TEXT(".") TOSTRING(NUM_PRODUCT_PRERELEASE) "-alpha4"

#define STR_ABOUT_NAME STR_INTERNAL_NAME
#define STR_ABOUT_WEB TEXT("https://github.com/stuerp/") STR_COMPONENT_BASENAME
Expand Down
34 changes: 27 additions & 7 deletions WebView.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** $VER: WebView.cpp (2024.07.05) P. Stuer - Creates the WebView. **/
/** $VER: WebView.cpp (2024.07.06) P. Stuer - Creates the WebView. **/

#include "pch.h"

Expand Down Expand Up @@ -85,17 +85,20 @@ HRESULT UIElement::CreateWebView()
[this](HRESULT hr, ICoreWebView2Controller * controller) -> HRESULT
{
if (controller == nullptr)
return hr;
return E_INVALIDARG;

{
_Controller = controller;

hr = _Controller->get_CoreWebView2(&_WebView);

if (!SUCCEEDED(hr))
{
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to get WebView from controller").c_str());
return hr;
}

// _Controller->put_IsVisible(TRUE);
_Controller->put_IsVisible(TRUE); // Required for the brain-dead CUI.
}

{
Expand Down Expand Up @@ -135,6 +138,9 @@ HRESULT UIElement::CreateWebView()
return E_NOINTERFACE;

hr = WebView03->SetVirtualHostNameToFolderMapping(_HostName, _Configuration._UserDataFolderPath.c_str(), COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW);

if (!SUCCEEDED(hr))
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to set virtual host name").c_str());
}

// Add an event handler to add the host object before navigation starts. That way the host object is available when the scripts start running.
Expand All @@ -153,6 +159,9 @@ HRESULT UIElement::CreateWebView()
// This will replace the previous object with the new object. In our case this is the same object and everything is fine.
HRESULT hr = _WebView->AddHostObjectToScript(TEXT(STR_COMPONENT_BASENAME), &RemoteObject);

if (!SUCCEEDED(hr))
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to add host object to script").c_str());

RemoteObject.pdispVal->Release();

return hr;
Expand All @@ -166,24 +175,32 @@ HRESULT UIElement::CreateWebView()
(
[this](ICoreWebView2 * webView, ICoreWebView2NavigationCompletedEventArgs * eventArgs) -> HRESULT
{
BOOL Success;
BOOL Success = TRUE;

HRESULT hr = eventArgs->get_IsSuccess(&Success);

if (!SUCCEEDED(hr))
{
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to get event status").c_str());
return hr;
}

if (!Success)
{
COREWEBVIEW2_WEB_ERROR_STATUS WebErrorStatus;

hr = eventArgs->get_WebErrorStatus(&WebErrorStatus);

if (WebErrorStatus == COREWEBVIEW2_WEB_ERROR_STATUS_DISCONNECTED)
if (SUCCEEDED(hr))
{
// Do something here if you want to handle a specific error case.
// In most cases this isn't necessary, because the WebView will display its own error page automatically.
if (WebErrorStatus == COREWEBVIEW2_WEB_ERROR_STATUS_DISCONNECTED)
{
// Do something here if you want to handle a specific error case.
// In most cases this isn't necessary, because the WebView will display its own error page automatically.
}
}
else
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to get web error status").c_str());
}

_IsNavigationCompleted = true;
Expand Down Expand Up @@ -211,7 +228,10 @@ HRESULT UIElement::CreateWebView()
HRESULT hr = Args->get_ContextMenuTarget(&Target);

if (!SUCCEEDED(hr))
{
console::printf(GetErrorMessage(hr, STR_COMPONENT_BASENAME " failed to get context menu target").c_str());
return hr;
}

COREWEBVIEW2_CONTEXT_MENU_TARGET_KIND TargetKind;

Expand Down

0 comments on commit 7e4f13f

Please sign in to comment.