BililiveRecorder/BililiveRecorder.WPF/Controls/RoomCard.xaml.cs
2023-08-24 23:08:56 +08:00

76 lines
2.5 KiB
C#

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using BililiveRecorder.Core;
using BililiveRecorder.WPF.Pages;
#nullable enable
namespace BililiveRecorder.WPF.Controls
{
/// <summary>
/// Interaction logic for RoomCard.xaml
/// </summary>
public partial class RoomCard : UserControl
{
public RoomCard()
{
this.InitializeComponent();
}
public event EventHandler? DeleteRequested;
public event EventHandler? ShowSettingsRequested;
private void MenuItem_StartRecording_Click(object sender, RoutedEventArgs e) => (this.DataContext as IRoom)?.StartRecord();
private void MenuItem_StopRecording_Click(object sender, RoutedEventArgs e) => (this.DataContext as IRoom)?.StopRecord();
#pragma warning disable VSTHRD110 // Observe result of async calls
private void MenuItem_RefreshInfo_Click(object sender, RoutedEventArgs e) => (this.DataContext as IRoom)?.RefreshRoomInfoAsync();
#pragma warning restore VSTHRD110 // Observe result of async calls
private void MenuItem_StartMonitor_Click(object sender, RoutedEventArgs e)
{
if (this.DataContext is IRoom room)
room.RoomConfig.AutoRecord = true;
}
private void MenuItem_StopMonitor_Click(object sender, RoutedEventArgs e)
{
if (this.DataContext is IRoom room)
room.RoomConfig.AutoRecord = false;
}
private void MenuItem_DeleteRoom_Click(object sender, RoutedEventArgs e) => DeleteRequested?.Invoke(this.DataContext, EventArgs.Empty);
private void MenuItem_ShowSettings_Click(object sender, RoutedEventArgs e) => ShowSettingsRequested?.Invoke(this.DataContext, EventArgs.Empty);
private void Button_Split_Click(object sender, RoutedEventArgs e)
{
if (this.DataContext is IRoom room)
room.SplitOutput();
}
private void MenuItem_OpenInBrowser_Click(object sender, RoutedEventArgs e)
{
if (this.DataContext is IRoom r && r is not null)
{
try
{
Process.Start("https://live.bilibili.com/" + r.RoomConfig.RoomId);
}
catch (Exception) { }
}
}
private void MenuItem_ShowGlobalSettings_Click(object sender, RoutedEventArgs e)
{
if (RootPage.SwitchToSettingsPage is Action change)
{
change();
}
}
}
}