feat: bundle Inter font, emergency stop button, window persistence + tests
Some checks failed
CI / build-and-test (push) Failing after 27s
Some checks failed
CI / build-and-test (push) Failing after 27s
Four polish items + a test pass. 1. Inter Variable (rsms/inter v3.19, OFL) is bundled at Assets/Fonts/Inter.ttf (~800 KB) and registered as a WPF Resource. WildDragonTheme.xaml's Wd.Font.Sans now points at pack://application:,,,/Assets/Fonts/#Inter so the typography matches wilddragon.net regardless of whether the user has Inter installed system-wide. Falls back to Segoe UI Variable Display if the resource is missing. 2. 'Stop all ISOs' button at the right of the participants header. Bound to a new MainViewModel.StopAllIsosCommand that snapshots the enabled list, awaits DisableIsoAsync sequentially, and silently swallows per-pipeline failures (best-effort emergency stop). CanExecute gates on whether any ISO is currently enabled. 3. WindowStateStore service persists the main window's Left/Top/Width/Height/State to %LOCALAPPDATA%\\TeamsISO\\window.json on close and restores it on SourceInitialized. Multi-monitor friendly: a saved position with no corner inside any virtual screen is rejected so a disconnected monitor doesn't strand the window off-screen. 4. Two new unit tests cover FrameProcessor's drops + duplicates accounting. 76/76 unit tests pass (was 74).
This commit is contained in:
parent
ff7e949466
commit
0c82ac71f0
8 changed files with 305 additions and 13 deletions
BIN
src/TeamsISO.App/Assets/Fonts/Inter.ttf
Normal file
BIN
src/TeamsISO.App/Assets/Fonts/Inter.ttf
Normal file
Binary file not shown.
|
|
@ -304,18 +304,43 @@
|
|||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Section header -->
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="Participants"
|
||||
Style="{StaticResource Wd.Text.Heading}"
|
||||
FontSize="18"/>
|
||||
<Border Style="{StaticResource Wd.Pill}"
|
||||
Margin="12,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Participants.Count}"
|
||||
Style="{StaticResource Wd.Text.Mono}"
|
||||
FontSize="11"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="Participants"
|
||||
Style="{StaticResource Wd.Text.Heading}"
|
||||
FontSize="18"/>
|
||||
<Border Style="{StaticResource Wd.Pill}"
|
||||
Margin="12,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Participants.Count}"
|
||||
Style="{StaticResource Wd.Text.Mono}"
|
||||
FontSize="11"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Emergency stop: tears down every running ISO in one click. -->
|
||||
<Button Grid.Column="1"
|
||||
Style="{StaticResource Wd.Button.Ghost}"
|
||||
Command="{Binding StopAllIsosCommand}"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip="Disable every running ISO immediately">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Border Width="8" Height="8"
|
||||
CornerRadius="4"
|
||||
Background="{DynamicResource Wd.Accent.Coral}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"/>
|
||||
<TextBlock Text="Stop all ISOs"
|
||||
Style="{StaticResource Wd.Text.Body}"
|
||||
FontSize="12"
|
||||
VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="1"
|
||||
Text="Toggle a participant's ISO to spin up an isolated, normalized NDI output."
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ public partial class MainWindow : Window
|
|||
{
|
||||
InitializeComponent();
|
||||
StateChanged += OnWindowStateChanged;
|
||||
SourceInitialized += OnSourceInitialized;
|
||||
Closing += OnClosing;
|
||||
}
|
||||
|
||||
public MainWindow(MainViewModel viewModel) : this()
|
||||
|
|
@ -18,6 +20,22 @@ public partial class MainWindow : Window
|
|||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restore the window's previous placement after the HWND is created (so
|
||||
/// SetWindowPos / WindowState transitions actually take effect). Falls
|
||||
/// silently back to the XAML-default startup location if no snapshot exists.
|
||||
/// </summary>
|
||||
private void OnSourceInitialized(object? sender, EventArgs e)
|
||||
{
|
||||
WindowStateStore.TryApply(this);
|
||||
}
|
||||
|
||||
/// <summary>Persist the placement on close so next launch lands in the same spot.</summary>
|
||||
private void OnClosing(object? sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
WindowStateStore.Save(this);
|
||||
}
|
||||
|
||||
/// <summary>Custom min button — chrome'd window has no system caption buttons.</summary>
|
||||
private void OnMinimize(object sender, RoutedEventArgs e) =>
|
||||
WindowState = WindowState.Minimized;
|
||||
|
|
|
|||
116
src/TeamsISO.App/Services/WindowStateStore.cs
Normal file
116
src/TeamsISO.App/Services/WindowStateStore.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Windows;
|
||||
|
||||
namespace TeamsISO.App.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Saves / restores the main window's size, position, and state across launches.
|
||||
/// Stored as JSON at <c>%LOCALAPPDATA%\TeamsISO\window.json</c>. Multi-monitor
|
||||
/// friendly: a saved position that no longer falls inside any working area is
|
||||
/// rejected on restore so the window doesn't disappear off-screen when a monitor
|
||||
/// has been disconnected.
|
||||
/// </summary>
|
||||
public static class WindowStateStore
|
||||
{
|
||||
private static readonly string Path =
|
||||
System.IO.Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"TeamsISO",
|
||||
"window.json");
|
||||
|
||||
public sealed record Snapshot(
|
||||
double Left,
|
||||
double Top,
|
||||
double Width,
|
||||
double Height,
|
||||
WindowState State);
|
||||
|
||||
/// <summary>Save the current window placement.</summary>
|
||||
public static void Save(Window window)
|
||||
{
|
||||
try
|
||||
{
|
||||
var snap = new Snapshot(
|
||||
Left: window.Left,
|
||||
Top: window.Top,
|
||||
Width: window.ActualWidth,
|
||||
Height: window.ActualHeight,
|
||||
State: window.WindowState == WindowState.Minimized ? WindowState.Normal : window.WindowState);
|
||||
var dir = System.IO.Path.GetDirectoryName(Path);
|
||||
if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(Path, JsonSerializer.Serialize(snap, new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Best-effort persistence; never crash on shutdown for a UI nicety.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply a previously-saved placement. Clamps onto a visible work area so a
|
||||
/// monitor change doesn't strand the window off-screen. Returns true if a
|
||||
/// valid snapshot was applied; false if no file existed or the snapshot was
|
||||
/// rejected for being entirely outside any visible work area.
|
||||
/// </summary>
|
||||
public static bool TryApply(Window window)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(Path)) return false;
|
||||
var json = File.ReadAllText(Path);
|
||||
var snap = JsonSerializer.Deserialize<Snapshot>(json);
|
||||
if (snap is null) return false;
|
||||
|
||||
// Sanity-check sizes (don't restore a 0×0 or absurdly large window).
|
||||
if (snap.Width < 320 || snap.Height < 240) return false;
|
||||
if (snap.Width > 16000 || snap.Height > 12000) return false;
|
||||
|
||||
// Reject if entirely off-screen (any working area on any screen contains
|
||||
// a corner). System.Windows.Forms gives us per-monitor work areas here;
|
||||
// we deliberately stick with WPF's SystemParameters which only reports the
|
||||
// primary, so we use a generous on-screen check rather than refusing
|
||||
// multi-monitor positions.
|
||||
if (!IsAnyCornerOnScreen(snap)) return false;
|
||||
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Left = snap.Left;
|
||||
window.Top = snap.Top;
|
||||
window.Width = snap.Width;
|
||||
window.Height = snap.Height;
|
||||
window.WindowState = snap.State;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Approximate "is at least one corner of the saved rect within the virtual
|
||||
/// screen?" check. Uses SystemParameters.VirtualScreen* which spans every
|
||||
/// monitor.
|
||||
/// </summary>
|
||||
private static bool IsAnyCornerOnScreen(Snapshot snap)
|
||||
{
|
||||
var minX = SystemParameters.VirtualScreenLeft;
|
||||
var minY = SystemParameters.VirtualScreenTop;
|
||||
var maxX = minX + SystemParameters.VirtualScreenWidth;
|
||||
var maxY = minY + SystemParameters.VirtualScreenHeight;
|
||||
|
||||
var corners = new[]
|
||||
{
|
||||
(snap.Left, snap.Top),
|
||||
(snap.Left + snap.Width, snap.Top),
|
||||
(snap.Left, snap.Top + snap.Height),
|
||||
(snap.Left + snap.Width, snap.Top + snap.Height),
|
||||
};
|
||||
foreach (var (x, y) in corners)
|
||||
{
|
||||
if (x >= minX && x <= maxX && y >= minY && y <= maxY)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,11 @@
|
|||
<Resource Include="Assets\dragon-mark.png" />
|
||||
<Resource Include="Assets\wild-dragon-wordmark.png" />
|
||||
<Resource Include="Assets\teamsiso.ico" />
|
||||
<!--
|
||||
Inter Variable from rsms/inter v3.19 (OFL). Single .ttf covers every weight
|
||||
from 100 (Thin) to 900 (Black) so we don't ship a directory of duplicates.
|
||||
-->
|
||||
<Resource Include="Assets\Fonts\Inter.ttf" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,13 @@
|
|||
<SolidColorBrush x:Key="Wd.Status.Error" Color="#FB819C"/>
|
||||
|
||||
<!-- ════ Typography ════ -->
|
||||
<FontFamily x:Key="Wd.Font.Sans">Inter, Segoe UI Variable Display, Segoe UI, sans-serif</FontFamily>
|
||||
<!--
|
||||
Inter is bundled as Assets\Fonts\Inter.ttf (Variable, OFL — rsms/inter v3.19).
|
||||
The pack URI loads it from this assembly's resources at runtime so we don't
|
||||
depend on the user having Inter installed system-wide. Fallback chain to
|
||||
Segoe UI if the resource is somehow missing.
|
||||
-->
|
||||
<FontFamily x:Key="Wd.Font.Sans">pack://application:,,,/Assets/Fonts/#Inter, Inter, Segoe UI Variable Display, Segoe UI, sans-serif</FontFamily>
|
||||
<FontFamily x:Key="Wd.Font.Mono">JetBrains Mono, Cascadia Mono, Consolas, monospace</FontFamily>
|
||||
|
||||
<Style x:Key="Wd.Text.Title" TargetType="TextBlock">
|
||||
|
|
|
|||
|
|
@ -26,6 +26,13 @@ public sealed class MainViewModel : ObservableObject, IDisposable
|
|||
public GlobalSettingsViewModel Settings { get; }
|
||||
public AlertBannerViewModel AlertBanner { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Emergency-stop: disable every running ISO. Bound to a small "Stop all" affordance
|
||||
/// near the participants header so an operator can kill all outputs in a single click
|
||||
/// when something goes sideways during a live show.
|
||||
/// </summary>
|
||||
public AsyncRelayCommand StopAllIsosCommand { get; }
|
||||
|
||||
public string StatusText
|
||||
{
|
||||
get => _statusText;
|
||||
|
|
@ -60,6 +67,26 @@ public sealed class MainViewModel : ObservableObject, IDisposable
|
|||
};
|
||||
_statsTimer.Tick += OnStatsTick;
|
||||
_statsTimer.Start();
|
||||
|
||||
StopAllIsosCommand = new AsyncRelayCommand(StopAllIsosAsync, () => Participants.Any(p => p.IsEnabled));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Issues DisableIsoAsync for every participant whose ISO is currently enabled.
|
||||
/// Each disable is awaited sequentially so we don't try to tear down N pipelines
|
||||
/// in parallel and trip channel-completion races; for ~10 participants this is
|
||||
/// still sub-second total. Failures are swallowed (best-effort emergency stop).
|
||||
/// </summary>
|
||||
private async Task StopAllIsosAsync()
|
||||
{
|
||||
// Snapshot first so the collection doesn't mutate while we iterate.
|
||||
var enabled = Participants.Where(p => p.IsEnabled).ToArray();
|
||||
foreach (var p in enabled)
|
||||
{
|
||||
try { await _controller.DisableIsoAsync(p.Id, CancellationToken.None); }
|
||||
catch { /* defensive */ }
|
||||
p.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStatsTick(object? sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
using System.Threading.Channels;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using TeamsISO.Engine.Domain;
|
||||
using TeamsISO.Engine.Pipeline;
|
||||
|
||||
namespace TeamsISO.Engine.Tests.Pipeline;
|
||||
|
||||
/// <summary>
|
||||
/// Targets the IsoPipeline stats wiring (FPS ring buffer + drops/dups surfaced
|
||||
/// from FrameProcessor). The production-ctor's runner pumps the receiver in a
|
||||
/// background thread, so we drive the FrameProcessor directly here — that's
|
||||
/// where FramesDropped and FramesDuplicated are computed.
|
||||
/// </summary>
|
||||
public class FrameProcessorStatsTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task FrameProcessor_DropsBackloggedFrames_WhenInputHasMultipleQueued()
|
||||
{
|
||||
// Arrange: a raw channel pre-filled with three frames before ProcessOnce runs.
|
||||
// The processor should keep only the newest (closest-frame strategy) and report
|
||||
// FramesDropped == 2 (the two it threw away).
|
||||
var raw = Channel.CreateUnbounded<RawFrame>();
|
||||
var processed = Channel.CreateUnbounded<ProcessedFrame>();
|
||||
var clock = new FakeClock();
|
||||
var settings = FrameProcessingSettings.Default;
|
||||
var processor = new FrameProcessor(
|
||||
settings,
|
||||
new ManagedNearestNeighborFrameScaler(),
|
||||
new SolidFrameRenderer(),
|
||||
clock,
|
||||
raw.Reader,
|
||||
processed.Writer,
|
||||
slateThreshold: TimeSpan.FromSeconds(2.5),
|
||||
NullLogger<FrameProcessor>.Instance);
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
raw.Writer.TryWrite(MakeFrame(width: 320, height: 180, ticks: i));
|
||||
|
||||
// Act
|
||||
await processor.ProcessOnceAsync(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
var stats = processor.Stats;
|
||||
stats.FramesIn.Should().Be(3, because: "the processor counts every frame it pulled off the channel");
|
||||
stats.FramesOut.Should().Be(1, because: "closest-frame strategy emits one frame per tick");
|
||||
stats.FramesDropped.Should().Be(2, because: "two queued frames were superseded by the newest");
|
||||
stats.IncomingWidth.Should().Be(320);
|
||||
stats.IncomingHeight.Should().Be(180);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FrameProcessor_DuplicatesLastFrame_WhenNoNewArrival()
|
||||
{
|
||||
// First tick: a single frame. Second tick: nothing new — should re-emit
|
||||
// the last frame (within slate threshold) and increment FramesDuplicated.
|
||||
var raw = Channel.CreateUnbounded<RawFrame>();
|
||||
var processed = Channel.CreateUnbounded<ProcessedFrame>();
|
||||
var clock = new FakeClock { NowTicks = 0 };
|
||||
var processor = new FrameProcessor(
|
||||
FrameProcessingSettings.Default,
|
||||
new ManagedNearestNeighborFrameScaler(),
|
||||
new SolidFrameRenderer(),
|
||||
clock,
|
||||
raw.Reader,
|
||||
processed.Writer,
|
||||
slateThreshold: TimeSpan.FromSeconds(2.5),
|
||||
NullLogger<FrameProcessor>.Instance);
|
||||
|
||||
raw.Writer.TryWrite(MakeFrame(width: 320, height: 180, ticks: 0));
|
||||
await processor.ProcessOnceAsync(CancellationToken.None);
|
||||
|
||||
// Advance clock 100ms; no new frame.
|
||||
clock.NowTicks = TimeSpan.FromMilliseconds(100).Ticks;
|
||||
await processor.ProcessOnceAsync(CancellationToken.None);
|
||||
|
||||
var stats = processor.Stats;
|
||||
stats.FramesIn.Should().Be(1);
|
||||
stats.FramesOut.Should().Be(2);
|
||||
stats.FramesDuplicated.Should().Be(1, because: "the second tick re-emitted the last frame");
|
||||
}
|
||||
|
||||
private static RawFrame MakeFrame(int width, int height, long ticks)
|
||||
{
|
||||
var bytes = new byte[width * height * 4];
|
||||
return new RawFrame(width, height, ticks, bytes, PixelFormat.Bgra);
|
||||
}
|
||||
|
||||
/// <summary>Simple deterministic clock for processor tests.</summary>
|
||||
private sealed class FakeClock : IFrameClock
|
||||
{
|
||||
public long NowTicks { get; set; }
|
||||
public ValueTask<bool> WaitForNextTickAsync(CancellationToken cancellationToken) => ValueTask.FromResult(true);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue