Skip to content

Commit

Permalink
Merge pull request #289 from Voltstro-Studios/master
Browse files Browse the repository at this point in the history
Release 2.1.1
  • Loading branch information
Voltstro authored Mar 22, 2024
2 parents d98d93f + 527fd8a commit b5ddf3e
Show file tree
Hide file tree
Showing 38 changed files with 1,138 additions and 50 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.1] - 2024-03-22

### Added

- Added Dynamic Runtime Sample

### Changed

- Bump deps
- Updated CEF to 122.1.13
- Updated basic sample description

### Fixed

- Implemented a handful of fixes to attempt to resolve issue #166
- Prevent engine process lingering when main parent process dies
- Uses Job Objects on Windows
- Uses prctl on Linux
- Errors related to binding ports are no longer swallowed

## [2.1.0] - 2024-02-18

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/Packages/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/*.dll
!**/*.prefab
!**/*.meta
!**/*.meta
!Samples~
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"changelogUrl": "https://projects.voltstro.dev/UnityWebBrowser/changelog/",
"unity": "2021.2",
"dependencies": {
"dev.voltstro.unitywebbrowser.engine.cef": "2.1.0-121.3.13",
"dev.voltstro.unitywebbrowser.engine.cef": "2.1.1-122.1.13",
"dev.voltstro.unitywebbrowser.unix-support": "1.0.0"
},
"documentationUrl": "https://projects.voltstro.dev/UnityWebBrowser/",
"description": "CEF Engine for Unity Web Browser (Linux x64)",
"displayName": "Unity Web Browser CEF Engine (Linux x64)",
"version": "2.1.0-121.3.13"
"version": "2.1.1-122.1.13"
}
4 changes: 2 additions & 2 deletions src/Packages/UnityWebBrowser.Engine.Cef.Win-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"changelogUrl": "https://projects.voltstro.dev/UnityWebBrowser/changelog/",
"unity": "2021.2",
"dependencies": {
"dev.voltstro.unitywebbrowser.engine.cef": "2.1.0-121.3.13"
"dev.voltstro.unitywebbrowser.engine.cef": "2.1.1-122.1.13"
},
"documentationUrl": "https://projects.voltstro.dev/UnityWebBrowser/",
"description": "CEF Engine for Unity Web Browser (Windows x64)",
"displayName": "Unity Web Browser CEF Engine (Windows x64)",
"version": "2.1.0-121.3.13"
"version": "2.1.1-122.1.13"
}
4 changes: 2 additions & 2 deletions src/Packages/UnityWebBrowser.Engine.Cef/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"changelogUrl": "https://projects.voltstro.dev/UnityWebBrowser/changelog/",
"description": "CEF Engine for Unity Web Browser",
"documentationUrl": "https://projects.voltstro.dev/UnityWebBrowser/",
"version": "2.1.0-121.3.13",
"version": "2.1.1-122.1.13",
"author": {
"email": "[email protected]",
"url": "https://voltstro.dev",
"name": "Voltstro"
},
"unity": "2021.3",
"dependencies": {
"dev.voltstro.unitywebbrowser": "2.0.2"
"dev.voltstro.unitywebbrowser": "2.1.1"
},
"licensesUrl": "https://github.com/Voltstro-Studios/UnityWebBrowser/blob/master/LICENSE.md",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/Packages/UnityWebBrowser/Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0")]
[assembly: AssemblyFileVersion("2.1.0")]
[assembly: AssemblyVersion("2.1.1")]
[assembly: AssemblyFileVersion("2.1.1")]

[assembly: InternalsVisibleTo("VoltstroStudios.UnityWebBrowser.Prj")]
[assembly: InternalsVisibleTo("VoltstroStudios.UnityWebBrowser.Editor")]
Expand Down
80 changes: 80 additions & 0 deletions src/Packages/UnityWebBrowser/Runtime/Core/Engines/EngineProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// UnityWebBrowser (UWB)
// Copyright (c) 2021-2024 Voltstro-Studios
//
// This project is under the MIT license. See the LICENSE.md file for more details.

using System;
using System.Diagnostics;
using VoltstroStudios.UnityWebBrowser.Core.Engines.Process;
using VoltstroStudios.UnityWebBrowser.Helper;
using VoltstroStudios.UnityWebBrowser.Logging;

namespace VoltstroStudios.UnityWebBrowser.Core.Engines
{
/// <summary>
/// Handler for the engine process
/// </summary>
internal sealed class EngineProcess : IDisposable
{
private readonly IProcess processHandle;
private readonly Engine engine;
private readonly IWebBrowserLogger logger;

/// <summary>
/// Creates a new <see cref="EngineProcess"/> instance
/// </summary>
/// <param name="engine"></param>
/// <param name="logger"></param>
public EngineProcess(Engine engine, IWebBrowserLogger logger)
{
#if UNITY_STANDALONE_WIN
processHandle = new WindowProcess();
#elif UNITY_STANDALONE_LINUX
processHandle = new LinuxProcess(logger);
#endif

this.engine = engine;
this.logger = logger;
}

/// <summary>
/// Has the process exited?
/// </summary>
public bool HasExited => processHandle.HasExited;

/// <summary>
/// What was the exit code of the process
/// </summary>
public int ExitCode => processHandle.ExitCode;

/// <summary>
/// Starts the engine process
/// </summary>
/// <param name="arguments"></param>
/// <param name="onLogEvent"></param>
/// <param name="onErrorLogEvent"></param>
public void StartProcess(string arguments, DataReceivedEventHandler onLogEvent, DataReceivedEventHandler onErrorLogEvent)
{
string engineFullProcessPath = WebBrowserUtils.GetBrowserEngineProcessPath(engine);
string engineDirectory = WebBrowserUtils.GetBrowserEnginePath(engine);

logger.Debug($"Process Path: '{engineFullProcessPath}'\nWorking: '{engineDirectory}'");
logger.Debug($"Arguments: '{arguments}'");

processHandle.StartProcess(engineFullProcessPath, engineDirectory, arguments, onLogEvent, onErrorLogEvent);
}

/// <summary>
/// Kills the engine process
/// </summary>
public void KillProcess()
{
processHandle.KillProcess();
}

public void Dispose()
{
processHandle.Dispose();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// UnityWebBrowser (UWB)
// Copyright (c) 2021-2024 Voltstro-Studios
//
// This project is under the MIT license. See the LICENSE.md file for more details.

using System;
using System.Diagnostics;

namespace VoltstroStudios.UnityWebBrowser.Core.Engines.Process
{
internal interface IProcess : IDisposable
{
public void StartProcess(string executable, string workingDir, string arguments, DataReceivedEventHandler onLogEvent, DataReceivedEventHandler onErrorLogEvent);

public void KillProcess();

public bool HasExited { get; }

public int ExitCode { get; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// UnityWebBrowser (UWB)
// Copyright (c) 2021-2024 Voltstro-Studios
//
// This project is under the MIT license. See the LICENSE.md file for more details.

#if UNITY_STANDALONE_LINUX

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using VoltstroStudios.UnityWebBrowser.Logging;
using VoltstroStudios.UnityWebBrowser.UnixSupport;

namespace VoltstroStudios.UnityWebBrowser.Core.Engines.Process
{
internal sealed class LinuxProcess : IProcess
{
private readonly System.Diagnostics.Process process;
private readonly IWebBrowserLogger logger;

public LinuxProcess(IWebBrowserLogger logger)
{
process = new System.Diagnostics.Process();
this.logger = logger;
}

public bool HasExited { get; }
public int ExitCode { get; }

public void StartProcess(string executable, string workingDir, string arguments, DataReceivedEventHandler onLogEvent,
DataReceivedEventHandler onErrorLogEvent)
{
if (PermissionsManager.CheckAndSetIfNeededFileExecutablePermission(executable))
logger.Warn(
"UWB engine process did not have +rwx permissions! Engine process permission's were updated for the user.");

ProcessStartInfo startInfo = new(executable, arguments)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = workingDir
};

process.StartInfo = startInfo;
process.OutputDataReceived += onLogEvent;
process.ErrorDataReceived += onErrorLogEvent;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}

public void KillProcess()
{
TimeSpan timeout = TimeSpan.FromSeconds(30);
HashSet<int> children = new();
GetAllChildIdsUnix(process.Id, children, timeout);
foreach (int childId in children) KillProcessUnix(childId, timeout);
KillProcessUnix(process.Id, timeout);
}

public void Dispose()
{
process.Dispose();
}

private static void GetAllChildIdsUnix(int parentId, ISet<int> children, TimeSpan timeout)
{
int exitCode = RunProcessAndWaitForExit(
"pgrep",
$"-P {parentId}",
timeout,
out string stdout);

if (exitCode != 0 || string.IsNullOrEmpty(stdout)) return;
using StringReader reader = new(stdout);
while (true)
{
string text = reader.ReadLine();
if (text == null) return;

if (!int.TryParse(text, out int id)) continue;

children.Add(id);
// Recursively get the children
GetAllChildIdsUnix(id, children, timeout);
}
}

private static void KillProcessUnix(int processId, TimeSpan timeout)
{
RunProcessAndWaitForExit(
"kill",
$"-TERM {processId}",
timeout,
out string _);
}

private static int RunProcessAndWaitForExit(string fileName, string arguments, TimeSpan timeout,
out string stdout)
{
ProcessStartInfo startInfo = new()
{
FileName = fileName,
Arguments = arguments,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};

System.Diagnostics.Process process = System.Diagnostics.Process.Start(startInfo);

stdout = null;
if (process.WaitForExit((int)timeout.TotalMilliseconds))
stdout = process.StandardOutput.ReadToEnd();
else
process.Kill();

return process.ExitCode;
}
}
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5ddf3e

Please sign in to comment.