mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
WebView fixes and improvements.
Re-organize initialization so that User-Agent CVar actually works. Add web.headless CVar to not load CEF even on graphical client. Clean up init logic to not rely on static IoC, and clean up loggers used too.
This commit is contained in:
@@ -39,19 +39,19 @@ END TEMPLATE-->
|
||||
|
||||
### New features
|
||||
|
||||
*None yet*
|
||||
* `web.headless` CVar can now be used to avoid loading CEF with graphical client.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
*None yet*
|
||||
* `web.user_agent` CVar can now be overriden by content before WebView is initialized.
|
||||
|
||||
### Other
|
||||
|
||||
*None yet*
|
||||
* WebView works again and is properly available from the launcher.
|
||||
|
||||
### Internal
|
||||
|
||||
*None yet*
|
||||
* Clean up WebView initialization logic to avoid static `IoCManager`.
|
||||
|
||||
|
||||
## 0.89.0.0
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Robust.Client.WebView.Cef
|
||||
var impl = new WebViewWindowImpl(this);
|
||||
|
||||
var lifeSpanHandler = new WindowLifeSpanHandler(impl);
|
||||
var reqHandler = new RobustRequestHandler(Logger.GetSawmill("root"));
|
||||
var reqHandler = new RobustRequestHandler(_sawmill);
|
||||
var client = new WindowCefClient(lifeSpanHandler, reqHandler);
|
||||
var settings = new CefBrowserSettings();
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
IoCManager.Instance!.InjectDependencies(this, oneOff: true);
|
||||
|
||||
_sawmill = _logManager.GetSawmill("web.cef");
|
||||
|
||||
_consoleHost.RegisterCommand(
|
||||
@@ -77,7 +75,7 @@ namespace Robust.Client.WebView.Cef
|
||||
CachePath = cachePath,
|
||||
};
|
||||
|
||||
var userAgentOverride = _cfg.GetCVar(WCVars.UserAgentOverride);
|
||||
var userAgentOverride = _cfg.GetCVar(WCVars.WebUserAgentOverride);
|
||||
if (!string.IsNullOrEmpty(userAgentOverride))
|
||||
{
|
||||
settings.UserAgent = userAgentOverride;
|
||||
@@ -96,7 +94,11 @@ namespace Robust.Client.WebView.Cef
|
||||
|
||||
if (_cfg.GetCVar(WCVars.WebResProtocol))
|
||||
{
|
||||
var handler = new ResourceSchemeFactoryHandler(this, _resourceManager, Logger.GetSawmill("web.res"));
|
||||
var handler = new ResourceSchemeFactoryHandler(
|
||||
this,
|
||||
_resourceManager,
|
||||
_logManager.GetSawmill("web.res"));
|
||||
|
||||
CefRuntime.RegisterSchemeHandlerFactory("res", "", handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ public static class WCVars
|
||||
/// <summary>
|
||||
/// Overrides the default CEF user-agent when set to a non-empty string.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<string> UserAgentOverride =
|
||||
public static readonly CVarDef<string> WebUserAgentOverride =
|
||||
CVarDef.Create("web.user_agent", "", CVar.CLIENTONLY);
|
||||
|
||||
/// <summary>
|
||||
/// If true, use headless WebView implementation even with graphical client (turn off CEF).
|
||||
/// </summary>
|
||||
public static readonly CVarDef<bool> WebHeadless =
|
||||
CVarDef.Create("web.headless", false, CVar.CLIENTONLY);
|
||||
}
|
||||
|
||||
@@ -15,22 +15,29 @@ namespace Robust.Client.WebView
|
||||
{
|
||||
private IWebViewManagerImpl? _impl;
|
||||
|
||||
public void Initialize(GameController.DisplayMode mode)
|
||||
public void PreInitialize(IDependencyCollection dependencies, GameController.DisplayMode mode)
|
||||
{
|
||||
DebugTools.Assert(_impl == null, "WebViewManager has already been initialized!");
|
||||
|
||||
var cfg = IoCManager.Resolve<IConfigurationManagerInternal>();
|
||||
var cfg = dependencies.Resolve<IConfigurationManagerInternal>();
|
||||
cfg.LoadCVarsFromAssembly(typeof(WebViewManager).Assembly);
|
||||
|
||||
IoCManager.RegisterInstance<IWebViewManager>(this);
|
||||
IoCManager.RegisterInstance<IWebViewManagerInternal>(this);
|
||||
dependencies.RegisterInstance<IWebViewManager>(this);
|
||||
dependencies.RegisterInstance<IWebViewManagerInternal>(this);
|
||||
|
||||
if (mode == GameController.DisplayMode.Headless)
|
||||
if (mode == GameController.DisplayMode.Headless || cfg.GetCVar(WCVars.WebHeadless))
|
||||
_impl = new WebViewManagerHeadless();
|
||||
else
|
||||
_impl = new WebViewManagerCef();
|
||||
|
||||
_impl.Initialize();
|
||||
dependencies.InjectDependencies(_impl, oneOff: true);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
DebugTools.Assert(_impl != null, "WebViewManager has not yet been initialized!");
|
||||
|
||||
_impl!.Initialize();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace Robust.Client
|
||||
|
||||
var managerType = attribute.ImplementationType;
|
||||
_webViewHook = (IWebViewManagerHook)Activator.CreateInstance(managerType)!;
|
||||
_webViewHook.Initialize(mode);
|
||||
_webViewHook.PreInitialize(_dependencyCollection, mode);
|
||||
|
||||
Logger.Debug("Done initializing Robust.Client.WebView");
|
||||
Logger.Debug("Done pre-initializing Robust.Client.WebView");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -131,6 +131,10 @@ namespace Robust.Client
|
||||
|
||||
// Call Init in game assemblies.
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.PreInit);
|
||||
|
||||
// Finish initialization of WebView if loaded.
|
||||
_webViewHook?.Initialize();
|
||||
|
||||
_modLoader.BroadcastRunLevel(ModRunLevel.Init);
|
||||
|
||||
// Start bad file extensions check after content init,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Robust.Client.WebViewHook
|
||||
{
|
||||
@@ -18,7 +19,8 @@ namespace Robust.Client.WebViewHook
|
||||
|
||||
internal interface IWebViewManagerHook
|
||||
{
|
||||
void Initialize(GameController.DisplayMode mode);
|
||||
void PreInitialize(IDependencyCollection dependencies, GameController.DisplayMode mode);
|
||||
void Initialize();
|
||||
void Update();
|
||||
void Shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user