From ded97b54ef2bcd5d21a549156aad9788b4f644fe Mon Sep 17 00:00:00 2001
From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com>
Date: Mon, 2 Sep 2024 09:13:03 +0200
Subject: [PATCH] best practise corrections
---
AudioCuesheetEditor/Pages/Index.razor | 12 ++++++----
AudioCuesheetEditor/Pages/RecordControl.razor | 9 ++++---
AudioCuesheetEditor/Shared/AudioPlayer.razor | 24 ++++++++++---------
.../Shared/EditTrackModal.razor | 10 ++++----
AudioCuesheetEditor/Shared/MainLayout.razor | 9 ++++---
AudioCuesheetEditor/Shared/ModalDialog.razor | 10 ++++----
.../Shared/ModalExportdialog.razor | 9 ++++---
.../Shared/OptionsDialog.razor | 10 ++++----
8 files changed, 56 insertions(+), 37 deletions(-)
diff --git a/AudioCuesheetEditor/Pages/Index.razor b/AudioCuesheetEditor/Pages/Index.razor
index d3e38b67..b9d76fc5 100644
--- a/AudioCuesheetEditor/Pages/Index.razor
+++ b/AudioCuesheetEditor/Pages/Index.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@page "/"
@inject IJSRuntime _jsRuntime
@@ -78,12 +77,15 @@ along with Foobar. If not, see
@code {
-
- public void Dispose()
+
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_sessionStateContainer.CurrentViewModeChanged -= CurrentViewModeChanged;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
[CascadingParameter]
diff --git a/AudioCuesheetEditor/Pages/RecordControl.razor b/AudioCuesheetEditor/Pages/RecordControl.razor
index c4260bea..a167e0fd 100644
--- a/AudioCuesheetEditor/Pages/RecordControl.razor
+++ b/AudioCuesheetEditor/Pages/RecordControl.razor
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-@implements IDisposable
+@implements IAsyncDisposable
@inject SessionStateContainer _sessionStateContainer
@inject ITextLocalizer _localizer
@@ -131,12 +131,15 @@ along with Foobar. If not, see
[Parameter]
public EventCallback StopRecordClicked { get; set; }
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionsSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override async Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/AudioPlayer.razor b/AudioCuesheetEditor/Shared/AudioPlayer.razor
index 5d0ca5eb..ee987d0e 100644
--- a/AudioCuesheetEditor/Shared/AudioPlayer.razor
+++ b/AudioCuesheetEditor/Shared/AudioPlayer.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject IHowl _howl
@@ -77,7 +76,7 @@ along with Foobar. If not, see
@code {
- Timer audioUpdateTimer = default!;
+ Timer? audioUpdateTimer;
int soundId;
Track? currentlyPlayingTrack;
HotKeysContext? hotKeysContext;
@@ -92,20 +91,23 @@ along with Foobar. If not, see
public TimeSpan? TotalTime { get; private set; }
public Boolean AudioIsPlaying { get; private set; }
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_howl.OnPlay -= HowlOnPlay;
_howl.OnPause -= HowlOnPause;
_howl.OnEnd -= HowlOnEnd;
_howl.OnStop -= HowlOnStop;
- audioUpdateTimer.Dispose();
+ _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
+ _sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
if (_sessionStateContainer.Cuesheet != null)
{
_sessionStateContainer.Cuesheet.AudioFileChanged -= Cuesheet_AudioFileChanged;
}
- _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
- _sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged;
+ audioUpdateTimer?.Dispose();
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public Boolean PlaybackPossible
@@ -242,7 +244,7 @@ along with Foobar. If not, see
void HowlOnPlay(Howler.Blazor.Components.Events.HowlPlayEventArgs args)
{
paused = false;
- audioUpdateTimer.Start();
+ audioUpdateTimer?.Start();
}
void HowlOnPause(Howler.Blazor.Components.Events.HowlEventArgs args)
@@ -253,7 +255,7 @@ along with Foobar. If not, see
void HowlOnEnd(Howler.Blazor.Components.Events.HowlEventArgs args)
{
paused = false;
- audioUpdateTimer.Stop();
+ audioUpdateTimer?.Stop();
CurrentlyPlayingTrack = null;
CurrentPlaybackPosition = null;
AudioIsPlaying = false;
@@ -263,7 +265,7 @@ along with Foobar. If not, see
void HowlOnStop(Howler.Blazor.Components.Events.HowlEventArgs args)
{
paused = false;
- audioUpdateTimer.Stop();
+ audioUpdateTimer?.Stop();
CurrentlyPlayingTrack = null;
CurrentPlaybackPosition = null;
AudioIsPlaying = false;
diff --git a/AudioCuesheetEditor/Shared/EditTrackModal.razor b/AudioCuesheetEditor/Shared/EditTrackModal.razor
index 1829e4ee..84f5e846 100644
--- a/AudioCuesheetEditor/Shared/EditTrackModal.razor
+++ b/AudioCuesheetEditor/Shared/EditTrackModal.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject MusicBrainzDataProvider _musicBrainzDataProvider
@@ -420,10 +419,13 @@ along with Foobar. If not, see
Validations? validations;
ApplicationOptions? applicationOptions;
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override async Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/MainLayout.razor b/AudioCuesheetEditor/Shared/MainLayout.razor
index 7fc6d42d..ea35a241 100644
--- a/AudioCuesheetEditor/Shared/MainLayout.razor
+++ b/AudioCuesheetEditor/Shared/MainLayout.razor
@@ -18,7 +18,7 @@ along with Foobar. If not, see
@inherits LayoutComponentBase
-@implements IDisposable
+@implements IAsyncDisposable
@inject NavigationManager _navigationManager
@inject ITextLocalizer _localizer
@@ -484,9 +484,8 @@ along with Foobar. If not, see
await base.OnInitializedAsync();
}
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
_traceChangeManager.TracedObjectHistoryChanged -= TraceChangeManager_TracedObjectHistoryChanged;
@@ -500,6 +499,10 @@ along with Foobar. If not, see
{
modalExportdialogCuesheet.GenerateExportfilesClicked -= ModalExportdialogCuesheet_GenerateExportfilesClicked;
}
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public void SetDisplayMenuBar(Boolean display)
diff --git a/AudioCuesheetEditor/Shared/ModalDialog.razor b/AudioCuesheetEditor/Shared/ModalDialog.razor
index c19fc165..8355b413 100644
--- a/AudioCuesheetEditor/Shared/ModalDialog.razor
+++ b/AudioCuesheetEditor/Shared/ModalDialog.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject HotKeys _hotKeys
@@ -65,10 +64,13 @@ along with Foobar. If not, see
@code {
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
protected override Task OnInitializedAsync()
diff --git a/AudioCuesheetEditor/Shared/ModalExportdialog.razor b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
index 271cb00c..fd83b9df 100644
--- a/AudioCuesheetEditor/Shared/ModalExportdialog.razor
+++ b/AudioCuesheetEditor/Shared/ModalExportdialog.razor
@@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-@implements IDisposable
+@implements IAsyncDisposable
@inject ITextLocalizer _localizer
@inject ILogger _logger
@@ -198,10 +198,13 @@ along with Foobar. If not, see
await base.OnInitializedAsync();
}
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public async Task Show()
diff --git a/AudioCuesheetEditor/Shared/OptionsDialog.razor b/AudioCuesheetEditor/Shared/OptionsDialog.razor
index fa7ea1bc..a0491b87 100644
--- a/AudioCuesheetEditor/Shared/OptionsDialog.razor
+++ b/AudioCuesheetEditor/Shared/OptionsDialog.razor
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with Foobar. If not, see
.
-->
-
-@implements IDisposable
+@implements IAsyncDisposable
@inject ILocalStorageOptionsProvider _localStorageOptionsProvider
@inject ITextLocalizer _localizer
@@ -159,11 +158,14 @@ along with Foobar. If not, see
HotKeysContext? hotKeysContext;
Validation? timespanformatValidation;
- public void Dispose()
+ public async ValueTask DisposeAsync()
{
- hotKeysContext?.Dispose();
_localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged;
_localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionSaved;
+ if (hotKeysContext != null)
+ {
+ await hotKeysContext.DisposeAsync();
+ }
}
public async Task Show()