mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-11 19:03:51 +02:00
Before this change, the browser would fail to navigate to the local index.html page if the path leading to the file contained any special characters. This resulted in the browser loading into a file view. This fix adds a custom URI scheme that retains the same base directory that was in use previously and sets the default file to index.html. This resolves the issue with cefsharp not loading uris with special characters.
72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using CefSharp;
|
|
using CefSharp.SchemeHandler;
|
|
using CefSharp.WinForms;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace VRCX
|
|
{
|
|
public class CefService
|
|
{
|
|
public static readonly CefService Instance;
|
|
|
|
static CefService()
|
|
{
|
|
Instance = new CefService();
|
|
}
|
|
|
|
internal void Init()
|
|
{
|
|
var cefSettings = new CefSettings
|
|
{
|
|
CachePath = Path.Combine(Program.AppDataDirectory, "cache"),
|
|
UserDataPath = Path.Combine(Program.AppDataDirectory, "userdata"),
|
|
LogSeverity = LogSeverity.Disable,
|
|
WindowlessRenderingEnabled = true,
|
|
PersistSessionCookies = true,
|
|
PersistUserPreferences = true
|
|
};
|
|
|
|
cefSettings.RegisterScheme(new CefCustomScheme
|
|
{
|
|
SchemeName = "localnjs",
|
|
DomainName = "vrcx",
|
|
SchemeHandlerFactory = new FolderSchemeHandlerFactory(
|
|
rootFolder: Path.Combine(Program.BaseDirectory, "html"),
|
|
hostName: "vrcx",
|
|
defaultPage: "index.html"
|
|
)
|
|
});
|
|
|
|
// cefSettings.CefCommandLineArgs.Add("allow-universal-access-from-files");
|
|
// cefSettings.CefCommandLineArgs.Add("ignore-certificate-errors");
|
|
// cefSettings.CefCommandLineArgs.Add("disable-plugins");
|
|
cefSettings.CefCommandLineArgs.Add("disable-spell-checking");
|
|
cefSettings.CefCommandLineArgs.Add("disable-pdf-extension");
|
|
cefSettings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required";
|
|
cefSettings.CefCommandLineArgs.Add("disable-web-security");
|
|
cefSettings.SetOffScreenRenderingBestPerformanceArgs();
|
|
|
|
if (Program.LaunchDebug)
|
|
cefSettings.RemoteDebuggingPort = 8088;
|
|
|
|
CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO (needed for synchronous configRepository)
|
|
CefSharpSettings.ShutdownOnExit = false;
|
|
|
|
// Enable High-DPI support on Windows 7 or newer
|
|
Cef.EnableHighDPISupport();
|
|
|
|
cefSettings.UserAgent = Program.Version;
|
|
|
|
if (Cef.Initialize(cefSettings) == false)
|
|
{
|
|
throw new Exception("Cef.Initialize()");
|
|
}
|
|
}
|
|
|
|
internal void Exit()
|
|
{
|
|
Cef.Shutdown();
|
|
}
|
|
}
|
|
} |