Skip to content

Commit

Permalink
Fix WASM UI audio toggle regression bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
highbyte committed Oct 1, 2024
1 parent cd42e01 commit e1ac801
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/apps/Highbyte.DotNet6502.App.WASM/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@

<label for="audioEnabled">Audio enabled (experimental)</label>
@* <input id="audioEnabled" type="checkbox" @bind="@IsAudioEnabled()" disabled=@AudioEnabledToggleDisabled() /> *@
<input id="audioEnabled" type="checkbox" value="@IsAudioEnabled()" onchange="@((bool e) => SetAudioEnabled(e))" disabled=@AudioEnabledToggleDisabled() />
@* <input id="audioEnabled" type="checkbox" value="@IsAudioEnabled()" onchange="@(async (bool e) => await SetAudioEnabled(e))" disabled=@AudioEnabledToggleDisabled().Result /> *@
@* <input id="audioEnabled" type="checkbox" value="@IsAudioEnabled()" onchange="@(async (ChangeEventArgs e) => await SetAudioEnabled(e))" disabled=@AudioEnabledToggleDisabled().Result /> *@
<InputCheckbox id="audioEnabled" @bind-Value:get="this.IsAudioEnabled().Result" @bind-Value:set="(async (bool e) => await SetAudioEnabled(e))" disabled=@AudioEnabledToggleDisabled().Result />

<div class="audioVolumeStyle">
Volume:
Expand Down
51 changes: 27 additions & 24 deletions src/apps/Highbyte.DotNet6502.App.WASM/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ private async Task<bool> AudioEnabledToggleDisabled()
{
if (_wasmHost == null)
return true;
var audioSuppoted = await _wasmHost.IsAudioSupported();
return (!audioSuppoted) ||
(CurrentEmulatorState == EmulatorState.Running || CurrentEmulatorState == EmulatorState.Paused);
var audioSupported = await _wasmHost.IsAudioSupported();
var audioToggleDisabled = !audioSupported || CurrentEmulatorState == EmulatorState.Running || CurrentEmulatorState == EmulatorState.Paused;
return audioToggleDisabled;
}

private async Task<bool> IsAudioEnabled()
Expand All @@ -53,10 +53,13 @@ private async Task<bool> IsAudioEnabled()
return false;
return await _wasmHost.IsAudioEnabled();
}

private async Task SetAudioEnabled(bool enabled)
{
if (_wasmHost != null)
await _wasmHost.SetAudioEnabled(enabled);
if (_wasmHost == null)
return;
await _wasmHost.SetAudioEnabled(enabled);
await this.StateHasChangedCustom();
}

private float _masterVolumePercent = 10.0f;
Expand Down Expand Up @@ -190,7 +193,7 @@ protected override async Task OnInitializedAsync()
Initialized = true;
}

private new async Task StateHasChanged()
private async Task StateHasChangedCustom()
{
await SetElementVisibleState();

Expand Down Expand Up @@ -269,7 +272,7 @@ private async Task SelectSystem(string systemName)
await Task.CompletedTask;
await Task.Yield();

await this.StateHasChanged();
await this.StateHasChangedCustom();
}

private async Task SelectedSystemChanged(string systemName)
Expand All @@ -295,7 +298,7 @@ private async Task SelectSystemConfigurationVariantChanged(string systemConfigur

await UpdateCanvasSize();

await this.StateHasChanged();
await this.StateHasChangedCustom();
}

private async Task UpdateCanvasSize()
Expand All @@ -315,7 +318,7 @@ private async Task UpdateCanvasSize()
_windowHeightStyle = $"{screen.VisibleHeight * Scale}px";
}

await this.StateHasChanged();
await this.StateHasChangedCustom();
}

private async Task SetConfigValidationMessage()
Expand Down Expand Up @@ -403,7 +406,7 @@ public async Task ShowConfigUI<T>() where T : IComponent

await SetConfigValidationMessage();
await UpdateCanvasSize();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}


Expand Down Expand Up @@ -441,38 +444,38 @@ public async Task SetDebugState(bool visible)
{
_debugVisible = visible;
await FocusEmulator();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
public async Task ToggleDebugState()
{
_debugVisible = !_debugVisible;
await FocusEmulator();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
public async Task UpdateDebug(string debug)
public void UpdateDebug(string debug)
{
_debugString = debug;
await this.StateHasChanged();
this.StateHasChanged();
}

public async Task SetStatsState(bool visible)
{
_statsVisible = visible;
await FocusEmulator();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
public async Task ToggleStatsState()
{
_statsVisible = !_statsVisible;
// Assume to only run when emulator is running
_wasmHost.CurrentRunningSystem!.InstrumentationEnabled = _statsVisible;
await FocusEmulator();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
public async Task UpdateStats(string stats)
public void UpdateStats(string stats)
{
_statsString = stats;
await this.StateHasChanged();
this.StateHasChanged();
}

public async Task SetMonitorState(bool visible)
Expand All @@ -482,7 +485,7 @@ public async Task SetMonitorState(bool visible)
await FocusMonitor();
else
await FocusEmulator();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}

//private void BeforeUnload_BeforeUnloadHandler(object? sender, blazejewicz.Blazor.BeforeUnload.BeforeUnloadArgs e)
Expand Down Expand Up @@ -586,29 +589,29 @@ public async Task OnStart(MouseEventArgs mouseEventArgs)

await FocusEmulator();

await this.StateHasChanged();
await this.StateHasChangedCustom();
}

public async Task OnPause(MouseEventArgs mouseEventArgs)
{
_wasmHost!.Pause();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}

public async Task OnReset(MouseEventArgs mouseEventArgs)
{
await _wasmHost!.Reset();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
public async Task OnStop(MouseEventArgs mouseEventArgs)
{
_wasmHost!.Stop();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}
private async Task OnMonitorToggle(MouseEventArgs mouseEventArgs)
{
_wasmHost!.ToggleMonitor();
await this.StateHasChanged();
await this.StateHasChangedCustom();
}

private async Task OnStatsToggle(MouseEventArgs mouseEventArgs)
Expand Down

0 comments on commit e1ac801

Please sign in to comment.