Files
vova 24ca481b64 Support local file paths for M3U playlists; UI tweaks
Added support for loading M3U playlists from both web URLs and local file paths, with logic to resolve relative paths. Improved exception handling in M3UParser. Enabled toggling of window border style in fullscreen mode, with data binding for WindowStyle. Removed IsValidUrl check to allow local file sources in settings. Cleaned up usings and formatting. Removed .NET SDK version from global.json.
2026-04-10 12:48:12 +03:00

118 lines
3.2 KiB
C#

using CommunityToolkit.Mvvm.Input;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using TV_Player.ViewModels;
namespace TV_Player
{
public class MainViewModel : ObservableViewModelBase
{
private ContentControl? _control;
public ContentControl? Control
{
get => _control;
set => SetProperty(ref _control, value);
}
private bool _isTopPanelVisible;
public bool IsTopPanelVisible
{
get => _isTopPanelVisible;
set => SetProperty(ref _isTopPanelVisible, value);
}
private string _topPaneTitle;
public string TopPanelTitle
{
get => _topPaneTitle;
set => SetProperty(ref _topPaneTitle, value);
}
private WindowState _currentWindowState;
public WindowState CurrentWindowState
{
get => _currentWindowState;
set => SetProperty(ref _currentWindowState, value);
}
private WindowStyle _currentWindowStyle;
public WindowStyle CurrentWindowStyle
{
get => _currentWindowStyle;
set => SetProperty(ref _currentWindowStyle, value);
}
public ICommand OnKeyDownCommand { get; }
public ICommand FullscreenCommand { get; }
public ICommand CloseAppCommand { get; }
public Action ButtonBackAction { get; set; }
public ICommand BackCommand { get; }
public ICommand SettingsCommand{ get; }
public MainViewModel()
{
OnKeyDownCommand = new RelayCommand<KeyEventArgs>(OnKeyDown);
BackCommand = new RelayCommand(OnButtonBackClick);
FullscreenCommand = new RelayCommand(OnFullSctreenButtonClick);
SettingsCommand = new RelayCommand(OnSettingsButtonClick);
CloseAppCommand = new RelayCommand(OnCloseAppButtonClick);
CurrentWindowStyle = WindowStyle.SingleBorderWindow;
}
public void OnFullSctreenButtonClick()
{
if (CurrentWindowState == WindowState.Normal)
{
CurrentWindowState = WindowState.Maximized;
CurrentWindowStyle = WindowStyle.None;
}
else
{
CurrentWindowState = WindowState.Normal;
CurrentWindowStyle = WindowStyle.SingleBorderWindow;
}
}
public void OnCloseAppButtonClick()
{
if (Application.Current?.MainWindow is Window window)
{
window.Close(); // Allows proper shutdown sequence
}
else
{
Environment.Exit(0); // Fallback if window not available
}
}
private void OnButtonBackClick()
{
ButtonBackAction?.Invoke();
}
private void OnSettingsButtonClick()
{
TVPlayerViewModel.Instance.ShowSettingsScreen();
}
private void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
Environment.Exit(0);
}
if (e.Key == Key.Back)
{
ButtonBackAction?.Invoke();
}
}
}
}