1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-25 00:15:48 +02:00

Refactor IResourceHandler usage

This commit is contained in:
chylex 2018-02-10 07:07:11 +01:00
parent 07d29207f0
commit 66d5f0d790
6 changed files with 25 additions and 10 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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{

View File

@ -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;

13
Data/ResourceLink.cs Normal file
View File

@ -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;
}
}
}