mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 18:15:47 +02:00
Refactor notification pausing code
This commit is contained in:
parent
933e0e54df
commit
cd02a03e8a
windows/TweetDuck
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
namespace TweetDuck.Browser.Notification {
|
||||
enum NotificationPauseReason {
|
||||
UserConfiguration,
|
||||
SettingsDialogOpen,
|
||||
WindowsSessionLocked,
|
||||
SystemIdle,
|
||||
CursorOverNotificationArea
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user