From 670c4a732fe01341ff7be0e5b6ac7f4930a33d1f Mon Sep 17 00:00:00 2001 From: bricefriha Date: Thu, 27 Aug 2026 18:28:53 +0100 Subject: [PATCH 1/4] prevent nallability of _sources --- App/ViewModels/NewsViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/App/ViewModels/NewsViewModel.cs b/App/ViewModels/NewsViewModel.cs index 6e71c16f..07ea5062 100644 --- a/App/ViewModels/NewsViewModel.cs +++ b/App/ViewModels/NewsViewModel.cs @@ -335,7 +335,7 @@ public bool IsSearchLoading } public bool IsLoadingChunks { get; private set; } - private List _sources; + private List _sources = []; public List Sources { @@ -797,8 +797,8 @@ public async Task Resume() else RefreshFeed.Execute(_isSearching); #endif - Sources = await _generalDB.GetSources(); } + Sources = await _generalDB.GetSources(); await FetchTrendingArticles(); From e3154925bb5459cfbbd68b169680d98959ff8e37 Mon Sep 17 00:00:00 2001 From: bricefriha Date: Thu, 27 Aug 2026 19:30:09 +0100 Subject: [PATCH 2/4] Settingup the instanceID in the datafetcher instead of the App class --- App/App.xaml.cs | 36 +----------------------------------- App/Services/Fetcher.cs | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/App/App.xaml.cs b/App/App.xaml.cs index b00dcf85..88a73019 100644 --- a/App/App.xaml.cs +++ b/App/App.xaml.cs @@ -39,7 +39,7 @@ public partial class App : Application public User SaveInfo { get; private set; } public Collection Partners { get; private set; } public Collection Deals { get; private set; } - public string InstanceID { get; set; } + /// /// Date first registered to determin when is the best time to ask for user review /// @@ -141,7 +141,6 @@ private async Task RecoverFromOffline() protected override void OnStart() { - SetupInstance().GetAwaiter(); Task.Run(RecoverFromOffline); @@ -316,39 +315,6 @@ await Snackbar.Make(message, actionButtonText: "contact support").Show(); } - /// - /// Setup the instance for a device - /// - /// a task returning the id of the instance - public async Task SetupInstance() - { - -#if IOS - string instanceID = await SecureStorage.Default.GetAsync(AppConstant.InstanceIdKey); - if (string.IsNullOrEmpty(instanceID)) - { - await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, instanceID = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.ToString().ToLower().Replace("-", string.Empty).Substring(0,30)); - - } - -#if DEBUG - Debug.WriteLine($"Instance: {instanceID}"); -#endif - return -#endif - InstanceID = -#if ANDROID - Secure.GetString(Android.App.Application.Context.ContentResolver, Secure.AndroidId); -#if DEBUG - Debug.WriteLine($"Instance: {InstanceID}"); -#endif - await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, InstanceID); - return InstanceID; -#elif IOS - instanceID; -#endif - - } /// /// Load all the partners /// diff --git a/App/Services/Fetcher.cs b/App/Services/Fetcher.cs index 4144d531..7ee949a2 100644 --- a/App/Services/Fetcher.cs +++ b/App/Services/Fetcher.cs @@ -8,6 +8,9 @@ using Plugin.FirebasePushNotifications; using System.Net.Sockets; +#if ANDROID +using static Android.Provider.Settings; +#endif #if IOS using Maui.RevenueCat.InAppBilling.Services; @@ -23,6 +26,8 @@ public class Fetcher public static string ProdHost { get; } = "api.gamhub.io"; private static string _dateFormat = "dd-MM-yyy_HH:mm:ss"; private Session CurrentSession { get; set; } + + public string InstanceID { get; set; } public Service WebService { get; private set; } public static Collection Sources { get; set; } @@ -1062,7 +1067,7 @@ private async Task> GetHeaders() if (string.IsNullOrEmpty(instanceID)) { // Reissue an instanceID - instanceID = await (App.Current as App).SetupInstance(); + instanceID = await SetupInstance(); } #if DEBUG Debug.WriteLine($"ApiKey: {apiKey}"); @@ -1087,6 +1092,40 @@ private async Task> GetHeaders() } /// + /// Setup the instance for a device + /// + /// a task returning the id of the instance + public async Task SetupInstance() + { + +#if IOS + string instanceID = await SecureStorage.Default.GetAsync(AppConstant.InstanceIdKey); + if (string.IsNullOrEmpty(instanceID)) + { + await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, instanceID = UIKit.UIDevice.CurrentDevice.IdentifierForVendor.ToString().ToLower().Replace("-", string.Empty).Substring(0,30)); + + } + +#if DEBUG + Debug.WriteLine($"Instance: {instanceID}"); +#endif + return +#endif + InstanceID = +#if ANDROID + Secure.GetString(Android.App.Application.Context.ContentResolver, Secure.AndroidId); +#if DEBUG + Debug.WriteLine($"Instance: {InstanceID}"); +#endif + await SecureStorage.Default.SetAsync(AppConstant.InstanceIdKey, InstanceID); + return InstanceID; +#elif IOS + instanceID; +#endif + } + + + /// /// Adding a hook to an article /// /// article hooked From 0a5072dfe30e48b3859247ecb5df037e40a2f6b8 Mon Sep 17 00:00:00 2001 From: bricefriha Date: Thu, 27 Aug 2026 19:32:38 +0100 Subject: [PATCH 3/4] Data fetcher | Initiate the data earlier --- App/Services/Fetcher.cs | 11 +++++++++-- App/ViewModels/AppShellViewModel.cs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/App/Services/Fetcher.cs b/App/Services/Fetcher.cs index 7ee949a2..5cc84626 100644 --- a/App/Services/Fetcher.cs +++ b/App/Services/Fetcher.cs @@ -75,12 +75,19 @@ Service wService _generalDB = generalDataBase; _backupDB = backUpDataBase; _firebasePushPermissions = notificationPermissions; + } - Task.WhenAll([ + /// + /// Initialised all the data needed to move forward + /// + /// + public async Task DataInit() + { + await Task.WhenAll([ GetSources(), SetCultureInfo(), GetDRMs() - ]).GetAwaiter(); + ]); } /// diff --git a/App/ViewModels/AppShellViewModel.cs b/App/ViewModels/AppShellViewModel.cs index ff4cac03..0b641ed4 100644 --- a/App/ViewModels/AppShellViewModel.cs +++ b/App/ViewModels/AppShellViewModel.cs @@ -156,6 +156,7 @@ public AppShellViewModel(Fetcher fetc, Task.Run(async () => { await Task.WhenAll( + dataFetcher.DataInit(), Task.Run(async () => { DonationEnabled = (await fetc.GetGlobalSettings())?.DonationEnabled ?? false; From 2efd448837169d2ef0b2e99522e11e084a006f12 Mon Sep 17 00:00:00 2001 From: bricefriha Date: Thu, 27 Aug 2026 19:38:13 +0100 Subject: [PATCH 4/4] Exception handling --- App/ViewModels/NewsViewModel.cs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/App/ViewModels/NewsViewModel.cs b/App/ViewModels/NewsViewModel.cs index 07ea5062..9260ca24 100644 --- a/App/ViewModels/NewsViewModel.cs +++ b/App/ViewModels/NewsViewModel.cs @@ -189,8 +189,10 @@ public ObservableRangeCollection
Articles { get { - ObservableRangeCollection
upArticles = new(); + ObservableRangeCollection
upArticles = []; + try + { for (int i = 0; i < _articles?.Count; i++) { var article = _articles[i]; @@ -199,6 +201,18 @@ public ObservableRangeCollection
Articles if (article.Source?.IsSelected ?? true) upArticles.Add(article); } + + } + + catch (Exception ex) + { +#if DEBUG + Debug.WriteLine(ex); + +#else + SentrySdk.CaptureException(ex); +#endif + } return upArticles; } set @@ -212,13 +226,15 @@ public ObservableRangeCollection
Articles SetProperty(ref _articles, value); } } - private ObservableCollection
_trendingArticles = new(); + private ObservableCollection
_trendingArticles = []; public ObservableCollection
TrendingArticles { get { - ObservableRangeCollection
upArticles = new(); + ObservableRangeCollection
upArticles = []; + try + { for (int i = 0; i < _trendingArticles?.Count; i++) { var article = _trendingArticles[i]; @@ -230,6 +246,16 @@ public ObservableCollection
TrendingArticles if (article.Source?.IsSelected ?? true) upArticles.Add(article); } + } + catch (Exception ex) + { +#if DEBUG + Debug.WriteLine(ex); + +#else + SentrySdk.CaptureException(ex); +#endif + } return upArticles; } set