mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-30 23:34:09 +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
|
// bridge methods
|
||||||
|
|
||||||
public void PauseNotification() {
|
public void PauseNotification(NotificationPauseReason reason) {
|
||||||
notification.PauseNotification();
|
notification.PauseNotification(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResumeNotification() {
|
public void ResumeNotification(NotificationPauseReason reason) {
|
||||||
notification.ResumeNotification();
|
notification.ResumeNotification(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadToTweetDeck() {
|
public void ReloadToTweetDeck() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp.WinForms;
|
using CefSharp.WinForms;
|
||||||
@ -97,12 +98,12 @@ protected virtual FormBorderStyle NotificationBorderStyle {
|
|||||||
private readonly CefByteArrayResourceHandler resourceHandler = new CefByteArrayResourceHandler();
|
private readonly CefByteArrayResourceHandler resourceHandler = new CefByteArrayResourceHandler();
|
||||||
|
|
||||||
private DesktopNotification currentNotification;
|
private DesktopNotification currentNotification;
|
||||||
private int pauseCounter;
|
private readonly HashSet<NotificationPauseReason> pauseReasons = new HashSet<NotificationPauseReason>();
|
||||||
|
|
||||||
public string CurrentTweetUrl => currentNotification?.TweetUrl;
|
public string CurrentTweetUrl => currentNotification?.TweetUrl;
|
||||||
public string CurrentQuoteUrl => currentNotification?.QuoteUrl;
|
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));
|
protected internal bool IsCursorOverBrowser => browser.Bounds.Contains(PointToClient(Cursor.Position));
|
||||||
|
|
||||||
public bool FreezeTimer { get; set; }
|
public bool FreezeTimer { get; set; }
|
||||||
@ -171,16 +172,14 @@ public virtual void HideNotification() {
|
|||||||
|
|
||||||
public virtual void FinishCurrentNotification() {}
|
public virtual void FinishCurrentNotification() {}
|
||||||
|
|
||||||
public virtual void PauseNotification() {
|
public virtual void PauseNotification(NotificationPauseReason reason) {
|
||||||
if (pauseCounter++ == 0 && IsNotificationVisible) {
|
if (pauseReasons.Add(reason) && IsNotificationVisible) {
|
||||||
Location = ControlExtensions.InvisibleLocation;
|
Location = ControlExtensions.InvisibleLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ResumeNotification() {
|
public virtual void ResumeNotification(NotificationPauseReason reason) {
|
||||||
if (pauseCounter > 0) {
|
pauseReasons.Remove(reason);
|
||||||
--pauseCounter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void LoadTweet(DesktopNotification tweet) {
|
protected virtual void LoadTweet(DesktopNotification tweet) {
|
||||||
|
@ -242,19 +242,19 @@ public override void FinishCurrentNotification() {
|
|||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PauseNotification() {
|
public override void PauseNotification(NotificationPauseReason reason) {
|
||||||
if (!IsPaused) {
|
if (!IsPaused) {
|
||||||
pausedDuringNotification = IsNotificationVisible;
|
pausedDuringNotification = IsNotificationVisible;
|
||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
StopMouseHook(true);
|
StopMouseHook(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
base.PauseNotification();
|
base.PauseNotification(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ResumeNotification() {
|
public override void ResumeNotification(NotificationPauseReason reason) {
|
||||||
bool wasPaused = IsPaused;
|
bool wasPaused = IsPaused;
|
||||||
base.ResumeNotification();
|
base.ResumeNotification(reason);
|
||||||
|
|
||||||
if (wasPaused && !IsPaused && pausedDuringNotification) {
|
if (wasPaused && !IsPaused && pausedDuringNotification) {
|
||||||
OnNotificationReady();
|
OnNotificationReady();
|
||||||
|
@ -43,7 +43,7 @@ protected override bool CanDragWindow {
|
|||||||
Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
|
Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
|
||||||
|
|
||||||
if (Config.MuteNotifications) {
|
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) {
|
private void Config_MuteToggled(object sender, EventArgs e) {
|
||||||
if (Config.MuteNotifications) {
|
if (Config.MuteNotifications) {
|
||||||
PauseNotification();
|
PauseNotification(NotificationPauseReason.UserConfiguration);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ResumeNotification();
|
ResumeNotification(NotificationPauseReason.UserConfiguration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timerCursorCheck_Tick(object sender, EventArgs e) {
|
private void timerCursorCheck_Tick(object sender, EventArgs e) {
|
||||||
if (!IsCursorOverNotificationArea) {
|
if (!IsCursorOverNotificationArea) {
|
||||||
ResumeNotification();
|
ResumeNotification(NotificationPauseReason.CursorOverNotificationArea);
|
||||||
timerCursorCheck.Stop();
|
timerCursorCheck.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timerIdlePauseCheck_Tick(object sender, EventArgs e) {
|
private void timerIdlePauseCheck_Tick(object sender, EventArgs e) {
|
||||||
if (NativeMethods.GetIdleSeconds() < Config.NotificationIdlePauseSeconds) {
|
if (NativeMethods.GetIdleSeconds() < Config.NotificationIdlePauseSeconds) {
|
||||||
ResumeNotification();
|
ResumeNotification(NotificationPauseReason.SystemIdle);
|
||||||
timerIdlePauseCheck.Stop();
|
timerIdlePauseCheck.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,9 +123,9 @@ public override void FinishCurrentNotification() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ResumeNotification() {
|
public override void ResumeNotification(NotificationPauseReason reason) {
|
||||||
bool wasPaused = IsPaused;
|
bool wasPaused = IsPaused;
|
||||||
base.ResumeNotification();
|
base.ResumeNotification(reason);
|
||||||
|
|
||||||
if (wasPaused && !IsPaused && !pausedDuringNotification && tweetQueue.Count > 0) {
|
if (wasPaused && !IsPaused && !pausedDuringNotification && tweetQueue.Count > 0) {
|
||||||
LoadNextNotification();
|
LoadNextNotification();
|
||||||
@ -136,7 +136,7 @@ private void LoadNextNotification() {
|
|||||||
if (!IsNotificationVisible) {
|
if (!IsNotificationVisible) {
|
||||||
if (Config.NotificationNonIntrusiveMode && IsCursorOverNotificationArea && NativeMethods.GetIdleSeconds() < NonIntrusiveIdleLimit) {
|
if (Config.NotificationNonIntrusiveMode && IsCursorOverNotificationArea && NativeMethods.GetIdleSeconds() < NonIntrusiveIdleLimit) {
|
||||||
if (!timerCursorCheck.Enabled) {
|
if (!timerCursorCheck.Enabled) {
|
||||||
PauseNotification();
|
PauseNotification(NotificationPauseReason.CursorOverNotificationArea);
|
||||||
timerCursorCheck.Start();
|
timerCursorCheck.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ private void LoadNextNotification() {
|
|||||||
}
|
}
|
||||||
else if (Config.NotificationIdlePauseSeconds > 0 && NativeMethods.GetIdleSeconds() >= Config.NotificationIdlePauseSeconds) {
|
else if (Config.NotificationIdlePauseSeconds > 0 && NativeMethods.GetIdleSeconds() >= Config.NotificationIdlePauseSeconds) {
|
||||||
if (!timerIdlePauseCheck.Enabled) {
|
if (!timerIdlePauseCheck.Enabled) {
|
||||||
PauseNotification();
|
PauseNotification(NotificationPauseReason.SystemIdle);
|
||||||
timerIdlePauseCheck.Start();
|
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 System.Windows.Forms;
|
||||||
using TweetDuck.Browser;
|
using TweetDuck.Browser;
|
||||||
using TweetDuck.Browser.Handling;
|
using TweetDuck.Browser.Handling;
|
||||||
|
using TweetDuck.Browser.Notification;
|
||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Controls;
|
using TweetDuck.Controls;
|
||||||
using TweetDuck.Dialogs.Settings;
|
using TweetDuck.Dialogs.Settings;
|
||||||
@ -32,7 +33,7 @@ public FormSettings(FormBrowser browser, PluginManager plugins, UpdateChecker up
|
|||||||
Text = Program.BrandName + " Options";
|
Text = Program.BrandName + " Options";
|
||||||
|
|
||||||
this.browser = browser;
|
this.browser = browser;
|
||||||
this.browser.PauseNotification();
|
this.browser.PauseNotification(NotificationPauseReason.SettingsDialogOpen);
|
||||||
|
|
||||||
this.plugins = plugins;
|
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) {
|
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.ShowDialog() == DialogResult.OK) {
|
||||||
if (!dialog.IsRestarting) {
|
if (!dialog.IsRestarting) {
|
||||||
browser.ResumeNotification();
|
browser.ResumeNotification(NotificationPauseReason.SettingsDialogOpen);
|
||||||
|
|
||||||
if (dialog.ShouldReloadBrowser) {
|
if (dialog.ShouldReloadBrowser) {
|
||||||
BrowserProcessHandler.UpdatePrefs();
|
BrowserProcessHandler.UpdatePrefs();
|
||||||
|
@ -126,6 +126,7 @@
|
|||||||
<Compile Include="Browser\Notification\FormNotificationExample.cs">
|
<Compile Include="Browser\Notification\FormNotificationExample.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Browser\Notification\NotificationPauseReason.cs" />
|
||||||
<Compile Include="Browser\Notification\Screenshot\ScreenshotBridge.cs" />
|
<Compile Include="Browser\Notification\Screenshot\ScreenshotBridge.cs" />
|
||||||
<Compile Include="Browser\Notification\Screenshot\TweetScreenshotManager.cs" />
|
<Compile Include="Browser\Notification\Screenshot\TweetScreenshotManager.cs" />
|
||||||
<Compile Include="Browser\Notification\SoundNotification.cs" />
|
<Compile Include="Browser\Notification\SoundNotification.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user