releases/VideoDownloader.App/Browser/Tabs/TabItem.cs

59 lines
2.4 KiB
C#

using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.Web.WebView2.Wpf;
namespace VideoDownloader.App.Browser.Tabs;
/// <summary>탭 하나의 상태. View(WebView2 컨트롤)는 앱 레이어에서 주입한다(단위 테스트에선 null).</summary>
public sealed class TabItem : INotifyPropertyChanged
{
public Guid Id { get; } = Guid.NewGuid();
/// <summary>탭에 연결된 WebView2 컨트롤. 닫힌 탭 재오픈 시 재생성될 수 있음.</summary>
public WebView2? View { get; set; }
/// <summary>CoreWebView2 (초기화 전 null)</summary>
public Microsoft.Web.WebView2.Core.CoreWebView2? Core => View?.CoreWebView2;
private string _title = "새 탭";
public string Title { get => _title; set => Set(ref _title, value); }
private string _url = "";
public string Url { get => _url; set => Set(ref _url, value); }
private bool _isPinned;
public bool IsPinned { get => _isPinned; set => Set(ref _isPinned, value); }
private bool _isActive;
public bool IsActive { get => _isActive; set => Set(ref _isActive, value); }
private bool _isAudioPlaying;
public bool IsAudioPlaying { get => _isAudioPlaying; set => Set(ref _isAudioPlaying, value); }
private bool _isMuted;
public bool IsMuted { get => _isMuted; set => Set(ref _isMuted, value); }
private bool _isSuspended;
public bool IsSuspended { get => _isSuspended; set => Set(ref _isSuspended, value); }
private bool _isLoading;
public bool IsLoading { get => _isLoading; set => Set(ref _isLoading, value); }
/// <summary>마지막 활성 시각(탭 절전 판정용)</summary>
public DateTime LastActivated { get; set; } = DateTime.UtcNow;
/// <summary>닫힌 시점의 인덱스(닫힌 탭 복원용). 열려 있는 동안은 무의미.</summary>
internal int ClosedIndex { get; set; } = -1;
public event PropertyChangedEventHandler? PropertyChanged;
private void Set<T>(ref T field, T value, [CallerMemberName] string? name = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return;
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
/// <summary>세션 스냅샷(T1-10): 탭 URL 순서 + 활성 인덱스 + 핀 여부.</summary>
public sealed record SessionSnapshot(List<string> Urls, int ActiveIndex, List<bool> Pinned);