diff --git a/src/FrontOffice.Main/App.razor.cs b/src/FrontOffice.Main/App.razor.cs
index 4b99d91..c638ac6 100644
--- a/src/FrontOffice.Main/App.razor.cs
+++ b/src/FrontOffice.Main/App.razor.cs
@@ -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
}
}
}
-}
+ ///
+ /// بررسی نسخه و نمایش دیالوگ آپدیت در صورت نیاز
+ /// فقط برای کاربران لاگین شده
+ ///
+ 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
+ {
+ { 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("بروزرسانی", 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}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/FrontOffice.Main/Pages/_Host.cshtml b/src/FrontOffice.Main/Pages/_Host.cshtml
index f99261c..6925fc6 100644
--- a/src/FrontOffice.Main/Pages/_Host.cshtml
+++ b/src/FrontOffice.Main/Pages/_Host.cshtml
@@ -106,6 +106,29 @@
// اجرای اولیه (حتی اگر کاربر اسکرول نکرده)
requestAnimationFrame(update);
}
+
+ // پاک کردن کش مرورگر (Cache Storage و Service Worker)
+ window.clearBrowserCache = async function() {
+ // پاک کردن Cache Storage (Service Worker cache)
+ if ('caches' in window) {
+ const cacheNames = await caches.keys();
+ await Promise.all(
+ cacheNames.map(cacheName => caches.delete(cacheName))
+ );
+ console.log('Cache Storage cleared:', cacheNames.length, 'caches deleted');
+ }
+
+ // پاک کردن Service Worker registration
+ if ('serviceWorker' in navigator) {
+ const registrations = await navigator.serviceWorker.getRegistrations();
+ await Promise.all(
+ registrations.map(registration => registration.unregister())
+ );
+ console.log('Service Workers unregistered:', registrations.length);
+ }
+
+ return true;
+ };