diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 03dfa1f6..5866afcf 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -40,7 +40,15 @@ public FormBrowser(PluginManager pluginManager){ 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/"){ MenuHandler = new ContextMenuBrowser(this), @@ -62,14 +70,6 @@ public FormBrowser(PluginManager pluginManager){ 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.UpdateAccepted += updates_UpdateAccepted; } @@ -85,7 +85,7 @@ private void ForceClose(){ } public FormNotification CreateNotificationForm(bool autoHide){ - return new FormNotification(this,bridge,plugins,trayIcon,autoHide); + return new FormNotification(this,plugins,trayIcon,autoHide); } // window setup @@ -265,20 +265,11 @@ public void OpenPlugins(){ } } - public void OnTweetPopup(TweetNotification tweet){ - notification.ShowNotification(tweet); - } - public void OnTweetSound(){ } - public void DisplayTooltip(string text, bool showInNotification){ - if (showInNotification){ - notification.DisplayTooltip(text); - return; - } - + public void DisplayTooltip(string text){ if (string.IsNullOrEmpty(text)){ toolTip.Hide(this); } diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index 123ffdea..7892dfc7 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -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(); Text = Program.BrandName; @@ -96,7 +96,7 @@ public FormNotification(Form owner, TweetDeckBridge bridge, PluginManager plugin }; browser.FrameLoadEnd += Browser_FrameLoadEnd; - browser.RegisterJsObject("$TD",bridge); + browser.RegisterJsObject("$TD",new TweetDeckBridge(owner,this)); panelBrowser.Controls.Add(browser); @@ -122,7 +122,7 @@ private void timerHideProgress_Tick(object sender, EventArgs e){ if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen)return; 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){ FinishCurrentTweet(); @@ -135,7 +135,6 @@ private void Config_MuteToggled(object sender, EventArgs e){ } else{ if (tweetQueue.Count > 0){ - MoveToVisibleLocation(); LoadNextNotification(); } @@ -170,8 +169,6 @@ public void ShowNotification(TweetNotification notification){ trayIcon.HasNotifications = true; } else{ - MoveToVisibleLocation(); - tweetQueue.Enqueue(notification); UpdateTitle(); @@ -182,17 +179,12 @@ public void ShowNotification(TweetNotification notification){ } public void ShowNotificationForSettings(bool reset){ - if (browser.Address == "about:blank"){ - browser.Load("about:blank"); // required, otherwise shit breaks - reset = true; - } - - if (reset){ + if (reset || browser.Address == "about:blank"){ LoadTweet(TweetNotification.ExampleTweet); - timerProgress.Start(); } - - MoveToVisibleLocation(); + else{ + MoveToVisibleLocation(); + } } public void HideNotification(){ @@ -202,6 +194,12 @@ public void HideNotification(){ timerProgress.Stop(); } + public void OnNotificationReady(){ + UpdateTitle(); + MoveToVisibleLocation(); + timerProgress.Start(); + } + public void FinishCurrentTweet(){ if (tweetQueue.Count > 0){ LoadNextNotification(); @@ -215,26 +213,17 @@ public void FinishCurrentTweet(){ } private void LoadNextNotification(){ - TweetNotification tweet = tweetQueue.Dequeue(); - - if (browser.Address == "about:blank"){ - browser.Load("about:blank"); // required, otherwise shit breaks - } - - LoadTweet(tweet); - timerProgress.Stop(); - timerProgress.Start(); - - UpdateTitle(); + LoadTweet(tweetQueue.Dequeue()); } 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); progressBarTimer.Value = 0; - CurrentUrl = tweet.Url; + browser.LoadHtml(tweet.GenerateHtml(),"http://tweetdeck.twitter.com/?"+DateTime.Now.Ticks); } private void MoveToVisibleLocation(){ diff --git a/Core/Handling/TweetDeckBridge.cs b/Core/Handling/TweetDeckBridge.cs index a971f500..d94e32ea 100644 --- a/Core/Handling/TweetDeckBridge.cs +++ b/Core/Handling/TweetDeckBridge.cs @@ -15,6 +15,7 @@ class TweetDeckBridge{ public static string ClipboardImagePath = string.Empty; private readonly FormBrowser form; + private readonly FormNotification notification; public string BrandName{ get{ @@ -40,8 +41,9 @@ public bool ExpandLinksOnHover{ } } - public TweetDeckBridge(FormBrowser form){ + public TweetDeckBridge(FormBrowser form, FormNotification notification){ this.form = form; + this.notification = notification; } public void LoadFontSizeClass(string fsClass){ @@ -80,8 +82,8 @@ public void OpenPluginsMenu(){ } public void OnTweetPopup(string tweetHtml, string tweetUrl, int tweetCharacters){ - form.InvokeSafe(() => { - form.OnTweetPopup(new TweetNotification(tweetHtml,tweetUrl,tweetCharacters)); + notification.InvokeSafe(() => { + notification.ShowNotification(new TweetNotification(tweetHtml,tweetUrl,tweetCharacters)); }); } @@ -89,10 +91,17 @@ public void OnTweetSound(){ form.InvokeSafe(form.OnTweetSound); } + public void OnNotificationReady(){ + notification.InvokeSafe(notification.OnNotificationReady); + } + public void DisplayTooltip(string text, bool showInNotification){ - form.InvokeSafe(() => { - form.DisplayTooltip(text,showInNotification); - }); + if (showInNotification){ + notification.InvokeSafe(() => notification.DisplayTooltip(text)); + } + else{ + form.InvokeSafe(() => form.DisplayTooltip(text)); + } } public void TryPasteImage(){ diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index 9278a139..8f0db947 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -94,7 +94,7 @@ })(); // - // Block: Setup embedded tweet address for context menu + // Block: Setup embedded tweet address for context menu. // (function(){ var embedded = document.getElementsByClassName("quoted-tweet"); @@ -108,4 +108,9 @@ $TD.setNotificationTweetEmbedded(account[0].getAttribute("href")+"/status/"+tweetId); })(); + + // + // Block: Page fully loaded. + // + $TD.onNotificationReady(); })($TD); \ No newline at end of file