Phase A logic: TabManager/TabItem/session store (TDD, 17 tests)
This commit is contained in:
parent
00a822eaeb
commit
603ad51406
4 changed files with 489 additions and 0 deletions
38
VideoDownloader.App/Browser/Tabs/TabSessionStore.cs
Normal file
38
VideoDownloader.App/Browser/Tabs/TabSessionStore.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoDownloader.App.Browser.Tabs;
|
||||
|
||||
/// <summary>세션 JSON 저장소(T1-10). 종료 시 탭 URL 저장, 시작 시 복원.</summary>
|
||||
public static class TabSessionStore
|
||||
{
|
||||
public static void Save(string path, SessionSnapshot snap)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir);
|
||||
var tmp = path + ".tmp";
|
||||
File.WriteAllText(tmp, JsonSerializer.Serialize(snap));
|
||||
File.Move(tmp, path, overwrite: true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static SessionSnapshot? Load(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path)) return null;
|
||||
var snap = JsonSerializer.Deserialize<SessionSnapshot>(File.ReadAllText(path));
|
||||
if (snap == null || snap.Urls == null || snap.Urls.Count == 0) return null;
|
||||
var pinned = snap.Pinned ?? new List<bool>();
|
||||
while (pinned.Count < snap.Urls.Count) pinned.Add(false);
|
||||
return snap with { Pinned = pinned };
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue