1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-25 23:35:16 +02:00

Implement notification timer pause on mouse hover

This commit is contained in:
2016-04-11 15:58:36 +02:00
parent 113247a06c
commit 17645a88cf
4 changed files with 31 additions and 41 deletions

@@ -36,7 +36,7 @@ namespace TweetDick.Core{
Controls.Add(browser); Controls.Add(browser);
notification = new FormNotification(this); notification = new FormNotification(this,true);
notification.Show(this); notification.Show(this);
} }

@@ -24,16 +24,11 @@
/// </summary> /// </summary>
private void InitializeComponent() { private void InitializeComponent() {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.timerNext = new System.Windows.Forms.Timer(this.components);
this.panelBrowser = new System.Windows.Forms.Panel(); this.panelBrowser = new System.Windows.Forms.Panel();
this.timerHideProgress = new System.Windows.Forms.Timer(this.components); this.timerProgress = new System.Windows.Forms.Timer(this.components);
this.progressBarTimer = new TweetDick.Core.Controls.FlatProgressBar(); this.progressBarTimer = new TweetDick.Core.Controls.FlatProgressBar();
this.SuspendLayout(); this.SuspendLayout();
// //
// timerNext
//
this.timerNext.Tick += new System.EventHandler(this.timer_Tick);
//
// panelBrowser // panelBrowser
// //
this.panelBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.panelBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@@ -45,10 +40,10 @@
this.panelBrowser.Size = new System.Drawing.Size(284, 118); this.panelBrowser.Size = new System.Drawing.Size(284, 118);
this.panelBrowser.TabIndex = 0; this.panelBrowser.TabIndex = 0;
// //
// timerHideProgress // timerProgress
// //
this.timerHideProgress.Interval = 16; this.timerProgress.Interval = 16;
this.timerHideProgress.Tick += new System.EventHandler(this.timerHideProgress_Tick); this.timerProgress.Tick += new System.EventHandler(this.timerHideProgress_Tick);
// //
// progressBarTimer // progressBarTimer
// //
@@ -82,9 +77,8 @@
#endregion #endregion
private System.Windows.Forms.Timer timerNext;
private System.Windows.Forms.Panel panelBrowser; private System.Windows.Forms.Panel panelBrowser;
private Controls.FlatProgressBar progressBarTimer; private Controls.FlatProgressBar progressBarTimer;
private System.Windows.Forms.Timer timerHideProgress; private System.Windows.Forms.Timer timerProgress;
} }
} }

@@ -13,12 +13,14 @@ namespace TweetDick.Core{
private readonly ChromiumWebBrowser browser; private readonly ChromiumWebBrowser browser;
private readonly Queue<TweetNotification> tweetQueue = new Queue<TweetNotification>(4); private readonly Queue<TweetNotification> tweetQueue = new Queue<TweetNotification>(4);
private DateTime timeLeftStart; private int timeLeft, totalTime;
private bool autoHide;
public FormNotification(Form owner){ public FormNotification(Form owner, bool autoHide){
InitializeComponent(); InitializeComponent();
this.owner = owner; this.owner = owner;
this.autoHide = autoHide;
browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new MenuHandlerEmpty() }; browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new MenuHandlerEmpty() };
panelBrowser.Controls.Add(browser); panelBrowser.Controls.Add(browser);
@@ -29,7 +31,7 @@ namespace TweetDick.Core{
tweetQueue.Enqueue(notification); tweetQueue.Enqueue(notification);
if (!timerNext.Enabled){ if (!timerProgress.Enabled){
LoadNextNotification(); LoadNextNotification();
} }
} }
@@ -41,10 +43,8 @@ namespace TweetDick.Core{
} }
if (resetAnimation){ if (resetAnimation){
timerNext.Interval = TweetNotification.ExampleTweet.GetDisplayDuration(Program.UserConfig.NotificationDuration); totalTime = timeLeft = TweetNotification.ExampleTweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
timeLeftStart = DateTime.Now; timerProgress.Start();
timerHideProgress.Stop();
timerHideProgress.Start();
} }
MoveToVisibleLocation(); MoveToVisibleLocation();
@@ -53,9 +53,7 @@ namespace TweetDick.Core{
public void HideNotification(){ public void HideNotification(){
browser.LoadHtml("","about:blank"); browser.LoadHtml("","about:blank");
Location = new Point(32000,32000); Location = new Point(32000,32000);
timerProgress.Stop();
timerNext.Stop();
timerHideProgress.Stop();
} }
private void LoadNextNotification(){ private void LoadNextNotification(){
@@ -64,13 +62,9 @@ namespace TweetDick.Core{
browser.Load("about:blank"); browser.Load("about:blank");
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/"); browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
timerNext.Stop(); totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
timerNext.Interval = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration); timerProgress.Stop();
timerNext.Start(); timerProgress.Start();
timeLeftStart = DateTime.Now;
timerHideProgress.Stop();
timerHideProgress.Start();
} }
private void MoveToVisibleLocation(){ private void MoveToVisibleLocation(){
@@ -107,18 +101,20 @@ namespace TweetDick.Core{
} }
} }
private void timer_Tick(object sender, EventArgs e){
if (tweetQueue.Count > 0){
LoadNextNotification();
}
else{
HideNotification();
}
}
private void timerHideProgress_Tick(object sender, EventArgs e){ private void timerHideProgress_Tick(object sender, EventArgs e){
int elapsed = (int)(DateTime.Now-timeLeftStart).TotalMilliseconds; if (Bounds.Contains(Cursor.Position))return;
progressBarTimer.SetValueInstant((int)Math.Min(1000,Math.Round(1001.0*elapsed/timerNext.Interval)));
timeLeft -= timerProgress.Interval;
progressBarTimer.SetValueInstant((int)Math.Min(1000,Math.Round(1001.0*(totalTime-timeLeft)/totalTime)));
if (timeLeft <= 0){
if (tweetQueue.Count > 0){
LoadNextNotification();
}
else if (autoHide){
HideNotification();
}
}
} }
private void FormNotification_FormClosing(object sender, FormClosingEventArgs e){ private void FormNotification_FormClosing(object sender, FormClosingEventArgs e){

@@ -16,7 +16,7 @@ namespace TweetDick.Core.Other{
public FormSettings(FormBrowser browserForm){ public FormSettings(FormBrowser browserForm){
InitializeComponent(); InitializeComponent();
notification = new FormNotification(browserForm); notification = new FormNotification(browserForm,false);
notification.Show(this); notification.Show(this);
notification.Move += (sender, args) => { notification.Move += (sender, args) => {