Folder cs files

This commit is contained in:
Natsumi
2023-10-11 20:36:41 +13:00
parent 634f465927
commit 6cfadfa67f
53 changed files with 192 additions and 147 deletions

View File

@@ -0,0 +1,36 @@
// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using CefSharp;
namespace VRCX
{
public class CustomDownloadHandler : IDownloadHandler
{
public bool CanDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, string url, string requestMethod)
{
return true;
}
public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
if (callback.IsDisposed)
return;
using (callback)
{
callback.Continue(
downloadItem.SuggestedFileName,
showDialog: true
);
}
}
public void OnDownloadUpdated(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
}
}
}

View File

@@ -0,0 +1,43 @@
using CefSharp.Enums;
using CefSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VRCX
{
/// <summary>
/// This class is used to 'handle' drag and drop events.
/// All it does is call a function in the app with the file name of the file being dragged into the window, since chromium doesn't have access to the full file path on regular drop events.
/// </summary>
public class CustomDragHandler : IDragHandler
{
public bool OnDragEnter(IWebBrowser chromiumWebBrowser, IBrowser browser, IDragData dragData, DragOperationsMask mask)
{
if (dragData.IsFile && dragData.FileNames != null && dragData.FileNames.Count > 0)
{
string file = dragData.FileNames[0];
if (!file.EndsWith(".png") && !file.EndsWith(".jpg") && !file.EndsWith(".jpeg"))
{
dragData.Dispose();
return true;
}
// forgive me father for i have sinned once again
AppApi.Instance.ExecuteAppFunction("dragEnterCef", dragData.FileNames[0]);
dragData.Dispose();
return false;
}
dragData.Dispose();
return true;
}
public void OnDraggableRegionsChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IList<DraggableRegion> regions)
{
}
}
}

View File

@@ -0,0 +1,33 @@
// Copyright(c) 2019 pypy. All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using CefSharp;
namespace VRCX
{
public class CustomMenuHandler : IContextMenuHandler
{
public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
{
// remove default right click
if (!parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable))
model.Clear();
}
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
{
return false;
}
public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
}
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
{
return false;
}
}
}

View File

@@ -0,0 +1,24 @@
// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System.Collections.Generic;
using CefSharp;
using CefSharp.Enums;
namespace VRCX
{
public class CefNoopDragHandler : IDragHandler
{
bool IDragHandler.OnDragEnter(IWebBrowser chromiumWebBrowser, IBrowser browser, IDragData dragData, DragOperationsMask mask)
{
return true;
}
void IDragHandler.OnDraggableRegionsChanged(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IList<DraggableRegion> regions)
{
}
}
}

73
Dotnet/Cef/CefService.cs Normal file
View File

@@ -0,0 +1,73 @@
using System;
using System.IO;
using CefSharp;
using CefSharp.SchemeHandler;
using CefSharp.WinForms;
namespace VRCX
{
public class CefService
{
public static readonly CefService Instance;
static CefService()
{
Instance = new CefService();
}
internal void Init()
{
var userDataDir = Path.Combine(Program.AppDataDirectory, "userdata");
var cefSettings = new CefSettings
{
RootCachePath = userDataDir,
CachePath = Path.Combine(userDataDir, "cache"),
LogSeverity = LogSeverity.Disable,
WindowlessRenderingEnabled = true,
PersistSessionCookies = true,
PersistUserPreferences = true,
UserAgent = Program.Version
};
cefSettings.RegisterScheme(new CefCustomScheme
{
SchemeName = "file",
DomainName = "vrcx",
SchemeHandlerFactory = new FolderSchemeHandlerFactory(
Path.Combine(Program.BaseDirectory, "html"),
"file",
defaultPage: "index.html"
),
IsLocal = true
});
// 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(); // causes white screen sometimes?
if (Program.LaunchDebug)
{
cefSettings.RemoteDebuggingPort = 8088;
cefSettings.CefCommandLineArgs["remote-allow-origins"] = "*";
}
CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO (needed for synchronous configRepository)
CefSharpSettings.ShutdownOnExit = false;
if (Cef.Initialize(cefSettings) == false)
{
throw new Exception("Cef.Initialize()");
}
}
internal void Exit()
{
Cef.Shutdown();
}
}
}