diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index 1582574b..e95f19ca 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -140,7 +140,7 @@ protected FormNotificationBase(FormBrowser owner, bool enableContextMenu){ DpiScale = this.GetDPIScale(); browser.SetupResourceHandler(TwitterUtils.TweetDeckURL, this.resourceHandler); - browser.SetupResourceHandler(TweetNotification.AppLogoLink, TweetNotification.AppLogoHandler); + browser.SetupResourceHandler(TweetNotification.AppLogo); Controls.Add(browser); diff --git a/Core/Notification/TweetNotification.cs b/Core/Notification/TweetNotification.cs index 12487773..fa570a9c 100644 --- a/Core/Notification/TweetNotification.cs +++ b/Core/Notification/TweetNotification.cs @@ -2,15 +2,14 @@ using System.Text; using CefSharp; using TweetDuck.Core.Bridge; +using TweetDuck.Data; using TweetDuck.Resources; namespace TweetDuck.Core.Notification{ sealed class TweetNotification{ private const string DefaultHeadLayout = @"<html id='tduck' class='os-windows txt-size--14' data-td-font='medium' data-td-theme='dark'><head><meta charset='utf-8'><meta http-equiv='X-UA-Compatible' content='chrome=1'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/font.5ef884f9f9.css'><link rel='stylesheet' href='https://ton.twimg.com/tweetdeck-web/web/css/app-dark.5631e0dd42.css'><style type='text/css'>body{background:#222426}</style>"; private static readonly string CustomCSS = ScriptLoader.LoadResource("styles/notification.css"); - - public const string AppLogoLink = "https://ton.twimg.com/tduck/avatar"; - public static readonly IResourceHandler AppLogoHandler = ResourceHandler.FromByteArray(Properties.Resources.avatar, "image/png"); + public static readonly ResourceLink AppLogo = new ResourceLink("https://ton.twimg.com/tduck/avatar", ResourceHandler.FromByteArray(Properties.Resources.avatar, "image/png")); public static TweetNotification Example(string html, int characters){ return new TweetNotification(string.Empty, string.Empty, "Home", html, characters, string.Empty, string.Empty, true); diff --git a/Core/TweetDeckBrowser.cs b/Core/TweetDeckBrowser.cs index 7aef666d..4598ee40 100644 --- a/Core/TweetDeckBrowser.cs +++ b/Core/TweetDeckBrowser.cs @@ -64,7 +64,7 @@ public TweetDeckBrowser(FormBrowser owner, PluginManager plugins, TweetDeckBridg this.browser.Dock = DockStyle.None; this.browser.Location = ControlExtensions.InvisibleLocation; - this.browser.SetupResourceHandler(TweetNotification.AppLogoLink, TweetNotification.AppLogoHandler); + this.browser.SetupResourceHandler(TweetNotification.AppLogo); this.browser.SetupResourceHandler(TwitterUtils.SpinnerLink, TwitterUtils.SpinnerHandler); owner.Controls.Add(browser); diff --git a/Core/Utils/BrowserUtils.cs b/Core/Utils/BrowserUtils.cs index d2e2657c..c5bb23ed 100644 --- a/Core/Utils/BrowserUtils.cs +++ b/Core/Utils/BrowserUtils.cs @@ -7,6 +7,7 @@ using System.Windows.Forms; using CefSharp.WinForms; using TweetDuck.Core.Other; +using TweetDuck.Data; namespace TweetDuck.Core.Utils{ static class BrowserUtils{ @@ -49,6 +50,10 @@ public static void SetupResourceHandler(this ChromiumWebBrowser browser, string } } + public static void SetupResourceHandler(this ChromiumWebBrowser browser, ResourceLink resource){ + browser.SetupResourceHandler(resource.Url, resource.Handler); + } + private const string TwitterTrackingUrl = "t.co"; public enum UrlCheckResult{ diff --git a/Core/Utils/TwitterUtils.cs b/Core/Utils/TwitterUtils.cs index 8f60c5a4..395d9ff1 100644 --- a/Core/Utils/TwitterUtils.cs +++ b/Core/Utils/TwitterUtils.cs @@ -6,17 +6,15 @@ using System.Text.RegularExpressions; using System.Windows.Forms; using TweetDuck.Core.Other; +using TweetDuck.Data; namespace TweetDuck.Core.Utils{ static class TwitterUtils{ public const string TweetDeckURL = "https://tweetdeck.twitter.com"; public static readonly Color BackgroundColor = Color.FromArgb(28, 99, 153); - - public static readonly IResourceHandler SpinnerHandler = ResourceHandler.FromByteArray(Properties.Resources.spinner, "image/apng"); - public const string SpinnerLink = "https://ton.twimg.com/tduck/spinner"; - - public const string OverrideScript = "let e=document.createElement('style');document.head.appendChild(e);e.innerHTML='body,body::before{background:#1c6399!important}';e=document.querySelector('.js-signin-ui img');if(e)e.src='"+SpinnerLink+"'"; + public static readonly ResourceLink LoadingSpinner = new ResourceLink("https://ton.twimg.com/tduck/spinner", ResourceHandler.FromByteArray(Properties.Resources.spinner, "image/apng")); + public const string OverrideScript = "let e=document.createElement('style');document.head.appendChild(e);e.innerHTML='body,body::before{background:#1c6399!important}';e=document.querySelector('.js-signin-ui img');if(e)e.src='https://ton.twimg.com/tduck/spinner'"; private static readonly Lazy<Regex> RegexAccountLazy = new Lazy<Regex>(() => new Regex(@"^https?://twitter\.com/(?!signup$|tos$|privacy$)([^/]+)/?$", RegexOptions.Compiled), false); public static Regex RegexAccount => RegexAccountLazy.Value; diff --git a/Data/ResourceLink.cs b/Data/ResourceLink.cs new file mode 100644 index 00000000..bc34d1ad --- /dev/null +++ b/Data/ResourceLink.cs @@ -0,0 +1,13 @@ +using CefSharp; + +namespace TweetDuck.Data{ + sealed class ResourceLink{ + public string Url { get; } + public IResourceHandler Handler { get; } + + public ResourceLink(string url, IResourceHandler handler){ + this.Url = url; + this.Handler = handler; + } + } +}