Skip to content

Commit

Permalink
Fix not handling first window creation (#14553)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 committed Feb 9, 2024
1 parent 0c4b19b commit b1670ab
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public bool TryShutdown(int exitCode = 0)
return DoShutdown(new ShutdownRequestedEventArgs(), true, false, exitCode);
}

internal void SetupCore(string[] args)
internal void SubscribeGlobalEvents()
{
if (_compositeDisposable is not null)
{
// There could be a case, when lifetime was setup without starting.
// Until developer started it manually later. To avoid API breaking changes, it will execute Setup method twice.
return;
}

_compositeDisposable = new CompositeDisposable(
Window.WindowOpenedEvent.AddClassHandler(typeof(Window), (sender, _) =>
{
Expand All @@ -91,7 +91,12 @@ internal void SetupCore(string[] args)
var window = (Window)sender!;
_windows.Remove(window);
HandleWindowClosed(window);
}));
}));
}

internal void SetupCore(string[] args)
{
SubscribeGlobalEvents();

Startup?.Invoke(this, new ControlledApplicationLifetimeStartupEventArgs(args));

Expand Down Expand Up @@ -214,6 +219,7 @@ private static ClassicDesktopStyleApplicationLifetime PrepareLifetime(AppBuilder
{
var lifetime = builder.LifetimeOverride?.Invoke(typeof(ClassicDesktopStyleApplicationLifetime)) as ClassicDesktopStyleApplicationLifetime
?? new ClassicDesktopStyleApplicationLifetime();
lifetime.SubscribeGlobalEvents();

lifetime.Args = args;
lifetimeBuilder?.Invoke(lifetime);
Expand Down

0 comments on commit b1670ab

Please sign in to comment.