1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 02:34:06 +02:00

Implement notification timer pause on mouse hover

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ private static UserConfig Config{
public FormSettings(FormBrowser browserForm){
InitializeComponent();
notification = new FormNotification(browserForm);
notification = new FormNotification(browserForm,false);
notification.Show(this);
notification.Move += (sender, args) => {