From b7de261d25f1667f73b4bd04663b537887ee6325 Mon Sep 17 00:00:00 2001 From: chylex <contact@chylex.com> Date: Thu, 21 Sep 2017 10:34:57 +0200 Subject: [PATCH] Move notification CSS to a file, refactor FontSizeLevel & TweetDeckBridge props --- Core/Bridge/TweetDeckBridge.cs | 12 ++--- Core/Notification/FormNotificationBase.cs | 13 ++++++ Core/Notification/FormNotificationMain.cs | 8 ++-- Core/Notification/TweetNotification.cs | 31 ++---------- Resources/Scripts/notification.js | 10 ++-- Resources/Scripts/styles/notification.css | 57 +++++++++++++++++++++++ 6 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 Resources/Scripts/styles/notification.css diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs index 1a588b99..1562b588 100644 --- a/Core/Bridge/TweetDeckBridge.cs +++ b/Core/Bridge/TweetDeckBridge.cs @@ -11,6 +11,9 @@ namespace TweetDuck.Core.Bridge{ sealed class TweetDeckBridge{ + public static string FontSizeClass; + public static string NotificationHeadContents; + public static string LastHighlightedTweetUrl = string.Empty; public static string LastHighlightedQuoteUrl = string.Empty; private static string LastHighlightedTweetAuthors = string.Empty; @@ -22,6 +25,7 @@ sealed class TweetDeckBridge{ private static readonly Dictionary<string, string> SessionData = new Dictionary<string, string>(2); public static void ResetStaticProperties(){ + FontSizeClass = NotificationHeadContents = null; LastHighlightedTweetUrl = LastHighlightedQuoteUrl = LastHighlightedTweetAuthors = LastHighlightedTweetImages = string.Empty; } @@ -47,15 +51,11 @@ public TweetDeckBridge(FormBrowser form, FormNotificationMain notification){ } public void LoadFontSizeClass(string fsClass){ - form.InvokeAsyncSafe(() => { - TweetNotification.SetFontSizeClass(fsClass); - }); + form.InvokeAsyncSafe(() => FontSizeClass = fsClass); } public void LoadNotificationHeadContents(string headContents){ - form.InvokeAsyncSafe(() => { - TweetNotification.SetHeadTag(headContents); - }); + form.InvokeAsyncSafe(() => NotificationHeadContents = headContents); } public void SetLastRightClickInfo(string type, string link){ diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index ac8167b6..b51969aa 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.Windows.Forms; using TweetDuck.Configuration; +using TweetDuck.Core.Bridge; using TweetDuck.Core.Controls; using TweetDuck.Core.Handling; using TweetDuck.Core.Handling.General; @@ -12,6 +13,18 @@ namespace TweetDuck.Core.Notification{ partial class FormNotificationBase : Form{ + protected static int FontSizeLevel{ + get{ + switch(TweetDeckBridge.FontSizeClass){ + case "largest": return 4; + case "large": return 3; + case "small": return 1; + case "smallest": return 0; + default: return 2; + } + } + } + protected Point PrimaryLocation{ get{ UserConfig config = Program.UserConfig; diff --git a/Core/Notification/FormNotificationMain.cs b/Core/Notification/FormNotificationMain.cs index 57f9effa..e9d68fba 100644 --- a/Core/Notification/FormNotificationMain.cs +++ b/Core/Notification/FormNotificationMain.cs @@ -33,7 +33,7 @@ partial class FormNotificationMain : FormNotificationBase{ public bool RequiresResize{ get{ - return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != TweetNotification.FontSizeLevel || CanResizeWindow; + return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != FontSizeLevel || CanResizeWindow; } set{ @@ -43,7 +43,7 @@ public bool RequiresResize{ } else{ prevDisplayTimer = Program.UserConfig.DisplayNotificationTimer; - prevFontSize = TweetNotification.FontSizeLevel; + prevFontSize = FontSizeLevel; } } } @@ -52,7 +52,7 @@ private int BaseClientWidth{ get{ switch(Program.UserConfig.NotificationSize){ default: - return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*TweetNotification.FontSizeLevel)); + return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*FontSizeLevel)); case TweetNotification.Size.Custom: return Program.UserConfig.CustomNotificationSize.Width; @@ -64,7 +64,7 @@ private int BaseClientHeight{ get{ switch(Program.UserConfig.NotificationSize){ default: - return BrowserUtils.Scale(122, SizeScale*(1.0+0.075*TweetNotification.FontSizeLevel)); + return BrowserUtils.Scale(122, SizeScale*(1.0+0.075*FontSizeLevel)); case TweetNotification.Size.Custom: return Program.UserConfig.CustomNotificationSize.Height; diff --git a/Core/Notification/TweetNotification.cs b/Core/Notification/TweetNotification.cs index 32463daa..1f0d0339 100644 --- a/Core/Notification/TweetNotification.cs +++ b/Core/Notification/TweetNotification.cs @@ -1,27 +1,14 @@ using System; using System.Text; +using TweetDuck.Core.Bridge; using TweetDuck.Resources; namespace TweetDuck.Core.Notification{ sealed class TweetNotification{ - private static string FontSizeClass { get; set; } - private static string HeadTag { get; set; } - private const string DefaultFontSizeClass = "medium"; - private const string DefaultHeadTag = @"<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 const string CustomCSS = @"body:before{content:none}body{overflow-y:auto}.scroll-styled-v::-webkit-scrollbar{width:7px}.scroll-styled-v::-webkit-scrollbar-thumb{border-radius:0}.scroll-styled-v::-webkit-scrollbar-track{border-left:0}#td-skip{opacity:0;cursor:pointer;transition:opacity 0.15s ease}.td-hover #td-skip{opacity:0.75}#td-skip:hover{opacity:1}.media-size-medium{height:calc(100vh - 16px)!important;max-height:240px;border-radius:1px!important}.js-quote-detail .media-size-medium{height:calc(100vh - 28px)!important;}.js-media.margin-vm, .js-media-preview-container.margin-vm{margin-bottom:0!important}"; + private const string DefaultHeadContents = @"<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>"; - public static int FontSizeLevel{ - get{ - switch(FontSizeClass){ - case "largest": return 4; - case "large": return 3; - case "medium": return 2; - case "small": return 1; - default: return 0; - } - } - } + private static readonly string CustomCSS = ScriptLoader.LoadResource("styles/notification.css"); private static string ExampleTweetHTML; @@ -39,14 +26,6 @@ public static TweetNotification ExampleTweet{ } } - public static void SetFontSizeClass(string newFSClass){ - FontSizeClass = newFSClass; - } - - public static void SetHeadTag(string headContents){ - HeadTag = headContents; - } - public enum Position{ TopLeft, TopRight, BottomLeft, BottomRight, Custom } @@ -88,8 +67,8 @@ public int GetDisplayDuration(int value){ public string GenerateHtml(string bodyClasses = null, bool enableCustomCSS = true){ StringBuilder build = new StringBuilder(); build.Append("<!DOCTYPE html>"); - build.Append("<html class='os-windows txt-base-").Append(FontSizeClass ?? DefaultFontSizeClass).Append("'>"); - build.Append("<head>").Append(HeadTag ?? DefaultHeadTag); + build.Append("<html class='os-windows txt-base-").Append(TweetDeckBridge.FontSizeClass ?? DefaultFontSizeClass).Append("'>"); + build.Append("<head>").Append(TweetDeckBridge.NotificationHeadContents ?? DefaultHeadContents); if (enableCustomCSS){ build.Append("<style type='text/css'>").Append(CustomCSS).Append("</style>"); diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js index 51e48d52..e40b2ba8 100644 --- a/Resources/Scripts/notification.js +++ b/Resources/Scripts/notification.js @@ -103,11 +103,11 @@ // Block: Setup a skip button. // if (!document.body.hasAttribute("td-example-notification")){ - document.body.insertAdjacentHTML("afterbegin", [ - '<svg id="td-skip" xmlns="http://www.w3.org/2000/svg" width="10" height="17" viewBox="0 0 350 600" style="position:fixed;left:30px;bottom:10px;z-index:1000">', - '<path fill="#888" d="M0,151.656l102.208-102.22l247.777,247.775L102.208,544.986L0,442.758l145.546-145.547">', - '</svg>' - ].join("")); + document.body.insertAdjacentHTML("afterbegin", ` +<svg id="td-skip" width="10" height="17" viewBox="0 0 350 600"> + <path fill="#888" d="M0,151.656l102.208-102.22l247.777,247.775L102.208,544.986L0,442.758l145.546-145.547"> +</svg> +`); document.getElementById("td-skip").addEventListener("click", function(){ $TD.loadNextNotification(); diff --git a/Resources/Scripts/styles/notification.css b/Resources/Scripts/styles/notification.css new file mode 100644 index 00000000..097c3797 --- /dev/null +++ b/Resources/Scripts/styles/notification.css @@ -0,0 +1,57 @@ +/* General */ + +body:before { + content: none; +} + +body { + overflow-y: auto; +} + +.scroll-styled-v::-webkit-scrollbar { + width: 7px; +} + +.scroll-styled-v::-webkit-scrollbar-thumb { + border-radius: 0; +} + +.scroll-styled-v::-webkit-scrollbar-track { + border-left: 0; +} + +/* Media */ + +.media-size-medium { + max-height: 240px; + height: calc(100vh - 16px) !important; + border-radius: 1px !important; +} + +.js-quote-detail .media-size-medium { + height: calc(100vh - 28px) !important; +} + +.js-media.margin-vm, .js-media-preview-container.margin-vm { + margin-bottom: 0 !important; +} + +/* Skip button */ + +#td-skip { + position: fixed; + left: 30px; + bottom: 10px; + z-index: 1000; + cursor: pointer; + opacity: 0; + transition: opacity 0.15s ease; +} + +.td-hover #td-skip { + opacity: 0.75; +} + +#td-skip:hover { + opacity: 1; +}