mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-12 03:13:50 +02:00
Build as Self Contained and Selfhost CefSharp SubProcess (#693)
* Added self contained parameter to builds * Remove dotnet install from installer * Fixed missing SubProcessExe * Self hot browser subprocess --------- Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
2
.github/workflows/github_actions.yml
vendored
2
.github/workflows/github_actions.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
||||
run: cd ${{ github.workspace }}/html && npm run production && cd ${{ github.workspace }}
|
||||
|
||||
- name: Build .NET Application
|
||||
run: dotnet build -p:Configuration=Release -p:Platform=x64 -p:EnableWindowsTargeting=true
|
||||
run: dotnet build -p:Configuration=Release -p:Platform=x64 -p:EnableWindowsTargeting=true --self-contained
|
||||
|
||||
- name: Copy Web UI
|
||||
run: cp -r ${{ github.workspace }}/html/dist ${{ github.workspace }}/bin/x64/Release/html
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace VRCX
|
||||
WindowlessRenderingEnabled = true,
|
||||
PersistSessionCookies = true,
|
||||
PersistUserPreferences = true,
|
||||
UserAgent = Program.Version
|
||||
UserAgent = Program.Version,
|
||||
BrowserSubprocessPath = Environment.ProcessPath
|
||||
};
|
||||
|
||||
cefSettings.RegisterScheme(new CefCustomScheme
|
||||
@@ -59,7 +60,7 @@ namespace VRCX
|
||||
//CefSharpSettings.WcfEnabled = true; // TOOD: REMOVE THIS LINE YO (needed for synchronous configRepository)
|
||||
CefSharpSettings.ShutdownOnExit = false;
|
||||
|
||||
if (Cef.Initialize(cefSettings) == false)
|
||||
if (Cef.Initialize(cefSettings, false) == false)
|
||||
{
|
||||
throw new Exception("Cef.Initialize()");
|
||||
}
|
||||
|
||||
54
Dotnet/Cef/SubProcess.cs
Normal file
54
Dotnet/Cef/SubProcess.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using CefSharp.Internals;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace VRCX;
|
||||
|
||||
public class BrowserSubprocess
|
||||
{
|
||||
/// <summary>
|
||||
/// This function should be called from the application entry point function (typically Program.Main)
|
||||
/// to execute a secondary process e.g. gpu, renderer, utility
|
||||
/// This overload is specifically used for .Net Core. For hosting your own BrowserSubProcess
|
||||
/// it's preferable to use the Main method provided by this class.
|
||||
/// - Pass in command line args
|
||||
/// </summary>
|
||||
/// <param name="args">command line args</param>
|
||||
/// <returns>
|
||||
/// If called for the browser process (identified by no "type" command-line value) it will return immediately
|
||||
/// with a value of -1. If called for a recognized secondary process it will block until the process should exit
|
||||
/// and then return the process exit code.
|
||||
/// </returns>
|
||||
public static void Start()
|
||||
{
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
var type = CommandLineArgsParser.GetArgumentValue(args, CefSharpArguments.SubProcessTypeArgument);
|
||||
|
||||
if (string.IsNullOrEmpty(type))
|
||||
{
|
||||
// If --type param missing from command line CEF/Chromium assums
|
||||
// this is the main process (as all subprocesses must have a type param).
|
||||
return;
|
||||
}
|
||||
|
||||
var browserSubprocessDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CefSharp.BrowserSubprocess.Core.dll");
|
||||
if (!File.Exists(browserSubprocessDllPath))
|
||||
{
|
||||
browserSubprocessDllPath = Path.Combine(Path.GetDirectoryName(typeof(CefSharp.Core.BrowserSettings).Assembly.Location), "CefSharp.BrowserSubprocess.Core.dll");
|
||||
}
|
||||
var browserSubprocessDll = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(browserSubprocessDllPath);
|
||||
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
|
||||
|
||||
var browserSubprocessExecutable = Activator.CreateInstance(browserSubprocessExecutableType);
|
||||
|
||||
var mainMethod = browserSubprocessExecutableType.GetMethod("MainSelfHost", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
||||
var argCount = mainMethod.GetParameters();
|
||||
|
||||
var methodArgs = new object[] { args };
|
||||
|
||||
var exitCode = mainMethod.Invoke(null, methodArgs);
|
||||
|
||||
Environment.Exit((int)exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@ namespace VRCX
|
||||
|
||||
private static void Run()
|
||||
{
|
||||
BrowserSubprocess.Start();
|
||||
Update.Check();
|
||||
StartupArgs.ArgsCheck();
|
||||
GetVersion();
|
||||
|
||||
@@ -118,20 +118,6 @@ Function .onInit
|
||||
done:
|
||||
FunctionEnd
|
||||
|
||||
Function CheckAndInstallDotNet
|
||||
nsExec::ExecToStack /OEM 'cmd /c dir "%windir%\system32" | dotnet --list-runtimes | find /c /i "Microsoft.NETCore.App 8"'
|
||||
Pop $0
|
||||
Pop $1
|
||||
StrCpy $2 $1 1
|
||||
StrCmp $2 "1" 0 version_not_found
|
||||
goto version_found
|
||||
version_not_found:
|
||||
inetc::get "https://aka.ms/dotnet/8.0/windowsdesktop-runtime-win-x64.exe" $TEMP\dotnet-runtime-win-x64.exe
|
||||
ExecWait "$TEMP\dotnet-runtime-win-x64.exe /install /quiet /norestart"
|
||||
Delete "$TEMP\dotnet-runtime-win-x64.exe"
|
||||
version_found:
|
||||
FunctionEnd
|
||||
|
||||
Function createDesktopShortcut
|
||||
CreateShortcut "$DESKTOP\VRCX.lnk" "$INSTDIR\VRCX.exe"
|
||||
FunctionEnd
|
||||
@@ -164,8 +150,6 @@ Section "Install" SecInstall
|
||||
Delete "$TEMP\vcredist_x64.exe"
|
||||
VSRedistInstalled:
|
||||
|
||||
Call CheckAndInstallDotNet
|
||||
|
||||
SetOutPath "$INSTDIR"
|
||||
|
||||
File /r /x *.log /x *.pdb "..\bin\x64\Release\*.*"
|
||||
|
||||
@@ -9,7 +9,7 @@ $ZipName = "VRCX_" + $Date + ".zip"
|
||||
$SetupName = "VRCX_" + $Date + "_Setup.exe"
|
||||
|
||||
Write-Host "Building .Net..." -ForegroundColor Green
|
||||
msbuild VRCX.sln -p:Configuration=Release -p:Platform=x64 -p:RestorePackagesConfig=true -t:"Restore;Clean;Build" -m
|
||||
dotnet build VRCX.sln -p:Configuration=Release -p:Platform=x64 -p:RestorePackagesConfig=true -t:"Restore;Clean;Build" -m --self-contained
|
||||
|
||||
Write-Host "Building Node.js..." -ForegroundColor Green
|
||||
cd "html"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@echo off
|
||||
dotnet build VRCX.sln -p:Configuration=Release -p:Platform=x64 -p:RestorePackagesConfig=true -t:"Restore;Clean;Build" -m
|
||||
dotnet build VRCX.sln -p:Configuration=Release -p:Platform=x64 -p:RestorePackagesConfig=true -t:"Restore;Clean;Build" -m --self-contained
|
||||
mklink /J "%~dp0\bin\x64\Release\html" "%~dp0\html\dist"
|
||||
pause
|
||||
|
||||
Reference in New Issue
Block a user