Skip to content

Commit b460892

Browse files
committed
Add readonly modifier
1 parent 6c3a829 commit b460892

36 files changed

+190
-156
lines changed

src/Bible.Alarm.Shared/Constants/AppConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public static class Platform
267267
/// <summary>
268268
/// iOS platform identifier
269269
/// </summary>
270-
public const string iOS = "iOS";
270+
public const string IOs = "iOS";
271271

272272
/// <summary>
273273
/// Windows platform identifier

src/Bible.Alarm.Shared/Utilities/DirectoryHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class DirectoryHelper
77
{
88
public static string IndexDirectory => indexDirectory.Value;
99

10-
private static Lazy<string> indexDirectory = new(() =>
10+
private static readonly Lazy<string> indexDirectory = new(() =>
1111
{
1212
var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
1313

src/Bible.Alarm/App.xaml.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using Bible.Alarm.Services.Contracts;
44
using Bible.Alarm.UI;
55
using Bible.Alarm.ViewModels;
6-
using Serilog;
7-
using Microsoft.Extensions.DependencyInjection;
86

97
namespace Bible.Alarm;
108

@@ -32,17 +30,9 @@ protected override Window CreateWindow(IActivationState? activationState)
3230
// Initialize platform-specific bootstrap helper after ServiceProviderManager is available
3331
InitializePlatformBootstrap();
3432

35-
// Create a simple window with a basic page for now
36-
var window = new Window(new ContentPage
37-
{
38-
Title = "Bible Alarm",
39-
Content = new Label
40-
{
41-
Text = "Bible Alarm is starting...",
42-
HorizontalOptions = LayoutOptions.Center,
43-
VerticalOptions = LayoutOptions.Center
44-
}
45-
});
33+
// Create a NavigationPage as the root page (proper MAUI pattern)
34+
var navigationPage = new NavigationPage();
35+
var window = new Window(navigationPage);
4636

4737
// Initialize services in background
4838
Task.Run(async () =>
@@ -51,13 +41,10 @@ protected override Window CreateWindow(IActivationState? activationState)
5141
{
5242
System.Diagnostics.Debug.WriteLine("Starting service initialization...");
5343

54-
// Create and store the navigation service for later use
44+
// Get navigation service from DI container
5545
using var scope = _scopeFactory.CreateScope();
56-
_navigationService = new NavigationService(
57-
scope.ServiceProvider.GetRequiredService<ILogger>(),
58-
null, // Will be set when we have proper navigation
59-
_scopeFactory);
60-
System.Diagnostics.Debug.WriteLine("NavigationService created!");
46+
_navigationService = scope.ServiceProvider.GetRequiredService<INavigationService>();
47+
System.Diagnostics.Debug.WriteLine("NavigationService retrieved from DI!");
6148

6249
// Initialize the home page
6350
await InitializeHomePage(window);
@@ -84,11 +71,22 @@ private async Task InitializeHomePage(Window window)
8471
System.Diagnostics.Debug.WriteLine("InitializeHomePage called!");
8572
using var scope = _scopeFactory.CreateScope();
8673
var homePage = new Home { BindingContext = scope.ServiceProvider.GetRequiredService<HomeViewModel>() };
87-
88-
// Set the main page to the home page
89-
window.Page = homePage;
90-
System.Diagnostics.Debug.WriteLine("Home page set!");
91-
74+
75+
// Get the NavigationPage from the window
76+
if (window.Page is NavigationPage navigationPage)
77+
{
78+
// Push the home page to the navigation stack
79+
await navigationPage.PushAsync(homePage);
80+
System.Diagnostics.Debug.WriteLine("Home page pushed to navigation stack!");
81+
82+
// Set the navigation instance for the NavigationService
83+
if (_navigationService != null)
84+
{
85+
_navigationService.SetNavigation(navigationPage.Navigation);
86+
System.Diagnostics.Debug.WriteLine("Navigation instance set!");
87+
}
88+
}
89+
9290
// Add a small delay to ensure proper initialization
9391
await Task.Delay(100);
9492
}

src/Bible.Alarm/Bible.Alarm.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<!-- Windows-specific -->
2323
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion>
2424
<UseWinUI>true</UseWinUI>
25+
26+
<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
27+
<WindowsPackageType>None</WindowsPackageType>
2528

2629
<!-- Suppress duplicate assembly attribute warnings -->
2730
<NoWarn>$(NoWarn);CS0579</NoWarn>

src/Bible.Alarm/Common/Helpers/CommonBootstrapHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace Bible.Alarm.Common.Helpers;
55

66
public static class CommonBootstrapHelper
77
{
8-
private static SemaphoreSlim @lock = new(1);
8+
private static readonly SemaphoreSlim Lock = new(1);
99

1010
public static async Task VerifyServices()
1111
{
12-
await @lock.WaitAsync();
12+
await Lock.WaitAsync();
1313

1414
try
1515
{
@@ -20,7 +20,7 @@ public static async Task VerifyServices()
2020
}
2121
finally
2222
{
23-
@lock.Release();
23+
Lock.Release();
2424
}
2525
}
2626

src/Bible.Alarm/Common/Mvvm/Commands/RelayCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RelayCommand(Action execute, Func<bool> canExecute = null) : IRelay
1313

1414
#region Fields
1515

16-
private Func<bool> _canExecute = canExecute ?? (() => true);
16+
private readonly Func<bool> _canExecute = canExecute ?? (() => true);
1717

1818
#endregion
1919

src/Bible.Alarm/Common/Mvvm/Commands/RelayCommand{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RelayCommand<T>(Action<T> execute, Func<T, bool> canExecute = null)
1313

1414
#region Fields
1515

16-
private Func<T, bool> _canExecute = canExecute ?? ((o) => true);
16+
private readonly Func<T, bool> _canExecute = canExecute ?? ((o) => true);
1717

1818
#endregion
1919

src/Bible.Alarm/Common/Mvvm/Messenger/Messenger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ private class MessageWrapper(T parameter)
2424
public T Parameter { get; private set; } = parameter;
2525
}
2626

27-
private static ConcurrentDictionary<MvvmMessages, BehaviorSubject<MessageWrapper>> cache = new();
27+
private static readonly ConcurrentDictionary<MvvmMessages, BehaviorSubject<MessageWrapper>> Cache = new();
2828

2929
public static void Publish(MvvmMessages stream, T parameter = default)
3030
{
31-
var subject = cache.GetOrAdd(stream, new BehaviorSubject<MessageWrapper>(null));
31+
var subject = Cache.GetOrAdd(stream, new BehaviorSubject<MessageWrapper>(null));
3232
subject.OnNext(new MessageWrapper(parameter));
3333
}
3434

3535
public static IDisposable Subscribe(MvvmMessages stream,
3636
Func<T, Task> action,
3737
bool getMostRecentEvent = false)
3838
{
39-
var subject = cache.GetOrAdd(stream, new BehaviorSubject<MessageWrapper>(null));
39+
var subject = Cache.GetOrAdd(stream, new BehaviorSubject<MessageWrapper>(null));
4040

4141
if (getMostRecentEvent)
4242
return subject.Where(x => x != null)

src/Bible.Alarm/Common/Mvvm/Observers/NotifyPropertyObserver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public NotifyPropertyObserver(TObservable observable, TObserver observer)
2727

2828
private bool _hasBeenActive;
2929

30-
private TObservable _observable;
30+
private readonly TObservable _observable;
3131

32-
private WeakReference<TObserver> _observer;
32+
private readonly WeakReference<TObserver> _observer;
3333

3434
private Dictionary<string, Action> _propertyObservers = [];
3535

src/Bible.Alarm/Common/ServiceProviderManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace Bible.Alarm;
66
/// </summary>
77
public static class ServiceProviderManager
88
{
9-
private static IServiceProvider _serviceProvider;
10-
private static readonly object _lock = new();
9+
private static IServiceProvider serviceProvider;
10+
private static readonly object Lock = new();
1111

1212
/// <summary>
1313
/// Gets the global service provider. Throws if not initialized.
@@ -16,10 +16,10 @@ public static IServiceProvider ServiceProvider
1616
{
1717
get
1818
{
19-
if (_serviceProvider == null)
19+
if (serviceProvider == null)
2020
throw new InvalidOperationException(
2121
"Service provider has not been initialized. Call Initialize() first.");
22-
return _serviceProvider;
22+
return serviceProvider;
2323
}
2424
}
2525

@@ -31,11 +31,11 @@ public static void Initialize(IServiceProvider serviceProvider)
3131
{
3232
if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider));
3333

34-
lock (_lock)
34+
lock (Lock)
3535
{
36-
if (_serviceProvider != null)
36+
if (ServiceProviderManager.serviceProvider != null)
3737
throw new InvalidOperationException("Service provider has already been initialized.");
38-
_serviceProvider = serviceProvider;
38+
ServiceProviderManager.serviceProvider = serviceProvider;
3939
}
4040
}
4141

@@ -62,5 +62,5 @@ public static object GetService(Type serviceType)
6262
/// <summary>
6363
/// Checks if the service provider has been initialized.
6464
/// </summary>
65-
public static bool IsInitialized => _serviceProvider != null;
65+
public static bool IsInitialized => serviceProvider != null;
6666
}

0 commit comments

Comments
 (0)