Skip to content

Commit

Permalink
Change ready signal to fire when cef calls OnAfterCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Oct 20, 2024
1 parent 7379df0 commit 0c29ef9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Packages/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,17 @@ public void Resize(Resolution newResolution)
logger.Debug($"Resized to {newResolution}.");
}

/// <summary>
/// Mutes browser audio
/// </summary>
/// <param name="muted"></param>
public void AudioMute(bool muted)
{
CheckIfIsReadyAndConnected();

communicationsManager.AudioMute(muted);
}

[DebuggerStepThrough]
private void CheckIfIsReadyAndConnected()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public void Resize(Resolution resolution)
ExecuteTask(() => engineProxy.Resize(resolution));
}

public void AudioMute(bool muted)
{
ExecuteTask(() => engineProxy.AudioMute(muted));
}

public void Connect()
{
ipcClient.Connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ public void Resize(Resolution resolution)
cefClient.Resize(resolution);
}

public void AudioMute(bool muted)
{
cefClient.AudioMute(muted);
}

#endregion

#region Destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void EntryPoint(LaunchArguments launchArguments, string[] arg
cefEngineControlsManager.Init(ClientControlsActions, PopupManager);

SetupIpc(cefEngineControlsManager, launchArguments);
Ready();
//Ready();

//Calling run message loop will cause the main thread to lock (what we want)
CefRuntime.RunMessageLoop();
Expand Down
7 changes: 7 additions & 0 deletions src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Extensions.Logging;
using UnityWebBrowser.Engine.Cef.Core;
using UnityWebBrowser.Engine.Cef.Shared.Browser.Js;
using UnityWebBrowser.Engine.Cef.Shared.Browser.Messages;
using UnityWebBrowser.Engine.Cef.Shared.Browser.Popups;
Expand Down Expand Up @@ -81,6 +82,7 @@ public UwbCefClient(
{
browser = cefBrowser;
browserHost = cefBrowser.GetHost();
ClientControls.Ready();
};
displayHandler = new UwbCefDisplayHandler(this, mainLogger, browserConsoleLogger);
requestHandler = new UwbCefRequestHandler(proxySettings, ignoreSslErrors, ignoreSslErrorsDomains);
Expand Down Expand Up @@ -414,6 +416,11 @@ public void Resize(Resolution resolution)
browserHost.WasResized();
}

public void AudioMute(bool muted)
{
browserHost.SetAudioMuted(muted);
}

#endregion

#region Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public sealed class UWBPrjDebugUI : MonoBehaviour

//Zoom
private double zoomLevel = double.MinValue;

//Audio
private bool audioMuted = false;

private void Awake()
{
Expand Down Expand Up @@ -134,7 +137,7 @@ private void OnClientConnected()

hasConnected = true;
}

private void Update()
{
if(webBrowserUIBasic.browserClient.HasDisposed || !hasConnected)
Expand Down Expand Up @@ -195,6 +198,11 @@ private void OnImGuiLayout(UImGui.UImGui uImGui)

//Buttons for getting details
{
if(ImGui.Checkbox("Audio Mute", ref audioMuted))
webBrowserUIBasic.browserClient.AudioMute(audioMuted);

ImGui.SameLine();

if (ImGui.Button("Get Scroll Pos"))
Debug.Log(webBrowserUIBasic.browserClient.GetScrollPosition());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,10 @@ internal interface IEngineControls
/// </summary>
/// <param name="resolution"></param>
public void Resize(Resolution resolution);

/// <summary>
/// Mutes browser audio
/// </summary>
/// <param name="muted"></param>
public void AudioMute(bool muted);
}

0 comments on commit 0c29ef9

Please sign in to comment.