BililiveRecorder/BililiveRecorder.WPF/NewMainWindow.xaml.cs
Genteure 0344adfa32 updates
copy pdb on build
fix crash
log sort room
update text on settings page
add betaid as userid
change log file name
change log level
2020-12-19 17:27:45 +08:00

100 lines
3.0 KiB
C#

using System;
using System.Threading;
using System.Windows;
using BililiveRecorder.WPF.Controls;
using Hardcodet.Wpf.TaskbarNotification;
using ModernWpf.Controls;
namespace BililiveRecorder.WPF
{
/// <summary>
/// Interaction logic for NewMainWindow.xaml
/// </summary>
public partial class NewMainWindow : Window
{
public NewMainWindow()
{
InitializeComponent();
Title = "B站录播姬 " + BuildInfo.Version + " " + BuildInfo.HeadShaShort;
SingleInstance.NotificationReceived += SingleInstance_NotificationReceived;
}
private void SingleInstance_NotificationReceived(object sender, EventArgs e) => SuperActivateAction();
public event EventHandler NativeBeforeWindowClose;
internal Action<string, string, BalloonIcon> ShowBalloonTipCallback { get; set; }
internal void CloseWithoutConfirmAction()
{
CloseConfirmed = true;
Close();
}
internal void SuperActivateAction()
{
try
{
Show();
WindowState = WindowState.Normal;
Topmost = true;
Activate();
Topmost = false;
Focus();
}
catch (Exception)
{ }
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Hide();
ShowBalloonTipCallback?.Invoke("B站录播姬", "录播姬已最小化到托盘,左键单击图标恢复界面", BalloonIcon.Info);
}
}
#region Confirm Close Window
private bool CloseConfirmed = false;
private readonly SemaphoreSlim CloseWindowSemaphoreSlim = new SemaphoreSlim(1, 1);
public bool PromptCloseConfirm { get; set; } = true;
private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (PromptCloseConfirm && !CloseConfirmed)
{
e.Cancel = true;
if (CloseWindowSemaphoreSlim.Wait(0))
{
try
{
if (await new CloseWindowConfirmDialog().ShowAsync() == ContentDialogResult.Primary)
{
CloseConfirmed = true;
CloseWindowSemaphoreSlim.Release();
Close();
return;
}
}
catch (Exception) { }
CloseWindowSemaphoreSlim.Release();
}
}
else
{
SingleInstance.NotificationReceived -= SingleInstance_NotificationReceived;
NativeBeforeWindowClose?.Invoke(this, EventArgs.Empty);
return;
}
}
#endregion
}
}