mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-29 03:15:51 +02:00
Pause notifications when Windows is on lock screen
This commit is contained in:
parent
cd02a03e8a
commit
dd6776fef4
windows/TweetDuck
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using TweetDuck.Management;
|
||||||
using TweetDuck.Utils;
|
using TweetDuck.Utils;
|
||||||
using TweetLib.Browser.Interfaces;
|
using TweetLib.Browser.Interfaces;
|
||||||
using TweetLib.Core.Features.Notifications;
|
using TweetLib.Core.Features.Notifications;
|
||||||
@ -40,13 +41,27 @@ protected override bool CanDragWindow {
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Config.MuteToggled += Config_MuteToggled;
|
Config.MuteToggled += Config_MuteToggled;
|
||||||
Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
|
WindowsSessionManager.LockStateChanged += WindowsSessionManager_LockStateChanged;
|
||||||
|
|
||||||
|
Disposed += (sender, args) => {
|
||||||
|
Config.MuteToggled -= Config_MuteToggled;
|
||||||
|
WindowsSessionManager.LockStateChanged -= WindowsSessionManager_LockStateChanged;
|
||||||
|
};
|
||||||
|
|
||||||
if (Config.MuteNotifications) {
|
if (Config.MuteNotifications) {
|
||||||
PauseNotification(NotificationPauseReason.UserConfiguration);
|
PauseNotification(NotificationPauseReason.UserConfiguration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WindowsSessionManager_LockStateChanged(object sender, EventArgs e) {
|
||||||
|
if (WindowsSessionManager.IsLocked) {
|
||||||
|
PauseNotification(NotificationPauseReason.WindowsSessionLocked);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ResumeNotification(NotificationPauseReason.WindowsSessionLocked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void WndProc(ref Message m) {
|
protected override void WndProc(ref Message m) {
|
||||||
if (m.Msg == 0x00A7) { // WM_NCMBUTTONDOWN
|
if (m.Msg == 0x00A7) { // WM_NCMBUTTONDOWN
|
||||||
int hitTest = m.WParam.ToInt32();
|
int hitTest = m.WParam.ToInt32();
|
||||||
|
34
windows/TweetDuck/Management/WindowsSessionManager.cs
Normal file
34
windows/TweetDuck/Management/WindowsSessionManager.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using Win = System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TweetDuck.Management {
|
||||||
|
static class WindowsSessionManager {
|
||||||
|
public static bool IsLocked { get; private set; } = false;
|
||||||
|
public static event EventHandler LockStateChanged;
|
||||||
|
|
||||||
|
public static void Register() {
|
||||||
|
Win.Application.ApplicationExit += OnApplicationExit;
|
||||||
|
SystemEvents.SessionSwitch += OnSessionSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnApplicationExit(object sender, EventArgs e) {
|
||||||
|
SystemEvents.SessionSwitch -= OnSessionSwitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnSessionSwitch(object sender, SessionSwitchEventArgs e) {
|
||||||
|
var reason = e.Reason;
|
||||||
|
if (reason == SessionSwitchReason.SessionLock) {
|
||||||
|
SetLocked(true);
|
||||||
|
}
|
||||||
|
else if (reason == SessionSwitchReason.SessionUnlock) {
|
||||||
|
SetLocked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetLocked(bool newState) {
|
||||||
|
IsLocked = newState;
|
||||||
|
LockStateChanged?.Invoke(null, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@ internal static void SetupWinForms() {
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main() {
|
private static void Main() {
|
||||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||||
|
WindowsSessionManager.Register();
|
||||||
|
|
||||||
SetupWinForms();
|
SetupWinForms();
|
||||||
Cef.EnableHighDPISupport();
|
Cef.EnableHighDPISupport();
|
||||||
|
@ -141,6 +141,7 @@
|
|||||||
<Compile Include="Management\LockManager.cs" />
|
<Compile Include="Management\LockManager.cs" />
|
||||||
<Compile Include="Management\ProfileManager.cs" />
|
<Compile Include="Management\ProfileManager.cs" />
|
||||||
<Compile Include="Management\VideoPlayer.cs" />
|
<Compile Include="Management\VideoPlayer.cs" />
|
||||||
|
<Compile Include="Management\WindowsSessionManager.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Reporter.cs" />
|
<Compile Include="Reporter.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user