I have a WebView2 container app that I am developing for game publishing and have a few issues that are blocking the development process. However, the component is not being read properly, so its functionality is not working at all. Case in point: I have a field that is supposed to be read on the Javascript side which is intended to block input to the game when the container app is not fully active (e. g. if the guide menu is open on an Xbox console). Unfortunately, because the WinRT component isn't being read properly the field shows up as undefined on the Javascript side, resulting in the user's input being blocked in all cases. Other functions (including the reading of game saves from the user's Xbox account) are having the same issue, indicating a major problem with the WinRT component being picked up by the WebView2.
Here's the field definition for my example case:
public static bool GameBarActive { get { return gameBarActive; } }
Activation detection is hanled through the associated window event:
private static void Window_Activated(CoreWindow sender, WindowActivatedEventArgs args)
{
if (args.WindowActivationState == CoreWindowActivationState.Deactivated)
{
gameBarActive = true;
}
else
{
gameBarActive = false;
}
}
What's supposed to happen here is that when gameBarActive is false, then GameBarActive (which is the public, read only version) is supposed to return the value of the internal, writable version from the WinRT component. The C# code that connects the WinRT component to the WebView2 container places it in a top-level Javascript namespace called Xbox with a class named API which exposes the WinRT component to the game. However, because the WinRT component is not being picked up on the Javascript side the detection acts as if it's always true (when in reality there's no definition to speak of).
Using the controller input detection from RPG Maker MV as an example, the input block is supposed to function as follows:
if (Xbox.API.GameBarActive == false) {
var lastState = this._gamepadStates[gamepad.index] || [];
var newState = [];
var buttons = gamepad.buttons;
var axes = gamepad.axes;
var threshold = 0.5;
newState[12] = false;
newState[13] = false;
newState[14] = false;
newState[15] = false;
for (var i = 0; i < buttons.length; i++) {
newState[i] = buttons[i].pressed;
}
if (axes[1] < -threshold) {
newState[12] = true; // up
} else if (axes[1] > threshold) {
newState[13] = true; // down
}
if (axes[0] < -threshold) {
newState[14] = true; // left
} else if (axes[0] > threshold) {
newState[15] = true; // right
}
for (var j = 0; j < newState.length; j++) {
if (newState[j] !== lastState[j]) {
var buttonName = this.gamepadMapper[j];
if (buttonName) {
this._currentState[buttonName] = newState[j];
}
}
}
this._gamepadStates[gamepad.index] = newState;
}
Any insight as to what's going on (or anything else that I can try) would be appreciated.
Big dumb. Turns out that I had also had functions that were set to private when they were supposed to be public, which ended up causing the bigger problems. On top of this, after changing the processing method from Boolean values to string responses I forgot to change the names of the matching function calls on the Javascript side. There was also a matter of using the same spelling regardless of case, which I found out about by switching to function calls in place of the field values from before, along with a major flaw in the code design that was firing the method continuously and thereby confusing things on the C# side.
The updated public function is as follows:
The updated detection is as follows:
The internal field is as follows:
And the updated Javascript is as follows:
Although I'm still verifying things on the C# end with the activation detection (which somehow decided to crap up) I think I have this figured out.