diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 4d8cc3e0..b167ea33 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -38,7 +38,7 @@ public FormBrowser(){ Controls.Add(browser); - notification = new FormNotification(this,true); + notification = new FormNotification(this,bridge,true); notification.Show(); } diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index ffd7b782..c225c62c 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using TweetDick.Core.Handling; using TweetDick.Configuration; +using TweetDick.Resources; namespace TweetDick.Core{ partial class FormNotification : Form{ @@ -16,7 +17,9 @@ partial class FormNotification : Form{ private readonly bool autoHide; private int timeLeft, totalTime; - public FormNotification(Form owner, bool autoHide){ + private readonly string notificationJS; + + public FormNotification(Form owner, TweetDeckBridge bridge, bool autoHide){ InitializeComponent(); this.owner = owner; @@ -24,10 +27,26 @@ public FormNotification(Form owner, bool autoHide){ owner.FormClosed += (sender, args) => Close(); + notificationJS = ScriptLoader.LoadResource("notification.js"); + browser = new ChromiumWebBrowser("about:blank"){ MenuHandler = new MenuHandlerEmpty() }; + browser.FrameLoadEnd += Browser_FrameLoadEnd; + + if (bridge != null){ + browser.RegisterJsObject("$TD",bridge); + } + panelBrowser.Controls.Add(browser); } + public FormNotification(Form owner, bool autoHide) : this(owner,null,autoHide){} + + private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ + if (e.Frame.IsMain && notificationJS != null){ + browser.ExecuteScriptAsync(notificationJS); + } + } + public void ShowNotification(TweetNotification notification){ MoveToVisibleLocation(); diff --git a/Resources/notification.js b/Resources/notification.js new file mode 100644 index 00000000..711b3a11 --- /dev/null +++ b/Resources/notification.js @@ -0,0 +1,11 @@ +(function($TD){ + // + // Block: Hook into links to bypass default open function + // + document.body.addEventListener("click",function(e){ + if (e.target.tagName == "A"){ + $TD.openBrowser(e.target.getAttribute("href")); + e.preventDefault(); + } + }); +})($TD); \ No newline at end of file diff --git a/TweetDick.csproj b/TweetDick.csproj index 82da8f6c..bfebfb20 100644 --- a/TweetDick.csproj +++ b/TweetDick.csproj @@ -200,6 +200,12 @@ <SubType>Designer</SubType> </EmbeddedResource> </ItemGroup> + <ItemGroup> + <ContentWithTargetPath Include="Resources\notification.js"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <TargetPath>notification.js</TargetPath> + </ContentWithTargetPath> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup>