diff --git a/Core/Bridge/PropertyBridge.cs b/Core/Bridge/PropertyBridge.cs new file mode 100644 index 00000000..31f70bb6 --- /dev/null +++ b/Core/Bridge/PropertyBridge.cs @@ -0,0 +1,34 @@ +using System; +using System.Text; + +namespace TweetDck.Core.Bridge{ + static class PropertyBridge{ + [Flags] + public enum Properties{ + ExpandLinksOnHover = 1, + MuteNotifications = 2, + HasCustomNotificationSound = 4, // TODO changes if the file is deleted + All = ExpandLinksOnHover | MuteNotifications | HasCustomNotificationSound + } + + public static string GenerateScript(Properties properties = Properties.All){ + StringBuilder build = new StringBuilder(); + build.Append("(function(c){"); + + if (properties.HasFlag(Properties.ExpandLinksOnHover)){ + build.Append("c.expandLinksOnHover=").Append(Program.UserConfig.ExpandLinksOnHover ? "true;" : "false;"); + } + + if (properties.HasFlag(Properties.MuteNotifications)){ + build.Append("c.muteNotifications=").Append(Program.UserConfig.MuteNotifications ? "true;" : "false;"); + } + + if (properties.HasFlag(Properties.HasCustomNotificationSound)){ + build.Append("c.hasCustomNotificationSound=").Append(!string.IsNullOrEmpty(Program.UserConfig.NotificationSoundPath) ? "true;" : "false;"); + } + + build.Append("})(window.$TDX=window.$TDX||{})"); + return build.ToString(); + } + } +} diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs index b132b5b7..ec1ba5e0 100644 --- a/Core/Bridge/TweetDeckBridge.cs +++ b/Core/Bridge/TweetDeckBridge.cs @@ -21,24 +21,6 @@ public static void ResetStaticProperties(){ private readonly FormBrowser form; private readonly FormNotification notification; - public bool MuteNotifications{ - get{ - return Program.UserConfig.MuteNotifications; - } - } - - public bool HasCustomNotificationSound{ - get{ - return !string.IsNullOrEmpty(Program.UserConfig.NotificationSoundPath); - } - } - - public bool ExpandLinksOnHover{ - get{ - return Program.UserConfig.ExpandLinksOnHover; - } - } - public TweetDeckBridge(FormBrowser form, FormNotification notification){ this.form = form; this.notification = notification; diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 0dc81856..ac6e57ea 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -97,6 +97,8 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings) UpdateTrayIcon(); + Config.MuteToggled += Config_MuteToggled; + this.updates = new UpdateHandler(browser, this, updaterSettings); this.updates.UpdateAccepted += updates_UpdateAccepted; this.updates.UpdateDismissed += updates_UpdateDismissed; @@ -141,6 +143,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ if (e.Frame.IsMain && BrowserUtils.IsTweetDeckWebsite(e.Frame)){ + UpdateProperties(); ScriptLoader.ExecuteFile(e.Frame, "code.js"); ReinjectCustomCSS(Config.CustomBrowserCSS); @@ -199,6 +202,10 @@ private void FormBrowser_FormClosing(object sender, FormClosingEventArgs e){ } } + private void Config_MuteToggled(object sender, EventArgs e){ + UpdateProperties(PropertyBridge.Properties.MuteNotifications); + } + private void Config_TrayBehaviorChanged(object sender, EventArgs e){ if (!isLoaded)return; @@ -287,6 +294,10 @@ public void ReinjectCustomCSS(string css){ browser.ExecuteScriptAsync("TDGF_reinjectCustomCSS", css == null ? string.Empty : css.Replace(Environment.NewLine, " ")); } + public void UpdateProperties(PropertyBridge.Properties properties = PropertyBridge.Properties.All){ + browser.ExecuteScriptAsync(PropertyBridge.GenerateScript(properties)); + } + // callback handlers public void OpenSettings(){ @@ -310,6 +321,8 @@ public void OpenSettings(){ if (!Config.EnableTrayHighlight){ trayIcon.HasNotifications = false; } + + UpdateProperties(PropertyBridge.Properties.ExpandLinksOnHover | PropertyBridge.Properties.HasCustomNotificationSound); }; ShowChildForm(currentFormSettings); diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index 911c74dd..73e855e9 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -238,6 +238,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ if (e.Frame.IsMain && notificationJS != null && browser.Address != "about:blank" && !flags.HasFlag(NotificationFlags.DisableScripts)){ + e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Properties.ExpandLinksOnHover)); ScriptLoader.ExecuteScript(e.Frame, notificationJS, NotificationScriptIdentifier); if (plugins != null && plugins.HasAnyPlugin(PluginEnvironment.Notification)){ diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js index a76d5ebf..d9722637 100644 --- a/Resources/Scripts/code.js +++ b/Resources/Scripts/code.js @@ -1,4 +1,4 @@ -(function($, $TD, TD){ +(function($, $TD, $TDX, TD){ // // Variable: Current highlighted column jQuery object. // @@ -199,7 +199,7 @@ return; } - if ($TD.expandLinksOnHover){ + if ($TDX.expandLinksOnHover){ tooltipTimer = window.setTimeout(function(){ var expanded = me.attr("data-full-url"); expanded = cutStart(expanded, "https://"); @@ -218,7 +218,7 @@ } } else if (e.type === "mouseleave"){ - if ($TD.expandLinksOnHover){ + if ($TDX.expandLinksOnHover){ var prevText = me.attr("td-prev-text"); if (prevText){ @@ -257,7 +257,7 @@ var soundEle = document.getElementById("update-sound"); soundEle.play = prependToFunction(soundEle.play, function(){ - return $TD.muteNotifications || $TD.hasCustomNotificationSound; + return $TDX.muteNotifications || $TDX.hasCustomNotificationSound; }); })(); @@ -554,4 +554,4 @@ } }; })(); -})($, $TD, TD); +})($, $TD, $TDX, TD); diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index cf98b096..15c15f05 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -1,4 +1,4 @@ -(function($TD){ +(function($TD, $TDX){ // // Variable: Collection of all <a> tags. // @@ -51,7 +51,7 @@ return; } - if ($TD.expandLinksOnHover){ + if ($TDX.expandLinksOnHover){ tooltipTimer = window.setTimeout(function(){ var expanded = url; expanded = cutStart(expanded, "https://"); @@ -73,7 +73,7 @@ addEventListener(links, "mouseleave", function(e){ if (!e.currentTarget.hasAttribute("data-full-url"))return; - if ($TD.expandLinksOnHover){ + if ($TDX.expandLinksOnHover){ var prevText = e.currentTarget.getAttribute("td-prev-text"); if (prevText){ @@ -146,4 +146,4 @@ document.body.addEventListener("mouseleave", function(){ document.body.classList.remove("td-hover"); }); -})($TD); +})($TD, $TDX); diff --git a/TweetDck.csproj b/TweetDck.csproj index 877cb079..0a8a3040 100644 --- a/TweetDck.csproj +++ b/TweetDck.csproj @@ -71,6 +71,7 @@ <ItemGroup> <Compile Include="Configuration\LockManager.cs" /> <Compile Include="Configuration\UserConfig.cs" /> + <Compile Include="Core\Bridge\PropertyBridge.cs" /> <Compile Include="Core\Controls\ControlExtensions.cs" /> <Compile Include="Core\Controls\FlatButton.cs"> <SubType>Component</SubType>