mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-30 14:34:09 +02:00
Move TweetDeckBridge properties to a separate JS object
This commit is contained in:
parent
6e4db4acea
commit
65a837a6e1
34
Core/Bridge/PropertyBridge.cs
Normal file
34
Core/Bridge/PropertyBridge.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21,24 +21,6 @@ public static void ResetStaticProperties(){
|
|||||||
private readonly FormBrowser form;
|
private readonly FormBrowser form;
|
||||||
private readonly FormNotification notification;
|
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){
|
public TweetDeckBridge(FormBrowser form, FormNotification notification){
|
||||||
this.form = form;
|
this.form = form;
|
||||||
this.notification = notification;
|
this.notification = notification;
|
||||||
|
@ -97,6 +97,8 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings)
|
|||||||
|
|
||||||
UpdateTrayIcon();
|
UpdateTrayIcon();
|
||||||
|
|
||||||
|
Config.MuteToggled += Config_MuteToggled;
|
||||||
|
|
||||||
this.updates = new UpdateHandler(browser, this, updaterSettings);
|
this.updates = new UpdateHandler(browser, this, updaterSettings);
|
||||||
this.updates.UpdateAccepted += updates_UpdateAccepted;
|
this.updates.UpdateAccepted += updates_UpdateAccepted;
|
||||||
this.updates.UpdateDismissed += updates_UpdateDismissed;
|
this.updates.UpdateDismissed += updates_UpdateDismissed;
|
||||||
@ -141,6 +143,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent
|
|||||||
|
|
||||||
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||||
if (e.Frame.IsMain && BrowserUtils.IsTweetDeckWebsite(e.Frame)){
|
if (e.Frame.IsMain && BrowserUtils.IsTweetDeckWebsite(e.Frame)){
|
||||||
|
UpdateProperties();
|
||||||
ScriptLoader.ExecuteFile(e.Frame, "code.js");
|
ScriptLoader.ExecuteFile(e.Frame, "code.js");
|
||||||
ReinjectCustomCSS(Config.CustomBrowserCSS);
|
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){
|
private void Config_TrayBehaviorChanged(object sender, EventArgs e){
|
||||||
if (!isLoaded)return;
|
if (!isLoaded)return;
|
||||||
|
|
||||||
@ -287,6 +294,10 @@ public void ReinjectCustomCSS(string css){
|
|||||||
browser.ExecuteScriptAsync("TDGF_reinjectCustomCSS", css == null ? string.Empty : css.Replace(Environment.NewLine, " "));
|
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
|
// callback handlers
|
||||||
|
|
||||||
public void OpenSettings(){
|
public void OpenSettings(){
|
||||||
@ -310,6 +321,8 @@ public void OpenSettings(){
|
|||||||
if (!Config.EnableTrayHighlight){
|
if (!Config.EnableTrayHighlight){
|
||||||
trayIcon.HasNotifications = false;
|
trayIcon.HasNotifications = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateProperties(PropertyBridge.Properties.ExpandLinksOnHover | PropertyBridge.Properties.HasCustomNotificationSound);
|
||||||
};
|
};
|
||||||
|
|
||||||
ShowChildForm(currentFormSettings);
|
ShowChildForm(currentFormSettings);
|
||||||
|
@ -238,6 +238,7 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent
|
|||||||
|
|
||||||
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||||
if (e.Frame.IsMain && notificationJS != null && browser.Address != "about:blank" && !flags.HasFlag(NotificationFlags.DisableScripts)){
|
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);
|
ScriptLoader.ExecuteScript(e.Frame, notificationJS, NotificationScriptIdentifier);
|
||||||
|
|
||||||
if (plugins != null && plugins.HasAnyPlugin(PluginEnvironment.Notification)){
|
if (plugins != null && plugins.HasAnyPlugin(PluginEnvironment.Notification)){
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(function($, $TD, TD){
|
(function($, $TD, $TDX, TD){
|
||||||
//
|
//
|
||||||
// Variable: Current highlighted column jQuery object.
|
// Variable: Current highlighted column jQuery object.
|
||||||
//
|
//
|
||||||
@ -199,7 +199,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($TD.expandLinksOnHover){
|
if ($TDX.expandLinksOnHover){
|
||||||
tooltipTimer = window.setTimeout(function(){
|
tooltipTimer = window.setTimeout(function(){
|
||||||
var expanded = me.attr("data-full-url");
|
var expanded = me.attr("data-full-url");
|
||||||
expanded = cutStart(expanded, "https://");
|
expanded = cutStart(expanded, "https://");
|
||||||
@ -218,7 +218,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e.type === "mouseleave"){
|
else if (e.type === "mouseleave"){
|
||||||
if ($TD.expandLinksOnHover){
|
if ($TDX.expandLinksOnHover){
|
||||||
var prevText = me.attr("td-prev-text");
|
var prevText = me.attr("td-prev-text");
|
||||||
|
|
||||||
if (prevText){
|
if (prevText){
|
||||||
@ -257,7 +257,7 @@
|
|||||||
var soundEle = document.getElementById("update-sound");
|
var soundEle = document.getElementById("update-sound");
|
||||||
|
|
||||||
soundEle.play = prependToFunction(soundEle.play, function(){
|
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);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(function($TD){
|
(function($TD, $TDX){
|
||||||
//
|
//
|
||||||
// Variable: Collection of all <a> tags.
|
// Variable: Collection of all <a> tags.
|
||||||
//
|
//
|
||||||
@ -51,7 +51,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($TD.expandLinksOnHover){
|
if ($TDX.expandLinksOnHover){
|
||||||
tooltipTimer = window.setTimeout(function(){
|
tooltipTimer = window.setTimeout(function(){
|
||||||
var expanded = url;
|
var expanded = url;
|
||||||
expanded = cutStart(expanded, "https://");
|
expanded = cutStart(expanded, "https://");
|
||||||
@ -73,7 +73,7 @@
|
|||||||
addEventListener(links, "mouseleave", function(e){
|
addEventListener(links, "mouseleave", function(e){
|
||||||
if (!e.currentTarget.hasAttribute("data-full-url"))return;
|
if (!e.currentTarget.hasAttribute("data-full-url"))return;
|
||||||
|
|
||||||
if ($TD.expandLinksOnHover){
|
if ($TDX.expandLinksOnHover){
|
||||||
var prevText = e.currentTarget.getAttribute("td-prev-text");
|
var prevText = e.currentTarget.getAttribute("td-prev-text");
|
||||||
|
|
||||||
if (prevText){
|
if (prevText){
|
||||||
@ -146,4 +146,4 @@
|
|||||||
document.body.addEventListener("mouseleave", function(){
|
document.body.addEventListener("mouseleave", function(){
|
||||||
document.body.classList.remove("td-hover");
|
document.body.classList.remove("td-hover");
|
||||||
});
|
});
|
||||||
})($TD);
|
})($TD, $TDX);
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Configuration\LockManager.cs" />
|
<Compile Include="Configuration\LockManager.cs" />
|
||||||
<Compile Include="Configuration\UserConfig.cs" />
|
<Compile Include="Configuration\UserConfig.cs" />
|
||||||
|
<Compile Include="Core\Bridge\PropertyBridge.cs" />
|
||||||
<Compile Include="Core\Controls\ControlExtensions.cs" />
|
<Compile Include="Core\Controls\ControlExtensions.cs" />
|
||||||
<Compile Include="Core\Controls\FlatButton.cs">
|
<Compile Include="Core\Controls\FlatButton.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
|
Loading…
Reference in New Issue
Block a user