diff --git a/sandbox/AvaloniaApplication1/Program.cs b/sandbox/AvaloniaApplication1/Program.cs index 46bcce9a..1b7bfcc2 100644 --- a/sandbox/AvaloniaApplication1/Program.cs +++ b/sandbox/AvaloniaApplication1/Program.cs @@ -19,5 +19,5 @@ public static AppBuilder BuildAvaloniaApp() .UsePlatformDetect() .WithInterFont() .LogToTrace() - .UseR3(ex => Logger.Sink?.Log(LogEventLevel.Error, "R3", null, "R3 Unhandled Exception {0}", ex)); // add this line + .UseR3(); // add this line } diff --git a/src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs b/src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs index bc6f1804..18e45899 100644 --- a/src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs +++ b/src/R3.Avalonia/AppBuilderR3InitializeExtensions.cs @@ -5,24 +5,29 @@ namespace Avalonia; // Avalonia namespace public static class AppBuilderR3InitializeExtensions { - public static AppBuilder UseR3(this AppBuilder builder, Action unhandledExceptionHandler) + public static AppBuilder UseR3(this AppBuilder builder) { // need to delay setup, initialize provider(dispatcher) need to determine platform + return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem()); + } + + public static AppBuilder UseR3(this AppBuilder builder, Action unhandledExceptionHandler) + { return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler)); } public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, Action unhandledExceptionHandler) { - return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority)); + return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, priority)); } public static AppBuilder UseR3(this AppBuilder builder, int framesPerSecond, Action unhandledExceptionHandler) { - return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,framesPerSecond)); + return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, framesPerSecond)); } public static AppBuilder UseR3(this AppBuilder builder, DispatcherPriority priority, int framesPerSecond, Action unhandledExceptionHandler) { - return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler,priority, framesPerSecond)); + return builder.AfterSetup(_ => AvaloniaProviderInitializer.SetDefaultObservableSystem(unhandledExceptionHandler, priority, framesPerSecond)); } } diff --git a/src/R3.Avalonia/AvaloniaProviderInitializer.cs b/src/R3.Avalonia/AvaloniaProviderInitializer.cs index 92470e4f..af27cac3 100644 --- a/src/R3.Avalonia/AvaloniaProviderInitializer.cs +++ b/src/R3.Avalonia/AvaloniaProviderInitializer.cs @@ -1,9 +1,15 @@ -using Avalonia.Threading; +using Avalonia.Logging; +using Avalonia.Threading; namespace R3.Avalonia; public static class AvaloniaProviderInitializer { + public static void SetDefaultObservableSystem() + { + SetDefaultObservableSystem(ex => Logger.Sink?.Log(LogEventLevel.Error, "R3", null, "R3 Unhandled Exception {0}", ex)); + } + public static void SetDefaultObservableSystem(Action unhandledExceptionHandler) { ObservableSystem.RegisterUnhandledExceptionHandler(unhandledExceptionHandler);