-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from Voltstro-Studios/master
Release 2.1.1
- Loading branch information
Showing
38 changed files
with
1,138 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
**/*.dll | ||
!**/*.prefab | ||
!**/*.meta | ||
!**/*.meta | ||
!Samples~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/Packages/UnityWebBrowser/Runtime/Core/Engines/EngineProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/Packages/UnityWebBrowser/Runtime/Core/Engines/EngineProcess.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
src/Packages/UnityWebBrowser/Runtime/Core/Engines/Process.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/Packages/UnityWebBrowser/Runtime/Core/Engines/Process/IProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/Packages/UnityWebBrowser/Runtime/Core/Engines/Process/IProcess.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
src/Packages/UnityWebBrowser/Runtime/Core/Engines/Process/LinuxProcess.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
3 changes: 3 additions & 0 deletions
3
src/Packages/UnityWebBrowser/Runtime/Core/Engines/Process/LinuxProcess.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.