From 5352f45b5c615a883f4a4d4e722e92a0b5b67691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=9D=E9=9B=B6?= <78294929+JiuLing-zhang@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:15:39 +0800 Subject: [PATCH] =?UTF-8?q?Windows=20=E9=94=81=E5=B1=8F=E6=97=B6=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E5=AE=9A=E6=97=B6=E9=94=81=E5=AE=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WindowMain.xaml.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/WindowMain.xaml.cs b/src/WindowMain.xaml.cs index 1684e73..9292dd2 100644 --- a/src/WindowMain.xaml.cs +++ b/src/WindowMain.xaml.cs @@ -4,6 +4,7 @@ using ComputerLock.Platforms; using ComputerLock.Resources; using JiuLing.CommonLibs.Log; +using Microsoft.Win32; namespace ComputerLock; public partial class WindowMain : Window, IDisposable @@ -54,6 +55,21 @@ public WindowMain(KeyboardHook keyboardHook, AppSettings appSettings, ILocker lo }; _logger.Write("自动锁定 -> 启动空闲检测"); _activityMonitor.StartMonitoring(); + + _logger.Write("自动锁定 -> 准备监控系统会话状态"); + SystemEvents.SessionSwitch += (_, e) => + { + if (e.Reason == SessionSwitchReason.SessionLock) + { + _logger.Write("Windows系统锁定 -> 暂停空闲检测"); + _activityMonitor.StopMonitoring(); + } + else if (e.Reason == SessionSwitchReason.SessionUnlock) + { + _logger.Write("Windows系统解锁 -> 启动空闲检测"); + _activityMonitor.StartMonitoring(); + } + }; } }