feat: implement version check and update dialog; add browser cache clearing functionality
Build and Deploy / build (push) Successful in 1m40s

This commit is contained in:
masoodafar-web
2025-12-27 04:47:27 +03:30
parent 51129704a0
commit 9cd275a777
6 changed files with 510 additions and 46 deletions
@@ -16,11 +16,17 @@ public partial class MainLayout : IDisposable
private bool _isAuthenticated;
private string? _email;
private int _cartCount;
// متغیرهای بروزرسانی
private bool _hasUpdate;
private string? _newVersion;
private VersionCheckResult? _versionCheckResult;
[Inject] private ILocalStorageService LocalStorage { get; set; } = default!;
[Inject] private AuthService AuthService { get; set; } = default!;
[Inject] private AuthDialogService AuthDialogService { get; set; } = default!;
[Inject] private CartService CartService { get; set; } = default!;
[Inject] private AppVersionService AppVersionService { get; set; } = default!;
private void ToggleTheme() => _isDark = !_isDark;
private void ToggleDrawer() => _drawerOpen = !_drawerOpen;
@@ -42,12 +48,83 @@ public partial class MainLayout : IDisposable
await CartService.EnsureInitializedAsync();
CartService.OnChange += OnCartChanged;
_cartCount = CartService.Count;
// چک کردن بروزرسانی (بدون نمایش popup - فقط برای نشون دادن آیکون)
await CheckForUpdateSilentlyAsync();
}
StateHasChanged();
}
}
/// <summary>
/// چک کردن بروزرسانی بدون نمایش popup
/// </summary>
private async Task CheckForUpdateSilentlyAsync()
{
try
{
_versionCheckResult = await AppVersionService.CheckVersionAsync(ignoreSkipped: true);
if (_versionCheckResult.HasNewVersion && !string.IsNullOrEmpty(_versionCheckResult.NewVersion))
{
_hasUpdate = true;
_newVersion = _versionCheckResult.NewVersion;
}
}
catch
{
// در صورت خطا نادیده بگیر
}
}
/// <summary>
/// باز کردن دیالوگ بروزرسانی
/// </summary>
private async Task OpenUpdateDialog()
{
if (_versionCheckResult == null || string.IsNullOrEmpty(_versionCheckResult.NewVersion))
return;
// ثبت زمان نمایش دیالوگ
await AppVersionService.RecordDialogShownAsync();
var dialogOptions = new DialogOptions
{
BackdropClick = !_versionCheckResult.IsForceUpdate,
CloseOnEscapeKey = !_versionCheckResult.IsForceUpdate,
CloseButton = !_versionCheckResult.IsForceUpdate,
MaxWidth = MaxWidth.Small,
FullWidth = true
};
var parameters = new DialogParameters<ReleaseNotesDialog>
{
{ x => x.OldVersion, _versionCheckResult.OldVersion },
{ x => x.NewVersion, _versionCheckResult.NewVersion },
{ x => x.ReleaseNotes, _versionCheckResult.ReleaseNotes },
{ x => x.UpdateMessage, _versionCheckResult.UpdateMessage },
{ x => x.IsForceUpdate, _versionCheckResult.IsForceUpdate }
};
var dialog = await DialogService.ShowAsync<ReleaseNotesDialog>("بروزرسانی", parameters, dialogOptions);
var result = await dialog.Result;
if (result is { Canceled: false, Data: bool shouldUpdate })
{
if (shouldUpdate)
{
await AppVersionService.ApplyUpdateAsync(_versionCheckResult.NewVersion);
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
}
else
{
await AppVersionService.SkipVersionAsync(_versionCheckResult.NewVersion);
// نمایش آپدیت همچنان باقی بمونه (hasUpdate true بمونه)
}
}
}
private void OnCartChanged()
{
_cartCount = CartService.Count;