Skip to content

Commit

Permalink
SetDefaultObservableSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 6, 2024
1 parent 88bc5bd commit c191b11
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion sandbox/AvaloniaApplication1/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Logging;
using R3;
using System;
using System.Diagnostics;
Expand All @@ -15,7 +16,7 @@ public MainWindow()







Expand Down
3 changes: 2 additions & 1 deletion sandbox/AvaloniaApplication1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia;
using Avalonia.Logging;
using System;

namespace AvaloniaApplication1;
Expand All @@ -18,5 +19,5 @@ public static AppBuilder BuildAvaloniaApp()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseR3(); // add this line
.UseR3(ex => Logger.Sink?.Log(LogEventLevel.Error, "R3", null, "R3 Unhandled Exception {0}", ex)); // add this line
}
2 changes: 1 addition & 1 deletion sandbox/WpfApp1/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MainWindow()



R3.WPF.WpfProviderInitializer.SetDefaultProviders();
R3.WPF.WpfProviderInitializer.SetDefaultObservableSystem(ex => Trace.WriteLine($"R3 UnhandledException:{ex}"));



Expand Down
16 changes: 8 additions & 8 deletions src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ namespace Avalonia; // Avalonia namespace

public static class AppBuilderR3InitializeExtensions
{
public static AppBuilder UseR3(this AppBuilder builder)
public static AppBuilder UseR3(this AppBuilder builder, Action<Exception> unhandledExceptionHandler)
{
// need to delay setup, initialize provider(dispatcher) need to determine platform
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultProviders());
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler));
}

public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority)
public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultProviders(priority));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority));
}

public static AppBuilder UseR3(this AppBuilder builder, int framesPerSecond)
public static AppBuilder UseR3(this AppBuilder builder, int framesPerSecond, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultProviders(framesPerSecond));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,framesPerSecond));
}

public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, int framesPerSecond)
public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, int framesPerSecond, Action<Exception> unhandledExceptionHandler)
{
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultProviders(priority, framesPerSecond));
return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority, framesPerSecond));
}
}
12 changes: 8 additions & 4 deletions src/R3.Avalonia/AvaloniaProviderInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ namespace R3.Avalonia;

public static class AvaloniaProviderInitializer
{
public static void SetDefaultProviders()
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new AvaloniaDispatcherTimerProvider();
ObservableSystem.DefaultFrameProvider = new AvaloniaDispatcherFrameProvider();
}

public static void SetDefaultProviders(DispatcherPriority priority)
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler, DispatcherPriority priority)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new AvaloniaDispatcherTimerProvider(priority);
ObservableSystem.DefaultFrameProvider = new AvaloniaDispatcherFrameProvider(priority);
}

public static void SetDefaultProviders(int framesPerSecond)
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler, int framesPerSecond)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new AvaloniaDispatcherTimerProvider();
ObservableSystem.DefaultFrameProvider = new AvaloniaDispatcherFrameProvider(framesPerSecond);
}

public static void SetDefaultProviders(DispatcherPriority priority, int framesPerSecond)
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler, DispatcherPriority priority, int framesPerSecond)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new AvaloniaDispatcherTimerProvider(priority);
ObservableSystem.DefaultFrameProvider = new AvaloniaDispatcherFrameProvider(framesPerSecond, priority);
}
Expand Down
12 changes: 8 additions & 4 deletions src/R3.WPF/WpfProviderInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
using System.Windows.Threading;
using System.Windows;
using System.Windows.Threading;

namespace R3.WPF;

public static class WpfProviderInitializer
{
public static void SetDefaultProviders()
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider();
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider();
}

public static void SetDefaultProviders(DispatcherPriority priority)
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler, DispatcherPriority priority)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider(priority);
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider();
}

public static void SetDefaultProviders(DispatcherPriority priority, Dispatcher dispatcher)
public static void SetDefaultObservableSystem(Action<Exception> unhandledExceptionHandler, DispatcherPriority priority, Dispatcher dispatcher)
{
ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);
ObservableSystem.DefaultTimeProvider = new WpfDispatcherTimerProvider(priority, dispatcher);
ObservableSystem.DefaultFrameProvider = new WpfRenderingFrameProvider();
}
Expand Down

0 comments on commit c191b11

Please sign in to comment.