The WebUi class
WebUi opens views and tells you about the web side as a whole.
WebUi opens views and tells you about the web side
Use Open to show one of your HTML pages, and SuspendAll and ResumeAll to hold and release every open view under a reason you name.
public static class WebUi
{
public static bool IsAvailable { get; }
public static string LastError { get; }
public static string Theme { get; }
public static event Action<string> ThemeChanged;
public static WebView Open(string modId, string folder, string page, bool modal);
public static void SuspendAll(string reason);
public static void ResumeAll(string reason);
}
| Method | Returns | What it does |
|---|---|---|
Open(modId, folder, page, modal) | WebView | Opens a view and shows it. Gives null when it cannot. |
SuspendAll(reason) | void | Hides the popup-window views for a reason. |
ResumeAll(reason) | void | Lets go of that reason. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | true when views can be opened. |
LastError | string | The text of the last error. null when there is none. |
Theme | string | "light" or "dark", the look pages should use. |
| Event | Gives you | When it fires | |
|---|---|---|---|
ThemeChanged | string | The new look, "light" or "dark". | The look has changed. You get the new "light" or "dark". |
Things to know
IsAvailableistrueon Windows when the shim is next to the module and has not failed to start.- It turns
falsefor good when the shim fails to start, or when a serious error arrives that belongs to no view. In the default mode, the framework restarts the shim in another mode instead, soIsAvailablestaystrueunless that start fails too.LastErrortells you why. (The fatal-error case applies outside thread mode. In thread mode, such an error restarts the shim in composition mode for the rest of the session.) LastErrorisnullwhen there has been none. It is the text of the last problem the shim reported. It is set when a call to the shim fails, when the shim reports an error, when the shim fails to start, whenOpenfinds no game window yet (no active game window), whenOpenruns after the framework has shut down (WebUi is shut down), and whenObxWebView.dllis missing.Themecomes from the settingAppearance.WebThemeof the WebUi module, which can belight,darkorsystem. The default islight.systemreads the Windows apps theme once at start and again when the setting changes. It does not follow a change of the Windows theme that happens later on its own.ThemeChangedfires with the new look after the setting changes. The framework has already told every open view by then (see Theme).SuspendAll(reason)hides the views that are popup windows, andResumeAll(reason)lets go. Each reason is counted, so everySuspendAllneeds oneResumeAllwith the same reason.- While any reason is held, the views are hidden. An empty reason is ignored, and both calls do nothing when they are not called from your mod’s normal code.
Open(modId, folder, page, modal)creates a view and shows it.folderis the folder with your page, andpageis the file in it to show first, such asindex.html.- A modal view takes over the player’s controls while it is shown. The player cannot move, and the mouse cursor is shown, like in a menu. A view that is not modal leaves the controls alone.
- The first
Openstarts the shim. It is not started earlier. The shim keeps its browser data inBepInEx\cache\ObxWebView. - Your view gets its own web address, made from your mod id. It looks like
https://<host>/, and the framework serves yourfolderthere, sohttps://<host>/index.htmlis<folder>\index.html. - A mod id made of lowercase letters and digits with single dots between them, at most 63 characters, and not
obx.core, turns each dot into-and ends with.obx. Soexample.webuihellogivesexample-webuihello.obx. - Any other id gets
h--and the first 16 hex digits of the SHA-256 hash of the id, then.obx, soMy_Modgivesh--faa957b3378b73e0.obx. Different ids get different hosts, and no id can map toobx-core.obx, the address of the shared files. (A hashed host is 64 bits of SHA-256, so a clash is not a practical risk.https://obx-core.obxis the host of the shared assets, writtenobx-core.obxin the code asCoreHost.) - You can have two open views with the same mod id. Each has its own number.
How the views are hosted
- By default, each view is a small separate window placed over the game. Another mode can be chosen in the module’s config, but the default is the one to build for. (The setting is
Debug.WebUiMode, which can bethread,compositionorwindowed. The default isthread. It is read once when the shim starts, so a change needs a game restart.)thread: the shim runs on its own thread, and each view is a WebView2 control in a popup window owned by the game window, placed over the view’s bounds in the game’s client rectangle.composition: the composition root runs on the game thread. This was the mode before version 0.9.windowed: a child window of the game runs on the game thread.windowedandcompositionmay not show over a fullscreen game, so when one of them is chosen while the game is not in windowed screen mode, the log gets one warning when the shim starts, saying thatthreadis the default and works in borderless fullscreen.Debug.WebUiWindowed(trueorfalse, defaultfalse) is deprecated. UseWebUiMode = windowedinstead. When it istrue, the mode iswindowedwhateverWebUiModesays.Debug.WebUiExclusiveThread(trueorfalse, defaultfalse) is a test setting. When it istrue, thread mode is tried in exclusive full screen instead of falling back to composition, to see whether the popups draw over it. It is read once when the shim starts, so a change needs a game restart.
- Thread mode turns itself into composition mode for the rest of the session in three cases, and each is logged. These are: exclusive full screen is on at the first
Open(unlessDebug.WebUiExclusiveThreadistrue); the thread does not start (composition is then tried at once); and a serious shim error arrives (the views close, and the nextOpenuses composition).
Limits
Opengivesnullwhen:- the shim cannot start. That means the computer is not Windows, the shim is missing, the game window does not exist yet, or the start failed;
modalistrueand the game is busy. That means a menu, the pause menu, a shop, a conversation or the developer console is open, no game camera is loaded, or the player’s controls are off;folderis not a folder that exists, orpageis not a relative path (see Navigation);- the view cannot be shown. It is closed again.
- A view that is not modal ignores the busy check.