Refactor settings management in PLib video library manager. Replace dialog-based settings with a single-panel overlay for improved user experience. Update MainWindow and SettingsView to support new settings panel, and adjust ViewModels accordingly. Enhance README.md to reflect these changes.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PLib.Desktop.ViewModels;
|
||||
using PLib.Desktop.Views;
|
||||
|
||||
namespace PLib.Desktop.Services;
|
||||
|
||||
/// <summary>Opens the application's dialogs, so view models never touch window types.</summary>
|
||||
public interface IDialogService
|
||||
{
|
||||
Task<SettingsDialogOutcome> ShowSettingsAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IDialogService"/>
|
||||
public sealed class DialogService(IServiceScopeFactory scopeFactory) : IDialogService
|
||||
{
|
||||
public async Task<SettingsDialogOutcome> ShowSettingsAsync()
|
||||
{
|
||||
if (Avalonia.Application.Current?.ApplicationLifetime
|
||||
is not IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
return SettingsDialogOutcome.Cancelled;
|
||||
}
|
||||
|
||||
// A scope per dialog: the container would otherwise keep every settings view model
|
||||
// it ever built alive until shutdown, and disposing the scope disposes the model.
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var viewModel = scope.ServiceProvider.GetRequiredService<SettingsViewModel>();
|
||||
|
||||
var window = new SettingsWindow { DataContext = viewModel };
|
||||
|
||||
// The view model decides when it is done; the window only carries the answer out.
|
||||
using var subscription = viewModel.Closed.Subscribe(outcome => window.Close(outcome));
|
||||
|
||||
// Show a real number in the cache section rather than an empty label.
|
||||
await viewModel.RefreshCacheSizeCommand.Execute().FirstAsync();
|
||||
|
||||
// Closing through the title bar yields null, which counts as cancelling.
|
||||
return await window.ShowDialog<SettingsDialogOutcome?>(owner) ?? SettingsDialogOutcome.Cancelled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user