Emby Toolbox 6264b487fe Initial commit: Emby Toolbox (conversion scroll fix, bulk Del for tracks).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 21:33:47 +05:00

77 lines
2.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using EmbyToolbox.Services;
namespace EmbyToolbox.ViewModels;
/// <summary>UI вкладки «Логи». Поток записей — <see cref="UiEntries"/> (тот же <see cref="LoggingService.UiEntries"/>, без дублирования).</summary>
public sealed class LogsViewModel : INotifyPropertyChanged
{
private readonly LoggingService _logging;
private int _scrollPulse;
public LogsViewModel(LoggingService logging)
{
_logging = logging;
RefreshLogViewCommand = new RelayCommand(ExecuteRefreshScroll);
OpenLogsFolderCommand = new RelayCommand(ExecuteOpenLogsFolder);
ClearUiLogCommand = new RelayCommand(ExecuteClearUiLog, () => UiEntries.Count > 0);
}
/// <summary>Инкремент для умного принудительного скролла вниз (кнопка «Обновить»).</summary>
public int ScrollPulse
{
get => _scrollPulse;
private set
{
if (_scrollPulse == value)
{
return;
}
_scrollPulse = value;
OnPropertyChanged();
}
}
/// <summary>Тот же <see cref="LoggingService.UiEntries"/>, что и у главного окна.</summary>
public ObservableCollection<LogEntryViewModel> UiEntries => _logging.UiEntries;
public RelayCommand RefreshLogViewCommand { get; }
public RelayCommand OpenLogsFolderCommand { get; }
public RelayCommand ClearUiLogCommand { get; }
public event PropertyChangedEventHandler? PropertyChanged;
private void ExecuteRefreshScroll() => ScrollPulse++;
private void ExecuteOpenLogsFolder()
{
Directory.CreateDirectory(_logging.LogsDirectory);
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = _logging.LogsDirectory,
UseShellExecute = true
});
_logging.Info("открыта папка логов", "ui.log");
}
private void ExecuteClearUiLog()
{
_logging.ClearUi();
_logging.Info("UI-лог очищен", "ui.log");
}
public void RaiseClearCommandState() =>
ClearUiLogCommand.RaiseCanExecuteChanged();
private void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}