Skip to content

Commit b921b91

Browse files
committed
程序关闭时释放钩子
1 parent 945a400 commit b921b91

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/WindowMain.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class WindowMain : Window
99
{
1010
private readonly KeyboardHook _keyboardHook;
1111
private readonly AppSettings _appSettings;
12-
private readonly UserActivityMonitor _activityMonitor;
12+
private readonly UserActivityMonitor? _activityMonitor;
1313
private readonly ILocker _locker;
1414

1515
private NotifyIcon _notifyIcon;
@@ -22,12 +22,12 @@ public WindowMain(KeyboardHook keyboardHook, AppSettings appSettings, ILocker lo
2222
_keyboardHook = keyboardHook;
2323
_appSettings = appSettings;
2424
_locker = locker;
25-
_activityMonitor = activityMonitor;
2625

2726
InitializeNotifyIcon();
2827

2928
if (_appSettings.AutoLockSecond != 0)
3029
{
30+
_activityMonitor = activityMonitor;
3131
_activityMonitor.SetAutoLockSecond(_appSettings.AutoLockSecond);
3232
_activityMonitor.OnIdle += (_, __) =>
3333
{
@@ -129,6 +129,7 @@ private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
129129
public void Dispose()
130130
{
131131
_notifyIcon.Visible = false;
132+
_activityMonitor?.StopMonitoring();
132133
_keyboardHook.Dispose();
133134
}
134135
}

0 commit comments

Comments
 (0)