mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-07-30 07:59:03 +02:00
Add 'Skip tweet' and 'Freeze' context menu options to notifications
This commit is contained in:
parent
24d8444043
commit
f6a4e39cfc
Core
@ -27,6 +27,8 @@ protected override bool ShowWithoutActivation{
|
||||
}
|
||||
}
|
||||
|
||||
public bool FreezeTimer { get; set; }
|
||||
|
||||
public FormNotification(Form owner, TweetDeckBridge bridge, bool autoHide){
|
||||
InitializeComponent();
|
||||
|
||||
@ -39,7 +41,7 @@ public FormNotification(Form owner, TweetDeckBridge bridge, bool autoHide){
|
||||
|
||||
notificationJS = ScriptLoader.LoadResource("notification.js");
|
||||
|
||||
browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new ContextMenuNotification() };
|
||||
browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new ContextMenuNotification(this,autoHide) };
|
||||
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||
|
||||
if (bridge != null){
|
||||
@ -69,18 +71,13 @@ protected override void WndProc(ref Message m){
|
||||
// event handlers
|
||||
|
||||
private void timerHideProgress_Tick(object sender, EventArgs e){
|
||||
if (Bounds.Contains(Cursor.Position))return;
|
||||
if (Bounds.Contains(Cursor.Position) || FreezeTimer)return;
|
||||
|
||||
timeLeft -= timerProgress.Interval;
|
||||
progressBarTimer.SetValueInstant((int)Math.Min(1000,Math.Round(1050.0*(totalTime-timeLeft)/totalTime)));
|
||||
|
||||
if (timeLeft <= 0){
|
||||
if (tweetQueue.Count > 0){
|
||||
LoadNextNotification();
|
||||
}
|
||||
else if (autoHide){
|
||||
HideNotification();
|
||||
}
|
||||
FinishCurrentTweet();
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +134,7 @@ public void ShowNotificationForSettings(bool reset){
|
||||
if (reset){
|
||||
browser.LoadHtml(TweetNotification.ExampleTweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
|
||||
|
||||
totalTime = timeLeft = TweetNotification.ExampleTweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
|
||||
ResetTimerValue(TweetNotification.ExampleTweet.GetDisplayDuration(Program.UserConfig.NotificationDuration));
|
||||
timerProgress.Start();
|
||||
}
|
||||
|
||||
@ -147,9 +144,19 @@ public void ShowNotificationForSettings(bool reset){
|
||||
public void HideNotification(){
|
||||
browser.LoadHtml("","about:blank");
|
||||
Location = new Point(-32000,-32000);
|
||||
progressBarTimer.Value = 0;
|
||||
timerProgress.Stop();
|
||||
}
|
||||
|
||||
public void FinishCurrentTweet(){
|
||||
if (tweetQueue.Count > 0){
|
||||
LoadNextNotification();
|
||||
}
|
||||
else if (autoHide){
|
||||
HideNotification();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadNextNotification(){
|
||||
TweetNotification tweet = tweetQueue.Dequeue();
|
||||
|
||||
@ -159,7 +166,7 @@ private void LoadNextNotification(){
|
||||
|
||||
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
|
||||
|
||||
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
|
||||
ResetTimerValue(tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration));
|
||||
timerProgress.Stop();
|
||||
timerProgress.Start();
|
||||
|
||||
@ -222,5 +229,10 @@ private void MoveToVisibleLocation(){
|
||||
private void UpdateTitle(){
|
||||
Text = tweetQueue.Count > 0 ? Program.BrandName+" ("+tweetQueue.Count+" more left)" : Program.BrandName;
|
||||
}
|
||||
|
||||
private void ResetTimerValue(int newTimeLeft){
|
||||
totalTime = timeLeft = newTimeLeft;
|
||||
progressBarTimer.Value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,49 @@
|
||||
using CefSharp;
|
||||
using TweetDck.Core.Controls;
|
||||
|
||||
namespace TweetDck.Core.Handling{
|
||||
class ContextMenuNotification : ContextMenuBase{
|
||||
private const int MenuSkipTweet = 26600;
|
||||
private const int MenuFreeze = 26601;
|
||||
|
||||
private readonly FormNotification form;
|
||||
private readonly bool enableCustomMenu;
|
||||
|
||||
public ContextMenuNotification(FormNotification form, bool enableCustomMenu){
|
||||
this.form = form;
|
||||
this.enableCustomMenu = enableCustomMenu;
|
||||
}
|
||||
|
||||
public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
||||
model.Clear();
|
||||
|
||||
if (enableCustomMenu){
|
||||
model.AddItem((CefMenuCommand)MenuSkipTweet,"Skip tweet");
|
||||
model.AddCheckItem((CefMenuCommand)MenuFreeze,"Freeze");
|
||||
model.SetChecked((CefMenuCommand)MenuFreeze,form.FreezeTimer);
|
||||
model.AddSeparator();
|
||||
}
|
||||
|
||||
base.OnBeforeContextMenu(browserControl,browser,frame,parameters,model);
|
||||
RemoveSeparatorIfLast(model);
|
||||
}
|
||||
|
||||
public override bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags){
|
||||
if (base.OnContextMenuCommand(browserControl,browser,frame,parameters,commandId,eventFlags)){
|
||||
return true;
|
||||
}
|
||||
|
||||
switch((int)commandId){
|
||||
case MenuSkipTweet:
|
||||
form.InvokeSafe(form.FinishCurrentTweet);
|
||||
return true;
|
||||
|
||||
case MenuFreeze:
|
||||
form.InvokeSafe(() => form.FreezeTimer = !form.FreezeTimer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user