mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 00:15:48 +02:00
Refactor PropertyBridge
This commit is contained in:
parent
c686349922
commit
f181f1fadc
Core
@ -1,50 +1,32 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace TweetDuck.Core.Bridge{
|
||||
static class PropertyBridge{
|
||||
[Flags]
|
||||
public enum Properties{
|
||||
ExpandLinksOnHover = 1,
|
||||
MuteNotifications = 2,
|
||||
HasCustomNotificationSound = 4,
|
||||
SkipOnLinkClick = 8,
|
||||
SwitchAccountSelectors = 16,
|
||||
NotificationMediaPreviews = 32,
|
||||
AllBrowser = ExpandLinksOnHover | SwitchAccountSelectors | MuteNotifications | HasCustomNotificationSound | NotificationMediaPreviews,
|
||||
AllNotification = ExpandLinksOnHover | SkipOnLinkClick
|
||||
public enum Environment{
|
||||
Browser, Notification
|
||||
}
|
||||
|
||||
public static string GenerateScript(Properties properties){
|
||||
StringBuilder build = new StringBuilder();
|
||||
build.Append("(function(c){");
|
||||
|
||||
if (properties.HasFlag(Properties.ExpandLinksOnHover)){
|
||||
build.Append("c.expandLinksOnHover=").Append(Program.UserConfig.ExpandLinksOnHover ? "true;" : "false;");
|
||||
public static string GenerateScript(Environment environment){
|
||||
string Bool(bool value){
|
||||
return value ? "true," : "false,";
|
||||
}
|
||||
|
||||
if (properties.HasFlag(Properties.SwitchAccountSelectors)){
|
||||
build.Append("c.switchAccountSelectors=").Append(Program.UserConfig.SwitchAccountSelectors ? "true;" : "false;");
|
||||
StringBuilder build = new StringBuilder().Append("window.$TDX={");
|
||||
|
||||
build.Append("expandLinksOnHover:").Append(Bool(Program.UserConfig.ExpandLinksOnHover));
|
||||
|
||||
if (environment == Environment.Browser){
|
||||
build.Append("switchAccountSelectors:").Append(Bool(Program.UserConfig.SwitchAccountSelectors));
|
||||
build.Append("muteNotifications:").Append(Bool(Program.UserConfig.MuteNotifications));
|
||||
build.Append("hasCustomNotificationSound:").Append(Bool(Program.UserConfig.NotificationSoundPath.Length > 0));
|
||||
build.Append("notificationMediaPreviews:").Append(Bool(Program.UserConfig.NotificationMediaPreviews));
|
||||
}
|
||||
|
||||
if (properties.HasFlag(Properties.MuteNotifications)){
|
||||
build.Append("c.muteNotifications=").Append(Program.UserConfig.MuteNotifications ? "true;" : "false;");
|
||||
if (environment == Environment.Notification){
|
||||
build.Append("skipOnLinkClick:").Append(Bool(Program.UserConfig.NotificationSkipOnLinkClick));
|
||||
}
|
||||
|
||||
if (properties.HasFlag(Properties.HasCustomNotificationSound)){
|
||||
build.Append("c.hasCustomNotificationSound=").Append(Program.UserConfig.NotificationSoundPath.Length > 0 ? "true;" : "false;");
|
||||
}
|
||||
|
||||
if (properties.HasFlag(Properties.NotificationMediaPreviews)){
|
||||
build.Append("c.notificationMediaPreviews=").Append(Program.UserConfig.NotificationMediaPreviews ? "true;" : "false;");
|
||||
}
|
||||
|
||||
if (properties.HasFlag(Properties.SkipOnLinkClick)){
|
||||
build.Append("c.skipOnLinkClick=").Append(Program.UserConfig.NotificationSkipOnLinkClick ? "true;" : "false;");
|
||||
}
|
||||
|
||||
build.Append("})(window.$TDX=window.$TDX||{})");
|
||||
return build.ToString();
|
||||
|
||||
return build.Append("}").ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
|
||||
if (e.Frame.IsMain && TwitterUtils.IsTweetDeckWebsite(e.Frame)){
|
||||
e.Frame.ExecuteJavaScriptAsync(TwitterUtils.BackgroundColorFix);
|
||||
|
||||
UpdateProperties(PropertyBridge.Properties.AllBrowser);
|
||||
UpdateProperties(PropertyBridge.Environment.Browser);
|
||||
ScriptLoader.ExecuteFile(e.Frame, "code.js");
|
||||
ReinjectCustomCSS(Config.CustomBrowserCSS);
|
||||
|
||||
@ -304,7 +304,7 @@ private void FormBrowser_FormClosed(object sender, FormClosedEventArgs e){
|
||||
}
|
||||
|
||||
private void Config_MuteToggled(object sender, EventArgs e){
|
||||
UpdateProperties(PropertyBridge.Properties.MuteNotifications);
|
||||
UpdateProperties(PropertyBridge.Environment.Browser);
|
||||
}
|
||||
|
||||
private void Config_ZoomLevelChanged(object sender, EventArgs e){
|
||||
@ -423,8 +423,8 @@ public void ReinjectCustomCSS(string css){
|
||||
browser.ExecuteScriptAsync("TDGF_reinjectCustomCSS", css?.Replace(Environment.NewLine, " ") ?? string.Empty);
|
||||
}
|
||||
|
||||
public void UpdateProperties(PropertyBridge.Properties properties){
|
||||
browser.ExecuteScriptAsync(PropertyBridge.GenerateScript(properties));
|
||||
public void UpdateProperties(PropertyBridge.Environment environment){
|
||||
browser.ExecuteScriptAsync(PropertyBridge.GenerateScript(environment));
|
||||
}
|
||||
|
||||
public void ReloadToTweetDeck(){
|
||||
@ -464,7 +464,7 @@ public void OpenSettings(Type startTab){
|
||||
memoryUsageTracker.Stop();
|
||||
}
|
||||
|
||||
UpdateProperties(PropertyBridge.Properties.ExpandLinksOnHover | PropertyBridge.Properties.SwitchAccountSelectors | PropertyBridge.Properties.HasCustomNotificationSound | PropertyBridge.Properties.NotificationMediaPreviews);
|
||||
UpdateProperties(PropertyBridge.Environment.Browser);
|
||||
|
||||
notification.RequiresResize = true;
|
||||
form.Dispose();
|
||||
|
@ -167,7 +167,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"){
|
||||
e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Properties.AllNotification));
|
||||
e.Frame.ExecuteJavaScriptAsync(PropertyBridge.GenerateScript(PropertyBridge.Environment.Notification));
|
||||
ScriptLoader.ExecuteScript(e.Frame, NotificationJS, NotificationScriptIdentifier);
|
||||
|
||||
if (plugins.HasAnyPlugin(PluginEnvironment.Notification)){
|
||||
|
Loading…
Reference in New Issue
Block a user