mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-31 17:34:14 +02:00
Move some stuff from BrowserUtils to a new TwitterUtils class
This commit is contained in:
parent
fa0cb120a7
commit
a70f64e1f6
2
Core/FormBrowser.Designer.cs
generated
2
Core/FormBrowser.Designer.cs
generated
@ -38,7 +38,7 @@ private void InitializeComponent() {
|
|||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.BackColor = TweetDuck.Core.Utils.BrowserUtils.BackgroundColor;
|
this.BackColor = TweetDuck.Core.Utils.TwitterUtils.BackgroundColor;
|
||||||
this.ClientSize = new System.Drawing.Size(324, 386);
|
this.ClientSize = new System.Drawing.Size(324, 386);
|
||||||
this.Icon = Properties.Resources.icon;
|
this.Icon = Properties.Resources.icon;
|
||||||
this.Location = TweetDuck.Core.Controls.ControlExtensions.InvisibleLocation;
|
this.Location = TweetDuck.Core.Controls.ControlExtensions.InvisibleLocation;
|
||||||
|
@ -81,7 +81,7 @@ public FormBrowser(PluginManager pluginManager, UpdaterSettings updaterSettings)
|
|||||||
this.browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge(this, notification));
|
this.browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge(this, notification));
|
||||||
this.browser.RegisterAsyncJsObject("$TDP", plugins.Bridge);
|
this.browser.RegisterAsyncJsObject("$TDP", plugins.Bridge);
|
||||||
|
|
||||||
browser.BrowserSettings.BackgroundColor = (uint)BrowserUtils.BackgroundColor.ToArgb();
|
browser.BrowserSettings.BackgroundColor = (uint)TwitterUtils.BackgroundColor.ToArgb();
|
||||||
browser.Dock = DockStyle.None;
|
browser.Dock = DockStyle.None;
|
||||||
browser.Location = ControlExtensions.InvisibleLocation;
|
browser.Location = ControlExtensions.InvisibleLocation;
|
||||||
Controls.Add(browser);
|
Controls.Add(browser);
|
||||||
@ -158,7 +158,7 @@ private void UpdateTrayIcon(){
|
|||||||
|
|
||||||
private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e){
|
private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e){
|
||||||
if (!e.IsLoading){
|
if (!e.IsLoading){
|
||||||
foreach(string word in BrowserUtils.DictionaryWords){
|
foreach(string word in TwitterUtils.DictionaryWords){
|
||||||
browser.AddWordToDictionary(word);
|
browser.AddWordToDictionary(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,15 +175,15 @@ private void browser_FrameLoadStart(object sender, FrameLoadStartEventArgs e){
|
|||||||
BrowserUtils.SetZoomLevel(browser.GetBrowser(), Config.ZoomLevel);
|
BrowserUtils.SetZoomLevel(browser.GetBrowser(), Config.ZoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BrowserUtils.IsTwitterWebsite(e.Frame)){
|
if (TwitterUtils.IsTwitterWebsite(e.Frame)){
|
||||||
ScriptLoader.ExecuteFile(e.Frame, "twitter.js");
|
ScriptLoader.ExecuteFile(e.Frame, "twitter.js");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 && TwitterUtils.IsTweetDeckWebsite(e.Frame)){
|
||||||
e.Frame.ExecuteJavaScriptAsync(BrowserUtils.BackgroundColorFix);
|
e.Frame.ExecuteJavaScriptAsync(TwitterUtils.BackgroundColorFix);
|
||||||
|
|
||||||
UpdateProperties(PropertyBridge.Properties.AllBrowser);
|
UpdateProperties(PropertyBridge.Properties.AllBrowser);
|
||||||
ScriptLoader.ExecuteFile(e.Frame, "code.js");
|
ScriptLoader.ExecuteFile(e.Frame, "code.js");
|
||||||
@ -406,7 +406,7 @@ public void UpdateProperties(PropertyBridge.Properties properties){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadToTweetDeck(){
|
public void ReloadToTweetDeck(){
|
||||||
browser.ExecuteScriptAsync($"gc&&gc();window.location.href='{BrowserUtils.TweetDeckURL}'");
|
browser.ExecuteScriptAsync($"gc&&gc();window.location.href='{TwitterUtils.TweetDeckURL}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback handlers
|
// callback handlers
|
||||||
|
@ -49,7 +49,7 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br
|
|||||||
lastHighlightedTweet = TweetDeckBridge.LastHighlightedTweet;
|
lastHighlightedTweet = TweetDeckBridge.LastHighlightedTweet;
|
||||||
lastHighlightedQuotedTweet = TweetDeckBridge.LastHighlightedQuotedTweet;
|
lastHighlightedQuotedTweet = TweetDeckBridge.LastHighlightedQuotedTweet;
|
||||||
|
|
||||||
if (!BrowserUtils.IsTweetDeckWebsite(frame) || browser.IsLoading){
|
if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading){
|
||||||
lastHighlightedTweet = string.Empty;
|
lastHighlightedTweet = string.Empty;
|
||||||
lastHighlightedQuotedTweet = string.Empty;
|
lastHighlightedQuotedTweet = string.Empty;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public FormNotificationBase(Form owner, bool enableContextMenu){
|
|||||||
this.dpiScale = this.GetDPIScale();
|
this.dpiScale = this.GetDPIScale();
|
||||||
|
|
||||||
DefaultResourceHandlerFactory handlerFactory = (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory;
|
DefaultResourceHandlerFactory handlerFactory = (DefaultResourceHandlerFactory)browser.ResourceHandlerFactory;
|
||||||
handlerFactory.RegisterHandler(BrowserUtils.TweetDeckURL, this.resourceHandler);
|
handlerFactory.RegisterHandler(TwitterUtils.TweetDeckURL, this.resourceHandler);
|
||||||
|
|
||||||
Controls.Add(browser);
|
Controls.Add(browser);
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ protected virtual void LoadTweet(TweetNotification tweet){
|
|||||||
currentColumn = tweet.Column;
|
currentColumn = tweet.Column;
|
||||||
|
|
||||||
resourceHandler.SetHTML(GetTweetHTML(tweet));
|
resourceHandler.SetHTML(GetTweetHTML(tweet));
|
||||||
browser.Load(BrowserUtils.TweetDeckURL);
|
browser.Load(TwitterUtils.TweetDeckURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void SetNotificationSize(int width, int height){
|
protected virtual void SetNotificationSize(int width, int height){
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -10,8 +9,6 @@
|
|||||||
|
|
||||||
namespace TweetDuck.Core.Utils{
|
namespace TweetDuck.Core.Utils{
|
||||||
static class BrowserUtils{
|
static class BrowserUtils{
|
||||||
public const string TweetDeckURL = "https://tweetdeck.twitter.com";
|
|
||||||
|
|
||||||
public static string HeaderAcceptLanguage{
|
public static string HeaderAcceptLanguage{
|
||||||
get{
|
get{
|
||||||
string culture = Program.Culture.Name;
|
string culture = Program.Culture.Name;
|
||||||
@ -27,13 +24,6 @@ public static string HeaderAcceptLanguage{
|
|||||||
|
|
||||||
public static string HeaderUserAgent => Program.BrandName+" "+Application.ProductVersion;
|
public static string HeaderUserAgent => Program.BrandName+" "+Application.ProductVersion;
|
||||||
|
|
||||||
public static readonly Color BackgroundColor = Color.FromArgb(28, 99, 153);
|
|
||||||
public const string BackgroundColorFix = "let e=document.createElement('style');document.head.appendChild(e);e.innerHTML='body::before{background:#1c6399!important}'";
|
|
||||||
|
|
||||||
public static readonly string[] DictionaryWords = {
|
|
||||||
"tweetdeck", "TweetDeck", "tweetduck", "TweetDuck", "TD"
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void SetupCefArgs(IDictionary<string, string> args){
|
public static void SetupCefArgs(IDictionary<string, string> args){
|
||||||
if (!Program.SystemConfig.HardwareAcceleration){
|
if (!Program.SystemConfig.HardwareAcceleration){
|
||||||
args["disable-gpu"] = "1";
|
args["disable-gpu"] = "1";
|
||||||
@ -117,14 +107,6 @@ public static void SetZoomLevel(IBrowser browser, int percentage){
|
|||||||
browser.GetHost().SetZoomLevel(Math.Log(percentage/100.0, 1.2));
|
browser.GetHost().SetZoomLevel(Math.Log(percentage/100.0, 1.2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsTweetDeckWebsite(IFrame frame){
|
|
||||||
return frame.Url.Contains("//tweetdeck.twitter.com/");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsTwitterWebsite(IFrame frame){
|
|
||||||
return frame.Url.Contains("//twitter.com/");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
public static void HandleConsoleMessage(object sender, ConsoleMessageEventArgs e){
|
public static void HandleConsoleMessage(object sender, ConsoleMessageEventArgs e){
|
||||||
Debug.WriteLine("[Console] {0} ({1}:{2})", e.Message, e.Source, e.Line);
|
Debug.WriteLine("[Console] {0} ({1}:{2})", e.Message, e.Source, e.Line);
|
||||||
|
23
Core/Utils/TwitterUtils.cs
Normal file
23
Core/Utils/TwitterUtils.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using CefSharp;
|
||||||
|
|
||||||
|
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 const string BackgroundColorFix = "let e=document.createElement('style');document.head.appendChild(e);e.innerHTML='body::before{background:#1c6399!important}'";
|
||||||
|
|
||||||
|
public static readonly string[] DictionaryWords = {
|
||||||
|
"tweetdeck", "TweetDeck", "tweetduck", "TweetDuck", "TD"
|
||||||
|
};
|
||||||
|
|
||||||
|
public static bool IsTweetDeckWebsite(IFrame frame){
|
||||||
|
return frame.Url.Contains("//tweetdeck.twitter.com/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsTwitterWebsite(IFrame frame){
|
||||||
|
return frame.Url.Contains("//twitter.com/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -167,6 +167,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Core\Utils\BrowserProcesses.cs" />
|
<Compile Include="Core\Utils\BrowserProcesses.cs" />
|
||||||
<Compile Include="Core\Utils\StringUtils.cs" />
|
<Compile Include="Core\Utils\StringUtils.cs" />
|
||||||
|
<Compile Include="Core\Utils\TwitterUtils.cs" />
|
||||||
<Compile Include="Data\CombinedFileStream.cs" />
|
<Compile Include="Data\CombinedFileStream.cs" />
|
||||||
<Compile Include="Core\Other\Settings\Export\ExportFileFlags.cs" />
|
<Compile Include="Core\Other\Settings\Export\ExportFileFlags.cs" />
|
||||||
<Compile Include="Core\Other\Settings\Export\ExportManager.cs" />
|
<Compile Include="Core\Other\Settings\Export\ExportManager.cs" />
|
||||||
|
@ -30,7 +30,7 @@ public UpdateHandler(ChromiumWebBrowser browser, UpdaterSettings settings){
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 && TwitterUtils.IsTweetDeckWebsite(e.Frame)){
|
||||||
ScriptLoader.ExecuteFile(e.Frame, "update.js");
|
ScriptLoader.ExecuteFile(e.Frame, "update.js");
|
||||||
Check(false);
|
Check(false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user