Skip to content

Commit

Permalink
Merge branch 'feature/schedule-params-on-ui' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstonis committed Sep 18, 2023
2 parents cccd761 + 425159f commit ef8ecf5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
24 changes: 23 additions & 1 deletion Stellar.Maui/Extensions/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Splat;
using Splat.Microsoft.Extensions.DependencyInjection;

Expand All @@ -20,13 +22,33 @@ public static MauiAppBuilder UseStellarComponents<TStellarAssembly>(this MauiApp
PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Maui);
Locator.CurrentMutable.InitializeSplat();
Locator.CurrentMutable.InitializeReactiveUI();

RxApp.TaskpoolScheduler = Schedulers.ShortTermThreadPoolScheduler;

mauiAppBuilder.Services.AddSingleton(
serviceProvider =>
{
var dispatcher = serviceProvider.GetRequiredService<IDispatcher>();
var mauiScheduler = new MauiScheduler(dispatcher);
RxApp.MainThreadScheduler = mauiScheduler;
return mauiScheduler;
});

mauiAppBuilder.Services.TryAddEnumerable(ServiceDescriptor.Scoped<IMauiInitializeScopedService, MauiSchedulerInitializer>());

mauiAppBuilder.Services.ConfigureStellarComponents(typeof(TStellarAssembly).GetTypeInfo().Assembly);

return mauiAppBuilder;
}

private class MauiSchedulerInitializer : IMauiInitializeScopedService
{
public void Initialize(IServiceProvider services)
{
_ = services.GetRequiredService<MauiScheduler>();
}
}

public static MauiAppBuilder EnableHotReload(this MauiAppBuilder mauiAppBuilder)
{
HotReloadService.HotReloadAware = true;
Expand Down Expand Up @@ -65,4 +87,4 @@ private static Task PreCache(MauiAppBuilder mauiAppBuilder, Assembly assembly)
}
});
}
}
}
16 changes: 0 additions & 16 deletions Stellar.Maui/Extensions/MauiAppExtensions.cs

This file was deleted.

28 changes: 19 additions & 9 deletions Stellar.Maui/MauiScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Stellar.Maui;

public class MauiScheduler : IScheduler
{
private IDispatcher _dispatcher;
private readonly IDispatcher _dispatcher;

public MauiScheduler(IDispatcher dispatcher)
{
Expand All @@ -17,15 +17,25 @@ public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisp
{
var innerDisp = new SingleAssignmentDisposable();

_dispatcher
.Dispatch(
() =>
{
if (!innerDisp.IsDisposed)
if (_dispatcher.IsDispatchRequired)
{
_dispatcher
.Dispatch(
() =>
{
innerDisp.Disposable = action(this, state);
}
});
if (!innerDisp.IsDisposed)
{
innerDisp.Disposable = action(this, state);
}
});
}
else
{
if (!innerDisp.IsDisposed)
{
innerDisp.Disposable = action(this, state);
}
}

return innerDisp;
}
Expand Down
3 changes: 1 addition & 2 deletions Stellar.MauiSample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ We can add individual service registrations or all at once

return
appBuilder
.Build()
.ConfigureReactiveUISchedulers();
.Build();
}
}
7 changes: 5 additions & 2 deletions Stellar.MauiSample/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ namespace Stellar.MauiSample;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
protected override MauiApp CreateMauiApp()
{
return MauiProgram.CreateMauiApp();
}
}
2 changes: 1 addition & 1 deletion Stellar.MauiSample/Stellar.MauiSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="3.2.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="5.2.0" />
<PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.2.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit ef8ecf5

Please sign in to comment.