BililiveRecorder/BililiveRecorder.WPF/App.xaml.cs

58 lines
2.0 KiB
C#
Raw Permalink Normal View History

2021-03-18 23:05:48 +08:00
using System;
2018-11-10 11:55:30 +08:00
using System.Windows;
2021-03-18 23:05:48 +08:00
using Microsoft.Win32;
using Serilog;
2018-03-12 18:57:20 +08:00
2021-02-23 18:03:37 +08:00
#nullable enable
2018-03-12 18:57:20 +08:00
namespace BililiveRecorder.WPF
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
2021-03-18 23:05:48 +08:00
private readonly ILogger loggerSystemEvents = Log.ForContext<SystemEvents>();
2020-12-05 18:27:54 +08:00
private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
2021-01-29 20:31:25 +08:00
if (e != null)
e.Cancel = true;
(Current.MainWindow as NewMainWindow)?.CloseWithoutConfirmAction();
2020-12-05 18:27:54 +08:00
}
2021-03-18 23:05:48 +08:00
private void Application_Startup(object sender, StartupEventArgs e)
{
try
{
SystemEvents.TimeChanged += this.SystemEvents_TimeChanged;
SystemEvents.SessionEnding += this.SystemEvents_SessionEnding;
SystemEvents.PowerModeChanged += this.SystemEvents_PowerModeChanged;
}
catch (Exception ex)
{
this.loggerSystemEvents.Error(ex, "Error attaching event");
}
}
private void Application_Exit(object sender, ExitEventArgs e)
{
try
{
SystemEvents.TimeChanged -= this.SystemEvents_TimeChanged;
SystemEvents.SessionEnding -= this.SystemEvents_SessionEnding;
SystemEvents.PowerModeChanged -= this.SystemEvents_PowerModeChanged;
}
catch (Exception ex)
{
this.loggerSystemEvents.Error(ex, "Error detaching event");
}
}
private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e) => this.loggerSystemEvents.Debug("SessionEnding {Reason}", e.Reason);
private void SystemEvents_TimeChanged(object sender, System.EventArgs e) => this.loggerSystemEvents.Debug("TimeChanged");
2021-05-01 17:57:43 +08:00
private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) => this.loggerSystemEvents.Debug("PowerModeChanged {Mode}", e.Mode);
2018-03-12 18:57:20 +08:00
}
}