Fix: derive IsBackground from Type on layout load (legacy rows healed)

This commit is contained in:
2026-08-23 07:25:54 -07:00
parent 46da9954ad
commit 809c066184
5 changed files with 88 additions and 23 deletions
@@ -120,6 +120,48 @@ public class LayoutStorePersistenceTests
}
}
// Rows saved before the Type setter derived IsBackground carry IsBackground=0
// for Type='Background', which used to load false — hiding the Background
// properties panel in BRB/Chat/Ending. Load must derive from Type while
// keeping the persisted bit for legacy DisplayCapture backdrops.
[Fact]
public void Legacy_IsBackground_Zero_Rows_Derive_From_Type_On_Load()
{
var path = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-{Guid.NewGuid():N}.db");
try
{
using (var store = new LayoutStore(path))
{
var scene = new Scene { Name = "BRB", HasBackground = true };
scene.Elements.Add(new Source { Name = "Game Capture", Type = SourceType.DisplayCapture, IsBackground = true });
scene.Elements.Add(new Source { Name = "Background", Type = SourceType.Background });
scene.Elements.Add(new Source { Name = "Logo", Type = SourceType.Image });
store.Save(new[] { scene }, null, null);
using var conn = new SqliteConnection($"Data Source={path}");
conn.Open();
using var cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE Source SET IsBackground = 0 WHERE Name IN ('Background', 'Logo');";
cmd.ExecuteNonQuery();
}
using var reopened = new LayoutStore(path);
var reloaded = reopened.Load();
var sources = Assert.Single(reloaded).Elements.OfType<Source>().ToList();
Assert.True(sources.Single(s => s.Type == SourceType.Background).IsBackground,
"A legacy IsBackground=0 row with Type=Background must derive the flag on load");
Assert.True(sources.Single(s => s.Type == SourceType.DisplayCapture).IsBackground,
"The persisted bit must survive for legacy DisplayCapture backdrops");
Assert.False(sources.Single(s => s.Type == SourceType.Image).IsBackground);
}
finally
{
SqliteConnection.ClearAllPools();
try { File.Delete(path); } catch { /* best-effort cleanup */ }
}
}
// Per-scene background switch (schema v6): a scene whose background was turned
// off must stay off across a save + reload.
[Fact]