using System.Windows.Data;
using Microsoft.Web.WebView2.Core;
namespace VideoDownloader.App.Browser.Features;
/// CoreWebView2DownloadOperation → IDownloadOperation 어댑터.
public sealed class DownloadOperationAdapter : IDownloadOperation
{
private readonly CoreWebView2DownloadOperation _op;
public DownloadOperationAdapter(CoreWebView2DownloadOperation op) => _op = op;
public string Uri => _op.Uri ?? "";
public string FileName => Path.GetFileName(_op.ResultFilePath ?? "");
public long BytesReceived => (long)_op.BytesReceived;
public long TotalBytesToReceive => (long)(_op.TotalBytesToReceive ?? 0);
public string State => _op.State.ToString();
public void Pause() => _op.Pause();
public void Resume() => _op.Resume();
public void Cancel() => _op.Cancel();
public event Action? Changed
{
add { _op.BytesReceivedChanged += (_, _) => value?.Invoke(); _op.StateChanged += (_, _) => value?.Invoke(); }
remove { }
}
}
/// 탭 검색 결과의 IsClosed → "닫힘" 라벨 변환.
public sealed class BoolToClosedConverter : IValueConverter
{
public static readonly BoolToClosedConverter Instance = new();
public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
=> value is true ? "닫힘 · 클릭해서 복원" : "";
public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
=> throw new NotSupportedException();
}
/// 그룹 색상 HEX → Color / 표시 여부 변환 (탭 그룹 바).
public sealed class StringToBrushConverter : System.Windows.Data.IValueConverter
{
public static readonly StringToBrushConverter Conv = new();
public static readonly StringToBrushConverter VisibleIf = new();
public object Convert(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
{
var hex = value as string;
if (ReferenceEquals(this, VisibleIf))
return string.IsNullOrWhiteSpace(hex) ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
try
{
var c = System.Windows.Media.ColorConverter.ConvertFromString(hex ?? "#5b8def");
return c is System.Windows.Media.Color col ? col : System.Windows.Media.Colors.Gray;
}
catch { return System.Windows.Media.Colors.Gray; }
}
public object ConvertBack(object? value, Type targetType, object? parameter, System.Globalization.CultureInfo culture)
=> throw new NotSupportedException();
}