AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.17k stars 2.27k forks source link

AfterPlatformServicesSetup callbacks are called by AfterApplicationSetupCallback #17675

Closed gentledepp closed 16 hours ago

gentledepp commented 19 hours ago

Describe the bug

When registering an AfterPlatformServicesSetup, it is invoked 2 times

  1. when the method SetupUnsafe calls the AfterPlatformServicesSetup
  2. when the method SetupUnsafe calls AfterApplicationSetupCallback

This is because there is a copy&paste-is issue in AppBuilder: The AfterApplicationSetupCallback is combined with the AfterPlatformServicesSetupCallback


        [PrivateApi]
        public AppBuilder AfterApplicationSetup(Action<AppBuilder> callback)
        {
-            AfterApplicationSetupCallback = (Action<AppBuilder>)Delegate.Combine(AfterPlatformServicesSetupCallback, callback);
+           AfterApplicationSetupCallback = (Action<AppBuilder>)Delegate.Combine(AfterApplicationSetupCallback , callback);
            return Self;
        }

To Reproduce

Register an AfterPlatformSericesSetup callback. On the Platforms Browser and Android, they will get called twice

  1. when the method SetupUnsafe calls the AfterPlatformServicesSetup
  2. when the method SetupUnsafe calls AfterApplicationSetupCallback

Expected behavior

The callbyck should just be called once - at AfterPlatformServicesSetup

Avalonia version

11.2.1, 11.2.2

OS

WebAssembly, Android

Additional context

I will provide a PR shortly

gentledepp commented 19 hours ago

@eszterhorvath @Zeljko-Predjeskovic fyi