diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66b7e6f..b6f28d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ All notable changes will be documented here. The format follows [Keep a Changelo
- `REL-00003` Firefox qualification covers the installed `firefox-bin` runtime, one-row grouping, visible launcher/icon preference, ambiguity safety, and executable fallback.
- `FAD-0301` XDG user-data paths and SQLite startup with versioned, checksummed, transactional schema migrations.
- `FAD-0302` Durable application identity records, allowlisted evidence, and custom name/icon overrides with opaque keys for sensitive fallback identities.
+- `FAD-0501` Live Avalonia application rows from immutable mixer snapshots, with per-application volume and mute commands and reconnect-aware controls.
### Changed
diff --git a/README.md b/README.md
index a9ed5e1..4336ad5 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
Fadrio resolves PipeWire playback nodes into stable logical applications and groups every session owned by an application behind one mixer target. Three browser streams should look like one **Brave** or **Firefox** control—not three nodes, renderer processes, or PIDs.
> [!IMPORTANT]
-> Fadrio is a source-only public alpha, not an end-user release. No supported binary package is published yet. Packaging, persistence, MIDI control, and the finished interface are not implemented. Initial Steam/Proton identification requires corroborating local process, compatibility-directory, and installed-manifest evidence.
+> Fadrio is a source-only public alpha, not an end-user release. No supported binary package is published yet. Basic identity persistence and live application controls exist, but durable mixer policies, MIDI control, output control, and the finished interface are not implemented. Initial Steam/Proton identification requires corroborating local process, compatibility-directory, and installed-manifest evidence.
## What works today
@@ -35,7 +35,7 @@ Fadrio resolves PipeWire playback nodes into stable logical applications and gro
- Stable fallback identities that never use PID.
- Multi-session application grouping and application-wide volume/mute commands.
- Managed reconnect supervision with generation isolation.
-- Diagnostic CLI and minimal Avalonia shell.
+- Diagnostic CLI, SQLite-backed identity overrides, and the first live Avalonia application rows with volume and mute controls.
## Architecture
@@ -89,6 +89,10 @@ dotnet run --project src/Fadrio.Cli -- profile clear xdg:firefox
The override appears in subsequent `apps` output while the canonical ID remains unchanged.
+Launch the in-development mixer with `dotnet run --project src/Fadrio.UI`. Its application rows reflect the live PipeWire snapshot and use the same application-wide volume/mute command path as the CLI. Output-device controls, icons, tray behavior, and UI polish remain on the roadmap.
+
+[See the first live-row screenshot](docs/screenshots/fad-0501-live-fixture.png), captured with a controlled, silent PipeWire fixture rather than a user's applications.
+
Exercise the shared M0 command path:
```bash
diff --git a/ROADMAP.md b/ROADMAP.md
index 8e74702..889161e 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -179,7 +179,7 @@ Canonical ticket format:
## 0.5 — UI alpha
-- [ ] `FAD-0501` `P0` Connect immutable mixer snapshots and commands to the Avalonia view models.
+- [x] `FAD-0501` `P0` Connect immutable mixer snapshots and commands to the Avalonia view models.
- [ ] `FAD-0502` `P1` Build accessible output and logical-application rows with mixed-volume state.
- [ ] `FAD-0503` `P1` Add stable sorting, interaction freeze, empty, unavailable, and reconnect states.
- [ ] `FAD-0504` `P1` Implement tray popup, single-instance activation, and clean shutdown.
diff --git a/docs/screenshots/fad-0501-live-fixture.png b/docs/screenshots/fad-0501-live-fixture.png
new file mode 100644
index 0000000..013522d
Binary files /dev/null and b/docs/screenshots/fad-0501-live-fixture.png differ
diff --git a/src/Fadrio.UI/App.axaml.cs b/src/Fadrio.UI/App.axaml.cs
index 28d8474..98d0b41 100644
--- a/src/Fadrio.UI/App.axaml.cs
+++ b/src/Fadrio.UI/App.axaml.cs
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
+using Fadrio.Infrastructure;
using Fadrio.UI.ViewModels;
namespace Fadrio.UI;
@@ -13,10 +14,19 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
- desktop.MainWindow = new MainWindow
+ var database = new FadrioDatabase(FadrioDataPaths.Resolve().DatabasePath);
+ MixerUiSession? session = null;
+ var viewModel = new MainWindowViewModel(
+ (id, volume) => session!.SetVolumeAsync(id, volume),
+ (id, muted) => session!.SetMuteAsync(id, muted));
+ session = new MixerUiSession(viewModel, database);
+ var window = new MainWindow
{
- DataContext = new MainWindowViewModel()
+ DataContext = viewModel
};
+ window.Opened += (_, _) => session.Start();
+ window.Closed += async (_, _) => await session.DisposeAsync();
+ desktop.MainWindow = window;
}
base.OnFrameworkInitializationCompleted();
diff --git a/src/Fadrio.UI/MainWindow.axaml b/src/Fadrio.UI/MainWindow.axaml
index 15c0301..4bf7450 100644
--- a/src/Fadrio.UI/MainWindow.axaml
+++ b/src/Fadrio.UI/MainWindow.axaml
@@ -12,13 +12,34 @@
WindowStartupLocation="CenterScreen">
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Fadrio.UI/MixerUiSession.cs b/src/Fadrio.UI/MixerUiSession.cs
new file mode 100644
index 0000000..120984c
--- /dev/null
+++ b/src/Fadrio.UI/MixerUiSession.cs
@@ -0,0 +1,77 @@
+using Avalonia.Threading;
+using Fadrio.Application;
+using Fadrio.Core;
+using Fadrio.Infrastructure;
+using Fadrio.NativeInterop;
+using Fadrio.Platform.Linux;
+using Fadrio.UI.ViewModels;
+using ApplicationId = Fadrio.Core.ApplicationId;
+
+namespace Fadrio.UI;
+
+internal sealed class MixerUiSession : IAsyncDisposable
+{
+ private readonly CancellationTokenSource _shutdown = new();
+ private readonly ReconnectingAudioBackend _backend = new(() => new NativeAudioBackend());
+ private readonly XdgDesktopApplicationIndex _desktopIndex = new();
+ private readonly MixerStateCoordinator _coordinator;
+ private readonly MixerCommands _commands;
+ private readonly MainWindowViewModel _viewModel;
+ private Task? _runTask;
+
+ public MixerUiSession(MainWindowViewModel viewModel, FadrioDatabase database)
+ {
+ _viewModel = viewModel;
+ IApplicationResolver resolver = new ApplicationResolver(new LinuxProcMetadataProvider(), _desktopIndex,
+ new SteamApplicationResolver(new SteamApplicationIndex()),
+ new FlatpakApplicationResolver(_desktopIndex), new SnapApplicationResolver(_desktopIndex));
+ resolver = new PersistentApplicationResolver(resolver, new ApplicationIdentityStore(database));
+ _coordinator = new MixerStateCoordinator(resolver);
+ _commands = new MixerCommands(_backend, _coordinator);
+ }
+
+ public void Start() => _runTask ??= Task.Run(RunAsync);
+
+ public ValueTask SetVolumeAsync(ApplicationId id, float volume) =>
+ _commands.SetApplicationVolumeAsync(id, volume, _shutdown.Token);
+
+ public ValueTask SetMuteAsync(ApplicationId id, bool muted) =>
+ _commands.SetApplicationMuteAsync(id, muted, _shutdown.Token);
+
+ private async Task RunAsync()
+ {
+ try
+ {
+ await foreach (AudioBackendEvent backendEvent in _backend.WatchAsync(_shutdown.Token))
+ {
+ await _coordinator.ApplyAsync(backendEvent, _shutdown.Token);
+ MixerSnapshot snapshot = _coordinator.Current;
+ bool? available = backendEvent switch
+ {
+ BackendReady => true,
+ BackendDisconnected => false,
+ _ => null
+ };
+ Dispatcher.UIThread.Post(() =>
+ {
+ if (available.HasValue) _viewModel.SetBackendAvailable(available.Value);
+ _viewModel.ApplySnapshot(snapshot);
+ });
+ }
+ }
+ catch (OperationCanceledException) when (_shutdown.IsCancellationRequested) { }
+ catch (Exception exception) when (exception is InvalidOperationException or IOException or DllNotFoundException)
+ {
+ Dispatcher.UIThread.Post(_viewModel.SetBackendFailed);
+ }
+ }
+
+ public async ValueTask DisposeAsync()
+ {
+ await _shutdown.CancelAsync();
+ if (_runTask is not null) await _runTask;
+ await _backend.DisposeAsync();
+ _desktopIndex.Dispose();
+ _shutdown.Dispose();
+ }
+}
diff --git a/src/Fadrio.UI/ViewModels/MainWindowViewModel.cs b/src/Fadrio.UI/ViewModels/MainWindowViewModel.cs
index 5df4b98..586f8f1 100644
--- a/src/Fadrio.UI/ViewModels/MainWindowViewModel.cs
+++ b/src/Fadrio.UI/ViewModels/MainWindowViewModel.cs
@@ -1,19 +1,226 @@
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Windows.Input;
+using Fadrio.Core;
+using ApplicationId = Fadrio.Core.ApplicationId;
+
namespace Fadrio.UI.ViewModels;
-public sealed class MainWindowViewModel
+public sealed class MainWindowViewModel : INotifyPropertyChanged
{
+ private readonly Dictionary _rows = [];
+ private readonly Func? _setVolume;
+ private readonly Func? _setMute;
+ private string _status = UiStrings.ConnectingMessage;
+ private bool _backendAvailable;
+
+ public MainWindowViewModel(
+ Func? setVolume = null,
+ Func? setMute = null)
+ {
+ _setVolume = setVolume;
+ _setMute = setMute;
+ }
+
+ public event PropertyChangedEventHandler? PropertyChanged;
public string Title => UiStrings.Title;
public string OutputHeading => UiStrings.OutputHeading;
public string EmptyOutputMessage => UiStrings.EmptyOutputMessage;
public string ApplicationsHeading => UiStrings.ApplicationsHeading;
public string EmptyApplicationsMessage => UiStrings.EmptyApplicationsMessage;
+ public ObservableCollection Applications { get; } = [];
+ public bool HasNoApplications => Applications.Count == 0;
+ public string Status
+ {
+ get => _status;
+ private set
+ {
+ if (_status == value) return;
+ _status = value;
+ OnPropertyChanged();
+ }
+ }
+
+ public void SetBackendAvailable(bool available)
+ {
+ _backendAvailable = available;
+ Status = available ? UiStrings.ReadyMessage : UiStrings.ReconnectingMessage;
+ foreach (ApplicationRowViewModel row in Applications) row.CanControl = available;
+ }
+
+ public void SetBackendFailed()
+ {
+ _backendAvailable = false;
+ Status = UiStrings.BackendFailedMessage;
+ foreach (ApplicationRowViewModel row in Applications) row.CanControl = false;
+ }
+
+ public void ApplySnapshot(MixerSnapshot snapshot)
+ {
+ ArgumentNullException.ThrowIfNull(snapshot);
+ var activeIds = new HashSet();
+ var ordered = new List();
+ foreach (RuntimeApplication application in snapshot.Applications)
+ {
+ ApplicationId id = application.Identity.Id;
+ activeIds.Add(id);
+ if (!_rows.TryGetValue(id, out ApplicationRowViewModel? row))
+ {
+ row = new ApplicationRowViewModel(id, SendVolumeAsync, SendMuteAsync);
+ _rows.Add(id, row);
+ }
+ row.Update(application, _backendAvailable);
+ ordered.Add(row);
+ }
+ foreach (ApplicationId id in _rows.Keys.Where(id => !activeIds.Contains(id)).ToArray()) _rows.Remove(id);
+ for (int index = Applications.Count - 1; index >= 0; index--)
+ if (!activeIds.Contains(Applications[index].Id)) Applications.RemoveAt(index);
+ for (int index = 0; index < ordered.Count; index++)
+ {
+ ApplicationRowViewModel row = ordered[index];
+ if (index < Applications.Count && ReferenceEquals(Applications[index], row)) continue;
+ int previousIndex = Applications.IndexOf(row);
+ if (previousIndex >= 0) Applications.Move(previousIndex, index);
+ else Applications.Insert(index, row);
+ }
+ OnPropertyChanged(nameof(HasNoApplications));
+ }
+
+ private ValueTask SendVolumeAsync(ApplicationId id, float value) => _setVolume?.Invoke(id, value) ?? ValueTask.CompletedTask;
+ private ValueTask SendMuteAsync(ApplicationId id, bool value) => _setMute?.Invoke(id, value) ?? ValueTask.CompletedTask;
+ private void OnPropertyChanged([CallerMemberName] string? name = null) =>
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+}
+
+public sealed class ApplicationRowViewModel : INotifyPropertyChanged
+{
+ private readonly Func _setVolume;
+ private readonly Func _setMute;
+ private string _displayName = string.Empty;
+ private double _volume;
+ private bool _isMuted;
+ private bool _isMixedVolume;
+ private bool _canControl;
+ private bool _updating;
+
+ internal ApplicationRowViewModel(ApplicationId id, Func setVolume,
+ Func setMute)
+ {
+ Id = id;
+ _setVolume = setVolume;
+ _setMute = setMute;
+ ToggleMuteCommand = new RelayCommand(() => _ = ToggleMuteAsync());
+ }
+
+ public event PropertyChangedEventHandler? PropertyChanged;
+ public ApplicationId Id { get; }
+ public ICommand ToggleMuteCommand { get; }
+ public string DisplayName
+ {
+ get => _displayName;
+ private set
+ {
+ if (SetField(ref _displayName, value))
+ {
+ OnPropertyChanged(nameof(VolumeControlLabel));
+ OnPropertyChanged(nameof(MuteControlLabel));
+ }
+ }
+ }
+ public double Volume
+ {
+ get => _volume;
+ set
+ {
+ double bounded = Math.Clamp(value, 0, 100);
+ if (Math.Abs(_volume - bounded) < 0.01) return;
+ _volume = bounded;
+ OnPropertyChanged();
+ OnPropertyChanged(nameof(VolumeLabel));
+ if (!_updating && CanControl) _ = SetVolumeAsync((float)(bounded / 100));
+ }
+ }
+ public string VolumeLabel => IsMixedVolume ? $"{Volume:0}% mixed" : $"{Volume:0}%";
+ public bool IsMuted
+ {
+ get => _isMuted;
+ private set
+ {
+ if (SetField(ref _isMuted, value))
+ {
+ OnPropertyChanged(nameof(MuteLabel));
+ OnPropertyChanged(nameof(MuteControlLabel));
+ }
+ }
+ }
+ public bool IsMixedVolume { get => _isMixedVolume; private set { if (SetField(ref _isMixedVolume, value)) OnPropertyChanged(nameof(VolumeLabel)); } }
+ public bool CanControl { get => _canControl; internal set => SetField(ref _canControl, value); }
+ public string MuteLabel => IsMuted ? UiStrings.UnmuteAction : UiStrings.MuteAction;
+ public string VolumeControlLabel => $"{DisplayName} volume";
+ public string MuteControlLabel => $"{MuteLabel} {DisplayName}";
+
+ internal void Update(RuntimeApplication application, bool canControl)
+ {
+ _updating = true;
+ try
+ {
+ DisplayName = application.Identity.DisplayName;
+ Volume = application.EffectiveVolume * 100;
+ IsMixedVolume = application.IsMixedVolume;
+ IsMuted = application.IsMuted;
+ CanControl = canControl;
+ }
+ finally { _updating = false; }
+ }
+
+ private async Task SetVolumeAsync(float value)
+ {
+ try { await _setVolume(Id, value); }
+ catch (Exception exception) when (exception is InvalidOperationException or IOException or OperationCanceledException)
+ {
+ // A stream can disappear, or the backend can stop, during a drag.
+ }
+ }
+
+ private async Task ToggleMuteAsync()
+ {
+ if (!CanControl) return;
+ try { await _setMute(Id, !IsMuted); }
+ catch (Exception exception) when (exception is InvalidOperationException or IOException or OperationCanceledException)
+ {
+ // A disappearing stream is normal.
+ }
+ }
+
+ private bool SetField(ref T field, T value, [CallerMemberName] string? name = null)
+ {
+ if (EqualityComparer.Default.Equals(field, value)) return false;
+ field = value;
+ OnPropertyChanged(name);
+ return true;
+ }
+ private void OnPropertyChanged(string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+}
+
+internal sealed class RelayCommand(Action execute) : ICommand
+{
+ public event EventHandler? CanExecuteChanged { add { } remove { } }
+ public bool CanExecute(object? parameter) => true;
+ public void Execute(object? parameter) => execute();
}
internal static class UiStrings
{
internal const string Title = "Fadrio";
internal const string OutputHeading = "OUTPUT";
- internal const string EmptyOutputMessage = "No output available";
+ internal const string EmptyOutputMessage = "Output control is coming soon";
internal const string ApplicationsHeading = "APPLICATIONS";
internal const string EmptyApplicationsMessage = "No applications are currently playing audio.";
+ internal const string ConnectingMessage = "Connecting to audio…";
+ internal const string ReconnectingMessage = "Audio unavailable — reconnecting…";
+ internal const string ReadyMessage = "Connected";
+ internal const string BackendFailedMessage = "Audio backend could not start";
+ internal const string MuteAction = "Mute";
+ internal const string UnmuteAction = "Unmute";
}
diff --git a/tests/Fadrio.UI.Tests/MainWindowViewModelTests.cs b/tests/Fadrio.UI.Tests/MainWindowViewModelTests.cs
index 63d70b1..a2e0340 100644
--- a/tests/Fadrio.UI.Tests/MainWindowViewModelTests.cs
+++ b/tests/Fadrio.UI.Tests/MainWindowViewModelTests.cs
@@ -1,14 +1,116 @@
+using Fadrio.Core;
using Fadrio.UI.ViewModels;
+using ApplicationId = Fadrio.Core.ApplicationId;
namespace Fadrio.UI.Tests;
public sealed class MainWindowViewModelTests
{
[Fact]
- public void ProductionShellStartsWithHonestEmptyStates()
+ public void EmptyShellDoesNotPretendToHaveAnOutputDevice()
{
var viewModel = new MainWindowViewModel();
- Assert.Equal("No output available", viewModel.EmptyOutputMessage);
+ Assert.Equal("Output control is coming soon", viewModel.EmptyOutputMessage);
Assert.Equal("No applications are currently playing audio.", viewModel.EmptyApplicationsMessage);
+ Assert.True(viewModel.HasNoApplications);
}
+
+ [Fact]
+ public void SnapshotsReuseRowsAndNeverEmitCommandsForBackendRefresh()
+ {
+ int volumeCommands = 0;
+ var viewModel = new MainWindowViewModel((_, _) => { volumeCommands++; return ValueTask.CompletedTask; });
+ viewModel.SetBackendAvailable(true);
+ viewModel.ApplySnapshot(Snapshot(App("xdg:firefox", "Firefox", 0.3f)));
+ ApplicationRowViewModel row = Assert.Single(viewModel.Applications);
+
+ viewModel.ApplySnapshot(Snapshot(App("xdg:firefox", "Browser", 0.7f)));
+
+ Assert.Same(row, Assert.Single(viewModel.Applications));
+ Assert.Equal("Browser", row.DisplayName);
+ Assert.Equal("Browser volume", row.VolumeControlLabel);
+ Assert.Equal("Mute Browser", row.MuteControlLabel);
+ Assert.Equal(70, row.Volume, 1);
+ Assert.Equal(0, volumeCommands);
+ }
+
+ [Fact]
+ public void SliderAndMuteCommandTargetStableApplicationId()
+ {
+ ApplicationId? volumeId = null;
+ float sentVolume = -1;
+ ApplicationId? muteId = null;
+ bool? sentMute = null;
+ var viewModel = new MainWindowViewModel(
+ (id, volume) => { volumeId = id; sentVolume = volume; return ValueTask.CompletedTask; },
+ (id, muted) => { muteId = id; sentMute = muted; return ValueTask.CompletedTask; });
+ viewModel.SetBackendAvailable(true);
+ viewModel.ApplySnapshot(Snapshot(App("xdg:firefox", "Firefox", 0.5f)));
+ ApplicationRowViewModel row = Assert.Single(viewModel.Applications);
+
+ row.Volume = 25;
+ row.ToggleMuteCommand.Execute(null);
+
+ Assert.Equal(new ApplicationId("xdg:firefox"), volumeId);
+ Assert.Equal(0.25f, sentVolume);
+ Assert.Equal(new ApplicationId("xdg:firefox"), muteId);
+ Assert.True(sentMute);
+ }
+
+ [Fact]
+ public void DisconnectDisablesControlsAndClearsRemovedApplications()
+ {
+ var viewModel = new MainWindowViewModel();
+ viewModel.SetBackendAvailable(true);
+ viewModel.ApplySnapshot(Snapshot(App("xdg:firefox", "Firefox", 0.3f)));
+ ApplicationRowViewModel row = Assert.Single(viewModel.Applications);
+
+ viewModel.SetBackendAvailable(false);
+ viewModel.ApplySnapshot(MixerSnapshot.Empty);
+
+ Assert.False(row.CanControl);
+ Assert.True(viewModel.HasNoApplications);
+ Assert.Empty(viewModel.Applications);
+ Assert.Contains("reconnecting", viewModel.Status, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void SnapshotOrderChangesWithoutReplacingExistingRows()
+ {
+ var viewModel = new MainWindowViewModel();
+ viewModel.ApplySnapshot(Snapshot(
+ App("xdg:firefox", "Firefox", 0.3f),
+ App("xdg:music", "Music", 0.6f)));
+ ApplicationRowViewModel firefox = viewModel.Applications[0];
+ ApplicationRowViewModel music = viewModel.Applications[1];
+
+ viewModel.ApplySnapshot(Snapshot(
+ App("xdg:music", "Music", 0.6f),
+ App("xdg:firefox", "Firefox", 0.3f)));
+
+ Assert.Same(music, viewModel.Applications[0]);
+ Assert.Same(firefox, viewModel.Applications[1]);
+ }
+
+ [Fact]
+ public void MixedSessionsShowAnHonestCombinedValue()
+ {
+ var viewModel = new MainWindowViewModel();
+ viewModel.ApplySnapshot(Snapshot(App("xdg:firefox", "Firefox", 0.2f, 0.8f)));
+ ApplicationRowViewModel row = Assert.Single(viewModel.Applications);
+
+ Assert.True(row.IsMixedVolume);
+ Assert.Equal("50% mixed", row.VolumeLabel);
+ }
+
+ private static MixerSnapshot Snapshot(params RuntimeApplication[] apps) => new(apps, 1);
+
+ private static RuntimeApplication App(string id, string name, params float[] volumes) => new(
+ new ApplicationIdentity { Id = new(id), DisplayName = name },
+ volumes.Select((volume, index) => new AudioSession
+ {
+ Id = new($"session:{index}"),
+ PipeWireNodeId = (uint)index + 1,
+ Volume = volume
+ }));
}