mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-02 20:34:07 +02:00
Rewrite notification bridge handling and add OnNotificationReady to show notification after it has loaded
This commit is contained in:
parent
a7e222f2e7
commit
b4fc522f37
@ -40,7 +40,15 @@ public FormBrowser(PluginManager pluginManager){
|
|||||||
|
|
||||||
Text = Program.BrandName;
|
Text = Program.BrandName;
|
||||||
|
|
||||||
bridge = new TweetDeckBridge(this);
|
plugins = pluginManager;
|
||||||
|
plugins.Reloaded += plugins_Reloaded;
|
||||||
|
plugins.Config.PluginChangedState += plugins_PluginChangedState;
|
||||||
|
|
||||||
|
notification = CreateNotificationForm(true);
|
||||||
|
notification.CanMoveWindow = () => false;
|
||||||
|
notification.Show();
|
||||||
|
|
||||||
|
bridge = new TweetDeckBridge(this,notification);
|
||||||
|
|
||||||
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
|
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/"){
|
||||||
MenuHandler = new ContextMenuBrowser(this),
|
MenuHandler = new ContextMenuBrowser(this),
|
||||||
@ -62,14 +70,6 @@ public FormBrowser(PluginManager pluginManager){
|
|||||||
|
|
||||||
UpdateTrayIcon();
|
UpdateTrayIcon();
|
||||||
|
|
||||||
plugins = pluginManager;
|
|
||||||
plugins.Reloaded += plugins_Reloaded;
|
|
||||||
plugins.Config.PluginChangedState += plugins_PluginChangedState;
|
|
||||||
|
|
||||||
notification = CreateNotificationForm(true);
|
|
||||||
notification.CanMoveWindow = () => false;
|
|
||||||
notification.Show();
|
|
||||||
|
|
||||||
updates = new UpdateHandler(browser,this);
|
updates = new UpdateHandler(browser,this);
|
||||||
updates.UpdateAccepted += updates_UpdateAccepted;
|
updates.UpdateAccepted += updates_UpdateAccepted;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ private void ForceClose(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FormNotification CreateNotificationForm(bool autoHide){
|
public FormNotification CreateNotificationForm(bool autoHide){
|
||||||
return new FormNotification(this,bridge,plugins,trayIcon,autoHide);
|
return new FormNotification(this,plugins,trayIcon,autoHide);
|
||||||
}
|
}
|
||||||
|
|
||||||
// window setup
|
// window setup
|
||||||
@ -265,20 +265,11 @@ public void OpenPlugins(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnTweetPopup(TweetNotification tweet){
|
|
||||||
notification.ShowNotification(tweet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnTweetSound(){
|
public void OnTweetSound(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisplayTooltip(string text, bool showInNotification){
|
public void DisplayTooltip(string text){
|
||||||
if (showInNotification){
|
|
||||||
notification.DisplayTooltip(text);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(text)){
|
if (string.IsNullOrEmpty(text)){
|
||||||
toolTip.Hide(this);
|
toolTip.Hide(this);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ private static int BaseClientHeight{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugins, TrayIcon trayIcon, bool autoHide){
|
public FormNotification(FormBrowser owner, PluginManager plugins, TrayIcon trayIcon, bool autoHide){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Text = Program.BrandName;
|
Text = Program.BrandName;
|
||||||
@ -96,7 +96,7 @@ public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugin
|
|||||||
};
|
};
|
||||||
|
|
||||||
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
browser.FrameLoadEnd += Browser_FrameLoadEnd;
|
||||||
browser.RegisterJsObject("$TD",bridge);
|
browser.RegisterJsObject("$TD",new TweetDeckBridge(owner,this));
|
||||||
|
|
||||||
panelBrowser.Controls.Add(browser);
|
panelBrowser.Controls.Add(browser);
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ private void timerHideProgress_Tick(object sender, EventArgs e){
|
|||||||
if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen)return;
|
if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen)return;
|
||||||
|
|
||||||
timeLeft -= timerProgress.Interval;
|
timeLeft -= timerProgress.Interval;
|
||||||
progressBarTimer.SetValueInstant((int)Math.Min(1000,Math.Round(1050.0*(totalTime-timeLeft)/totalTime)));
|
progressBarTimer.SetValueInstant((int)Math.Min(1000,Math.Round(1025.0*(totalTime-timeLeft)/totalTime)));
|
||||||
|
|
||||||
if (timeLeft <= 0){
|
if (timeLeft <= 0){
|
||||||
FinishCurrentTweet();
|
FinishCurrentTweet();
|
||||||
@ -135,7 +135,6 @@ private void Config_MuteToggled(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (tweetQueue.Count > 0){
|
if (tweetQueue.Count > 0){
|
||||||
MoveToVisibleLocation();
|
|
||||||
LoadNextNotification();
|
LoadNextNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +169,6 @@ public void ShowNotification(TweetNotification notification){
|
|||||||
trayIcon.HasNotifications = true;
|
trayIcon.HasNotifications = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
MoveToVisibleLocation();
|
|
||||||
|
|
||||||
tweetQueue.Enqueue(notification);
|
tweetQueue.Enqueue(notification);
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
|
|
||||||
@ -182,17 +179,12 @@ public void ShowNotification(TweetNotification notification){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ShowNotificationForSettings(bool reset){
|
public void ShowNotificationForSettings(bool reset){
|
||||||
if (browser.Address == "about:blank"){
|
if (reset || browser.Address == "about:blank"){
|
||||||
browser.Load("about:blank"); // required, otherwise shit breaks
|
|
||||||
reset = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reset){
|
|
||||||
LoadTweet(TweetNotification.ExampleTweet);
|
LoadTweet(TweetNotification.ExampleTweet);
|
||||||
timerProgress.Start();
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
MoveToVisibleLocation();
|
MoveToVisibleLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideNotification(){
|
public void HideNotification(){
|
||||||
@ -202,6 +194,12 @@ public void HideNotification(){
|
|||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnNotificationReady(){
|
||||||
|
UpdateTitle();
|
||||||
|
MoveToVisibleLocation();
|
||||||
|
timerProgress.Start();
|
||||||
|
}
|
||||||
|
|
||||||
public void FinishCurrentTweet(){
|
public void FinishCurrentTweet(){
|
||||||
if (tweetQueue.Count > 0){
|
if (tweetQueue.Count > 0){
|
||||||
LoadNextNotification();
|
LoadNextNotification();
|
||||||
@ -215,26 +213,17 @@ public void FinishCurrentTweet(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void LoadNextNotification(){
|
private void LoadNextNotification(){
|
||||||
TweetNotification tweet = tweetQueue.Dequeue();
|
LoadTweet(tweetQueue.Dequeue());
|
||||||
|
|
||||||
if (browser.Address == "about:blank"){
|
|
||||||
browser.Load("about:blank"); // required, otherwise shit breaks
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadTweet(tweet);
|
|
||||||
timerProgress.Stop();
|
|
||||||
timerProgress.Start();
|
|
||||||
|
|
||||||
UpdateTitle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadTweet(TweetNotification tweet){
|
private void LoadTweet(TweetNotification tweet){
|
||||||
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/");
|
CurrentUrl = tweet.Url;
|
||||||
|
|
||||||
|
timerProgress.Stop();
|
||||||
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
|
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDuration);
|
||||||
progressBarTimer.Value = 0;
|
progressBarTimer.Value = 0;
|
||||||
|
|
||||||
CurrentUrl = tweet.Url;
|
browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/?"+DateTime.Now.Ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MoveToVisibleLocation(){
|
private void MoveToVisibleLocation(){
|
||||||
|
@ -15,6 +15,7 @@ class TweetDeckBridge{
|
|||||||
public static string ClipboardImagePath = string.Empty;
|
public static string ClipboardImagePath = string.Empty;
|
||||||
|
|
||||||
private readonly FormBrowser form;
|
private readonly FormBrowser form;
|
||||||
|
private readonly FormNotification notification;
|
||||||
|
|
||||||
public string BrandName{
|
public string BrandName{
|
||||||
get{
|
get{
|
||||||
@ -40,8 +41,9 @@ public bool ExpandLinksOnHover{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TweetDeckBridge(FormBrowser form){
|
public TweetDeckBridge(FormBrowser form, FormNotification notification){
|
||||||
this.form = form;
|
this.form = form;
|
||||||
|
this.notification = notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFontSizeClass(string fsClass){
|
public void LoadFontSizeClass(string fsClass){
|
||||||
@ -80,8 +82,8 @@ public void OpenPluginsMenu(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnTweetPopup(string tweetHtml, string tweetUrl, int tweetCharacters){
|
public void OnTweetPopup(string tweetHtml, string tweetUrl, int tweetCharacters){
|
||||||
form.InvokeSafe(() => {
|
notification.InvokeSafe(() => {
|
||||||
form.OnTweetPopup(new TweetNotification(tweetHtml,tweetUrl,tweetCharacters));
|
notification.ShowNotification(new TweetNotification(tweetHtml,tweetUrl,tweetCharacters));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,10 +91,17 @@ public void OnTweetSound(){
|
|||||||
form.InvokeSafe(form.OnTweetSound);
|
form.InvokeSafe(form.OnTweetSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnNotificationReady(){
|
||||||
|
notification.InvokeSafe(notification.OnNotificationReady);
|
||||||
|
}
|
||||||
|
|
||||||
public void DisplayTooltip(string text, bool showInNotification){
|
public void DisplayTooltip(string text, bool showInNotification){
|
||||||
form.InvokeSafe(() => {
|
if (showInNotification){
|
||||||
form.DisplayTooltip(text,showInNotification);
|
notification.InvokeSafe(() => notification.DisplayTooltip(text));
|
||||||
});
|
}
|
||||||
|
else{
|
||||||
|
form.InvokeSafe(() => form.DisplayTooltip(text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TryPasteImage(){
|
public void TryPasteImage(){
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Block: Setup embedded tweet address for context menu
|
// Block: Setup embedded tweet address for context menu.
|
||||||
//
|
//
|
||||||
(function(){
|
(function(){
|
||||||
var embedded = document.getElementsByClassName("quoted-tweet");
|
var embedded = document.getElementsByClassName("quoted-tweet");
|
||||||
@ -108,4 +108,9 @@
|
|||||||
|
|
||||||
$TD.setNotificationTweetEmbedded(account[0].getAttribute("href")+"/status/"+tweetId);
|
$TD.setNotificationTweetEmbedded(account[0].getAttribute("href")+"/status/"+tweetId);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Block: Page fully loaded.
|
||||||
|
//
|
||||||
|
$TD.onNotificationReady();
|
||||||
})($TD);
|
})($TD);
|
Loading…
Reference in New Issue
Block a user