mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-22 00:22:18 -05:00
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.Win32;
|
|
|
|
namespace ColorControl.Shared.EventDispatcher;
|
|
|
|
public class SessionSwitchDispatcher : EventDispatcher<SessionSwitchEventArgs>
|
|
{
|
|
public const string Event_SessionSwitch = "SessionSwitch";
|
|
|
|
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
public bool UserLocalSession { get; private set; } = true;
|
|
public SessionSwitchReason LastSessionSwitchReason { get; private set; } = 0;
|
|
|
|
public SessionSwitchDispatcher()
|
|
{
|
|
SystemEvents.SessionSwitch += SessionSwitchHandler;
|
|
}
|
|
|
|
public void SessionSwitchHandler(object sender, SessionSwitchEventArgs evt)
|
|
{
|
|
if (evt.Reason == SessionSwitchReason.ConsoleDisconnect)
|
|
{
|
|
Logger.Debug("Detected a disconnect from the console");
|
|
UserLocalSession = false;
|
|
|
|
DispatchEvent(Event_SessionSwitch, evt);
|
|
}
|
|
else if (evt.Reason == SessionSwitchReason.ConsoleConnect)
|
|
{
|
|
Logger.Debug("Detected a connect to the console");
|
|
if (!UserLocalSession)
|
|
{
|
|
Logger.Debug("Session state switched to local");
|
|
UserLocalSession = true;
|
|
DispatchEvent(Event_SessionSwitch, evt);
|
|
}
|
|
}
|
|
LastSessionSwitchReason = evt.Reason;
|
|
}
|
|
}
|