feat(37): restore all scenes to factory defaults
This commit is contained in:
@@ -165,6 +165,16 @@ public partial class LayoutStore : IDisposable
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Restores the full factory snapshot without changing the active build stamp.</summary>
|
||||||
|
public bool RestoreAllDefaults()
|
||||||
|
{
|
||||||
|
if (GetSnapshotState(DefaultsInitializedKey) != "1") return false;
|
||||||
|
var buildId = GetSnapshotState(CurrentBuildIdKey);
|
||||||
|
if (string.IsNullOrWhiteSpace(buildId)) return false;
|
||||||
|
RestoreDefaults(buildId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private string? GetCurrentWebcamId()
|
private string? GetCurrentWebcamId()
|
||||||
{
|
{
|
||||||
using var cmd = _connection.CreateCommand();
|
using var cmd = _connection.CreateCommand();
|
||||||
|
|||||||
@@ -149,6 +149,42 @@ public sealed class LayoutStoreSnapshotTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ResetAllScenes_RestoresTheFactorySnapshot()
|
||||||
|
{
|
||||||
|
var path = Path.Combine(Path.GetTempPath(), $"ytLlive-layout-snapshot-{Guid.NewGuid():N}.db");
|
||||||
|
var starting = MakeScene(SceneCatalog.Starting, "Factory starting");
|
||||||
|
var brb = MakeScene(SceneCatalog.Brb, "Factory BRB");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var store = new LayoutStore(path))
|
||||||
|
{
|
||||||
|
store.Save(new[] { starting, brb }, null, null);
|
||||||
|
store.PrepareLayoutSnapshots("build-a");
|
||||||
|
store.Save(new[]
|
||||||
|
{
|
||||||
|
MakeScene(starting.Id, starting.Name, "Edited starting"),
|
||||||
|
MakeScene(brb.Id, brb.Name, "Edited BRB"),
|
||||||
|
}, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var reopened = new LayoutStore(path))
|
||||||
|
{
|
||||||
|
reopened.PrepareLayoutSnapshots("build-a");
|
||||||
|
Assert.True(reopened.RestoreAllDefaults());
|
||||||
|
|
||||||
|
var scenes = reopened.Load();
|
||||||
|
Assert.Equal("Factory starting", Assert.Single(scenes.Single(s => s.Name == SceneCatalog.Starting).Elements.OfType<Source>()).Name);
|
||||||
|
Assert.Equal("Factory BRB", Assert.Single(scenes.Single(s => s.Name == SceneCatalog.Brb).Elements.OfType<Source>()).Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SqliteConnection.ClearAllPools();
|
||||||
|
try { File.Delete(path); } catch { /* best-effort cleanup */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Scene MakeScene(string sourceName)
|
private static Scene MakeScene(string sourceName)
|
||||||
=> MakeScene(SceneCatalog.Starting, sourceName);
|
=> MakeScene(SceneCatalog.Starting, sourceName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user