feat: implement version check and update dialog; add browser cache clearing functionality
Build and Deploy / build (push) Successful in 1m40s
Build and Deploy / build (push) Successful in 1m40s
This commit is contained in:
@@ -17,8 +17,8 @@ public partial class App
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
// Check app version and clear cache if needed
|
||||
await AppVersionService.CheckVersionAndClearCacheIfNeededAsync();
|
||||
// Check app version and show update dialog if needed
|
||||
await CheckAndShowVersionUpdateAsync();
|
||||
|
||||
// Check for referral code in URL query parameters
|
||||
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
||||
@@ -58,5 +58,77 @@ public partial class App
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// بررسی نسخه و نمایش دیالوگ آپدیت در صورت نیاز
|
||||
/// فقط برای کاربران لاگین شده
|
||||
/// </summary>
|
||||
private async Task CheckAndShowVersionUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// فقط برای کاربران لاگین شده
|
||||
if (!await AuthService.IsAuthenticatedAsync())
|
||||
return;
|
||||
|
||||
// forDialog: true یعنی اگه skip کرده ولی یک روز گذشته، دوباره نشون بده
|
||||
var versionCheck = await AppVersionService.CheckVersionAsync(forDialog: true);
|
||||
|
||||
if (!versionCheck.HasNewVersion || string.IsNullOrEmpty(versionCheck.NewVersion))
|
||||
return;
|
||||
|
||||
// ثبت زمان نمایش دیالوگ
|
||||
await AppVersionService.RecordDialogShownAsync();
|
||||
|
||||
// تنظیمات دیالوگ
|
||||
var dialogOptions = new DialogOptions
|
||||
{
|
||||
BackdropClick = !versionCheck.IsForceUpdate, // اگر force باشه نتونه بیرون کلیک کنه
|
||||
CloseOnEscapeKey = !versionCheck.IsForceUpdate,
|
||||
CloseButton = !versionCheck.IsForceUpdate,
|
||||
MaxWidth = MaxWidth.Small,
|
||||
FullWidth = true
|
||||
};
|
||||
|
||||
var parameters = new DialogParameters<ReleaseNotesDialog>
|
||||
{
|
||||
{ x => x.OldVersion, versionCheck.OldVersion },
|
||||
{ x => x.NewVersion, versionCheck.NewVersion },
|
||||
{ x => x.ReleaseNotes, versionCheck.ReleaseNotes },
|
||||
{ x => x.UpdateMessage, versionCheck.UpdateMessage },
|
||||
{ x => x.IsForceUpdate, versionCheck.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(versionCheck.NewVersion);
|
||||
|
||||
// رفرش صفحه
|
||||
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// کاربر گفت بعداً (فقط وقتی force نیست)
|
||||
await AppVersionService.SkipVersionAsync(versionCheck.NewVersion);
|
||||
}
|
||||
}
|
||||
else if (versionCheck.IsForceUpdate)
|
||||
{
|
||||
// اگر force بود و دیالوگ بسته شد، باز هم آپدیت کن
|
||||
await AppVersionService.ApplyUpdateAsync(versionCheck.NewVersion);
|
||||
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// در صورت خطا، لاگ کن ولی ادامه بده
|
||||
Console.WriteLine($"Error checking version: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user