diff --git a/windows/TweetDuck/Browser/FormBrowser.cs b/windows/TweetDuck/Browser/FormBrowser.cs index 697bc19a..e7aad6e2 100644 --- a/windows/TweetDuck/Browser/FormBrowser.cs +++ b/windows/TweetDuck/Browser/FormBrowser.cs @@ -335,12 +335,12 @@ protected override void WndProc(ref Message m) { // bridge methods - public void PauseNotification() { - notification.PauseNotification(); + public void PauseNotification(NotificationPauseReason reason) { + notification.PauseNotification(reason); } - public void ResumeNotification() { - notification.ResumeNotification(); + public void ResumeNotification(NotificationPauseReason reason) { + notification.ResumeNotification(reason); } public void ReloadToTweetDeck() { diff --git a/windows/TweetDuck/Browser/Notification/FormNotificationBase.cs b/windows/TweetDuck/Browser/Notification/FormNotificationBase.cs index 913dc51a..40121290 100644 --- a/windows/TweetDuck/Browser/Notification/FormNotificationBase.cs +++ b/windows/TweetDuck/Browser/Notification/FormNotificationBase.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System.Collections.Generic; +using System.Drawing; using System.Text; using System.Windows.Forms; using CefSharp.WinForms; @@ -97,12 +98,12 @@ protected virtual FormBorderStyle NotificationBorderStyle { private readonly CefByteArrayResourceHandler resourceHandler = new CefByteArrayResourceHandler(); private DesktopNotification currentNotification; - private int pauseCounter; + private readonly HashSet<NotificationPauseReason> pauseReasons = new HashSet<NotificationPauseReason>(); public string CurrentTweetUrl => currentNotification?.TweetUrl; public string CurrentQuoteUrl => currentNotification?.QuoteUrl; - protected bool IsPaused => pauseCounter > 0; + protected bool IsPaused => pauseReasons.Count > 0; protected internal bool IsCursorOverBrowser => browser.Bounds.Contains(PointToClient(Cursor.Position)); public bool FreezeTimer { get; set; } @@ -171,16 +172,14 @@ public virtual void HideNotification() { public virtual void FinishCurrentNotification() {} - public virtual void PauseNotification() { - if (pauseCounter++ == 0 && IsNotificationVisible) { + public virtual void PauseNotification(NotificationPauseReason reason) { + if (pauseReasons.Add(reason) && IsNotificationVisible) { Location = ControlExtensions.InvisibleLocation; } } - public virtual void ResumeNotification() { - if (pauseCounter > 0) { - --pauseCounter; - } + public virtual void ResumeNotification(NotificationPauseReason reason) { + pauseReasons.Remove(reason); } protected virtual void LoadTweet(DesktopNotification tweet) { diff --git a/windows/TweetDuck/Browser/Notification/FormNotificationMain.cs b/windows/TweetDuck/Browser/Notification/FormNotificationMain.cs index 12a6790e..997184d9 100644 --- a/windows/TweetDuck/Browser/Notification/FormNotificationMain.cs +++ b/windows/TweetDuck/Browser/Notification/FormNotificationMain.cs @@ -242,19 +242,19 @@ public override void FinishCurrentNotification() { timerProgress.Stop(); } - public override void PauseNotification() { + public override void PauseNotification(NotificationPauseReason reason) { if (!IsPaused) { pausedDuringNotification = IsNotificationVisible; timerProgress.Stop(); StopMouseHook(true); } - base.PauseNotification(); + base.PauseNotification(reason); } - public override void ResumeNotification() { + public override void ResumeNotification(NotificationPauseReason reason) { bool wasPaused = IsPaused; - base.ResumeNotification(); + base.ResumeNotification(reason); if (wasPaused && !IsPaused && pausedDuringNotification) { OnNotificationReady(); diff --git a/windows/TweetDuck/Browser/Notification/FormNotificationTweet.cs b/windows/TweetDuck/Browser/Notification/FormNotificationTweet.cs index a4b79bad..540ecbec 100644 --- a/windows/TweetDuck/Browser/Notification/FormNotificationTweet.cs +++ b/windows/TweetDuck/Browser/Notification/FormNotificationTweet.cs @@ -43,7 +43,7 @@ protected override bool CanDragWindow { Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled; if (Config.MuteNotifications) { - PauseNotification(); + PauseNotification(NotificationPauseReason.UserConfiguration); } } @@ -65,23 +65,23 @@ protected override void WndProc(ref Message m) { private void Config_MuteToggled(object sender, EventArgs e) { if (Config.MuteNotifications) { - PauseNotification(); + PauseNotification(NotificationPauseReason.UserConfiguration); } else { - ResumeNotification(); + ResumeNotification(NotificationPauseReason.UserConfiguration); } } private void timerCursorCheck_Tick(object sender, EventArgs e) { if (!IsCursorOverNotificationArea) { - ResumeNotification(); + ResumeNotification(NotificationPauseReason.CursorOverNotificationArea); timerCursorCheck.Stop(); } } private void timerIdlePauseCheck_Tick(object sender, EventArgs e) { if (NativeMethods.GetIdleSeconds() < Config.NotificationIdlePauseSeconds) { - ResumeNotification(); + ResumeNotification(NotificationPauseReason.SystemIdle); timerIdlePauseCheck.Stop(); } } @@ -123,9 +123,9 @@ public override void FinishCurrentNotification() { } } - public override void ResumeNotification() { + public override void ResumeNotification(NotificationPauseReason reason) { bool wasPaused = IsPaused; - base.ResumeNotification(); + base.ResumeNotification(reason); if (wasPaused && !IsPaused && !pausedDuringNotification && tweetQueue.Count > 0) { LoadNextNotification(); @@ -136,7 +136,7 @@ private void LoadNextNotification() { if (!IsNotificationVisible) { if (Config.NotificationNonIntrusiveMode && IsCursorOverNotificationArea && NativeMethods.GetIdleSeconds() < NonIntrusiveIdleLimit) { if (!timerCursorCheck.Enabled) { - PauseNotification(); + PauseNotification(NotificationPauseReason.CursorOverNotificationArea); timerCursorCheck.Start(); } @@ -144,7 +144,7 @@ private void LoadNextNotification() { } else if (Config.NotificationIdlePauseSeconds > 0 && NativeMethods.GetIdleSeconds() >= Config.NotificationIdlePauseSeconds) { if (!timerIdlePauseCheck.Enabled) { - PauseNotification(); + PauseNotification(NotificationPauseReason.SystemIdle); timerIdlePauseCheck.Start(); } diff --git a/windows/TweetDuck/Browser/Notification/NotificationPauseReason.cs b/windows/TweetDuck/Browser/Notification/NotificationPauseReason.cs new file mode 100644 index 00000000..9ea12758 --- /dev/null +++ b/windows/TweetDuck/Browser/Notification/NotificationPauseReason.cs @@ -0,0 +1,9 @@ +namespace TweetDuck.Browser.Notification { + enum NotificationPauseReason { + UserConfiguration, + SettingsDialogOpen, + WindowsSessionLocked, + SystemIdle, + CursorOverNotificationArea + } +} diff --git a/windows/TweetDuck/Dialogs/FormSettings.cs b/windows/TweetDuck/Dialogs/FormSettings.cs index a651a263..50451874 100644 --- a/windows/TweetDuck/Dialogs/FormSettings.cs +++ b/windows/TweetDuck/Dialogs/FormSettings.cs @@ -4,6 +4,7 @@ using System.Windows.Forms; using TweetDuck.Browser; using TweetDuck.Browser.Handling; +using TweetDuck.Browser.Notification; using TweetDuck.Configuration; using TweetDuck.Controls; using TweetDuck.Dialogs.Settings; @@ -32,7 +33,7 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateChecker up Text = Program.BrandName + " Options"; this.browser = browser; - this.browser.PauseNotification(); + this.browser.PauseNotification(NotificationPauseReason.SettingsDialogOpen); this.plugins = plugins; @@ -76,7 +77,7 @@ private void FormSettings_FormClosing(object sender, FormClosingEventArgs e) { } } - browser.ResumeNotification(); + browser.ResumeNotification(NotificationPauseReason.SettingsDialogOpen); } private void btnManageOptions_Click(object sender, EventArgs e) { @@ -87,7 +88,7 @@ private void btnManageOptions_Click(object sender, EventArgs e) { if (dialog.ShowDialog() == DialogResult.OK) { if (!dialog.IsRestarting) { - browser.ResumeNotification(); + browser.ResumeNotification(NotificationPauseReason.SettingsDialogOpen); if (dialog.ShouldReloadBrowser) { BrowserProcessHandler.UpdatePrefs(); diff --git a/windows/TweetDuck/TweetDuck.csproj b/windows/TweetDuck/TweetDuck.csproj index 119774cd..2e0ac95b 100644 --- a/windows/TweetDuck/TweetDuck.csproj +++ b/windows/TweetDuck/TweetDuck.csproj @@ -126,6 +126,7 @@ <Compile Include="Browser\Notification\FormNotificationExample.cs"> <SubType>Form</SubType> </Compile> + <Compile Include="Browser\Notification\NotificationPauseReason.cs" /> <Compile Include="Browser\Notification\Screenshot\ScreenshotBridge.cs" /> <Compile Include="Browser\Notification\Screenshot\TweetScreenshotManager.cs" /> <Compile Include="Browser\Notification\SoundNotification.cs" />