feat: close directly if next window is null.

This commit is contained in:
Dong Bin
2025-02-24 19:50:02 +08:00
parent aa4507c9c8
commit dc2cf01b43
5 changed files with 72 additions and 58 deletions

View File

@@ -35,7 +35,8 @@ public abstract class SplashWindow: Window
private void OnContextRequestClose(object? sender, object? args)
{
Close(args);
DialogResult = args;
Close();
}
protected override void OnLoaded(RoutedEventArgs e)
@@ -46,9 +47,11 @@ public abstract class SplashWindow: Window
DispatcherTimer.RunOnce(Close, CountDown.Value);
}
}
protected object? DialogResult { get; private set; }
protected virtual Task<bool> CanClose() => Task.FromResult(true);
protected abstract Task<Window> CreateNextWindow();
protected abstract Task<Window?> CreateNextWindow();
private bool _canClose;
@@ -62,16 +65,17 @@ public abstract class SplashWindow: Window
if (_canClose)
{
var nextWindow = await CreateNextWindow();
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime && nextWindow is not null)
{
lifetime.MainWindow = nextWindow;
}
nextWindow.Show();
nextWindow?.Show();
Close();
if (DataContext is IDialogContext idc)
{
idc.Close();
// unregister in advance in case developer try to raise event again.
idc.RequestClose -= OnContextRequestClose;
idc.Close();
}
return;
}