Multi-scene webcam (schema v3/v4): singleton Webcam + per-scene WebcamSceneConfig, right-click OBS-style border/context menu, persisted round-to-rect restore + legacy-square 16:9 heal, dark MenuItem template, tests (25 passing)

This commit is contained in:
2026-08-07 08:24:18 -07:00
parent f31ce9fdb7
commit e037ba027b
23 changed files with 1405 additions and 287 deletions
+54 -12
View File
@@ -9,37 +9,79 @@ namespace ytLive.Tests;
/// <summary>
/// The layout DB is a full rewrite on every save (DELETE all scenes/sources,
/// re-insert from memory). This guards the round trip: sources the user deletes
/// in the UI must not come back after a save + reload.
/// re-insert from memory). This guards the round trip: webcam configs the user
/// removes in the UI must not come back after a save + reload.
/// </summary>
public class LayoutStorePersistenceTests
{
[Fact]
public void Deleted_Webcam_Source_Does_Not_Return_After_Save_And_Reload()
public void Deleted_Webcam_Config_Does_Not_Return_After_Save_And_Reload()
{
var path = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-{Guid.NewGuid():N}.db");
try
{
using var store = new LayoutStore(path);
var webcam = new Webcam { DeviceId = "real-device", Name = "Logitech" };
var scene = new Scene { Name = "Starting" };
scene.Sources.Add(new Source
scene.Elements.Add(new WebcamSceneConfig
{
Name = "Webcam",
Type = SourceType.Webcam,
DeviceId = "real-device",
WebcamId = webcam.Id,
Name = webcam.Name,
Width = 480,
Height = 270,
});
store.Save(new[] { scene });
store.Save(new[] { scene }, webcam);
var reloaded = store.Load();
Assert.Single(reloaded[0].Sources);
var config = Assert.Single(reloaded[0].Elements);
Assert.IsType<WebcamSceneConfig>(config);
reloaded[0].Sources.RemoveAt(0);
store.Save(reloaded);
reloaded[0].Elements.RemoveAt(0);
store.Save(reloaded, store.Webcam);
var afterDelete = store.Load();
Assert.Empty(afterDelete[0].Sources);
Assert.Empty(afterDelete[0].Elements);
}
finally
{
SqliteConnection.ClearAllPools();
try { File.Delete(path); } catch { /* best-effort cleanup */ }
}
}
// Round-to-rect restore is persisted (schema v4): a Round webcam resized to a
// square saves its pre-Round rect dims, and a reloaded config restores them on
// toggle-back instead of staying square.
[Fact]
public void Pre_Round_Rect_Dims_Survive_Save_And_Reload()
{
var path = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-{Guid.NewGuid():N}.db");
try
{
using var store = new LayoutStore(path);
var webcam = new Webcam { DeviceId = "real-device", Name = "Logitech" };
var scene = new Scene { Name = "Starting" };
scene.Elements.Add(new WebcamSceneConfig
{
WebcamId = webcam.Id,
Name = webcam.Name,
Width = 400,
Height = 400,
ClipShape = ClipShape.Round,
RectWidth = 480,
RectHeight = 270,
});
store.Save(new[] { scene }, webcam);
var reloaded = store.Load();
var config = Assert.IsType<WebcamSceneConfig>(Assert.Single(reloaded[0].Elements));
config.ToggleClipShape();
Assert.Equal(ClipShape.Traditional, config.ClipShape);
Assert.Equal(480, config.Width);
Assert.Equal(270, config.Height);
Assert.Null(config.RectWidth);
Assert.Null(config.RectHeight);
}
finally
{