mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 21:59:48 +00:00
Add periodic UI refresh using a timer and ensure proper disposal when closing the dialog
This commit is contained in:
parent
6c1981ebd3
commit
8f5010dfda
@ -5,6 +5,8 @@ using AIStudio.Settings.DataModel;
|
|||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
namespace AIStudio.Dialogs;
|
namespace AIStudio.Dialogs;
|
||||||
|
|
||||||
public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncDisposable
|
public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncDisposable
|
||||||
@ -17,6 +19,11 @@ public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncD
|
|||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
private SettingsManager SettingsManager { get; init; } = null!;
|
private SettingsManager SettingsManager { get; init; } = null!;
|
||||||
|
|
||||||
|
private readonly Timer refreshTimer = new(TimeSpan.FromSeconds(1.6))
|
||||||
|
{
|
||||||
|
AutoReset = true,
|
||||||
|
};
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
@ -26,8 +33,12 @@ public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncD
|
|||||||
this.directoryInfo = new DirectoryInfo(this.DataSource.Path);
|
this.directoryInfo = new DirectoryInfo(this.DataSource.Path);
|
||||||
|
|
||||||
if (this.directoryInfo.Exists)
|
if (this.directoryInfo.Exists)
|
||||||
|
{
|
||||||
this.directorySizeTask = this.directoryInfo.DetermineContentSize(this.UpdateDirectorySize, this.UpdateDirectoryFiles, this.UpdateFileList, MAX_FILES_TO_SHOW, this.DirectoryOperationDone, this.cts.Token);
|
this.directorySizeTask = this.directoryInfo.DetermineContentSize(this.UpdateDirectorySize, this.UpdateDirectoryFiles, this.UpdateFileList, MAX_FILES_TO_SHOW, this.DirectoryOperationDone, this.cts.Token);
|
||||||
|
this.refreshTimer.Elapsed += (_, _) => this.InvokeAsync(this.StateHasChanged);
|
||||||
|
this.refreshTimer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,19 +65,18 @@ public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncD
|
|||||||
{
|
{
|
||||||
this.directoryFiles.Append("- ");
|
this.directoryFiles.Append("- ");
|
||||||
this.directoryFiles.AppendLine(file);
|
this.directoryFiles.AppendLine(file);
|
||||||
this.InvokeAsync(this.StateHasChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDirectorySize(long size)
|
private void UpdateDirectorySize(long size)
|
||||||
{
|
{
|
||||||
this.directorySizeBytes = size;
|
this.directorySizeBytes = size;
|
||||||
this.InvokeAsync(this.StateHasChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateDirectoryFiles(long numFiles) => this.directorySizeNumFiles = numFiles;
|
private void UpdateDirectoryFiles(long numFiles) => this.directorySizeNumFiles = numFiles;
|
||||||
|
|
||||||
private void DirectoryOperationDone()
|
private void DirectoryOperationDone()
|
||||||
{
|
{
|
||||||
|
this.refreshTimer.Stop();
|
||||||
this.IsOperationInProgress = false;
|
this.IsOperationInProgress = false;
|
||||||
this.InvokeAsync(this.StateHasChanged);
|
this.InvokeAsync(this.StateHasChanged);
|
||||||
}
|
}
|
||||||
@ -89,6 +99,8 @@ public partial class DataSourceLocalDirectoryInfoDialog : ComponentBase, IAsyncD
|
|||||||
await this.directorySizeTask;
|
await this.directorySizeTask;
|
||||||
|
|
||||||
this.cts.Dispose();
|
this.cts.Dispose();
|
||||||
|
this.refreshTimer.Stop();
|
||||||
|
this.refreshTimer.Dispose();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user