mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-28 08:34:06 +02:00
Minor refactoring & removal of unnecessary code
This commit is contained in:
parent
bbb7907e54
commit
bd0be65038
Core
Reporter.csResources/Scripts
Updates
video
@ -8,8 +8,8 @@ public enum Environment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateScript(Environment environment){
|
public static string GenerateScript(Environment environment){
|
||||||
string Bool(bool value) => value ? "true;" : "false;";
|
static string Bool(bool value) => value ? "true;" : "false;";
|
||||||
string Str(string value) => '"'+value+"\";";
|
static string Str(string value) => '"'+value+"\";";
|
||||||
|
|
||||||
UserConfig config = Program.Config.User;
|
UserConfig config = Program.Config.User;
|
||||||
StringBuilder build = new StringBuilder(128).Append("(function(x){");
|
StringBuilder build = new StringBuilder(128).Append("(function(x){");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using TweetDuck.Core.Controls;
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Management;
|
using TweetDuck.Core.Handling;
|
||||||
using TweetDuck.Core.Notification;
|
using TweetDuck.Core.Notification;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
@ -10,12 +10,9 @@
|
|||||||
namespace TweetDuck.Core.Bridge{
|
namespace TweetDuck.Core.Bridge{
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
class TweetDeckBridge{
|
class TweetDeckBridge{
|
||||||
public static string FontSize { get; private set; }
|
|
||||||
public static string NotificationHeadLayout { get; private set; }
|
|
||||||
public static readonly ContextInfo ContextInfo = new ContextInfo();
|
|
||||||
|
|
||||||
public static void ResetStaticProperties(){
|
public static void ResetStaticProperties(){
|
||||||
FontSize = NotificationHeadLayout = null;
|
FormNotificationBase.FontSize = null;
|
||||||
|
FormNotificationBase.HeadLayout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly FormBrowser form;
|
private readonly FormBrowser form;
|
||||||
@ -47,17 +44,17 @@ public void OnIntroductionClosed(bool showGuide, bool allowDataCollection){
|
|||||||
|
|
||||||
public void LoadNotificationLayout(string fontSize, string headLayout){
|
public void LoadNotificationLayout(string fontSize, string headLayout){
|
||||||
form.InvokeAsyncSafe(() => {
|
form.InvokeAsyncSafe(() => {
|
||||||
FontSize = fontSize;
|
FormNotificationBase.FontSize = fontSize;
|
||||||
NotificationHeadLayout = headLayout;
|
FormNotificationBase.HeadLayout = headLayout;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRightClickedLink(string type, string url){
|
public void SetRightClickedLink(string type, string url){
|
||||||
ContextInfo.SetLink(type, url);
|
ContextMenuBase.CurrentInfo.SetLink(type, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRightClickedChirp(string tweetUrl, string quoteUrl, string chirpAuthors, string chirpImages){
|
public void SetRightClickedChirp(string tweetUrl, string quoteUrl, string chirpAuthors, string chirpImages){
|
||||||
ContextInfo.SetChirp(tweetUrl, quoteUrl, chirpAuthors, chirpImages);
|
ContextMenuBase.CurrentInfo.SetChirp(tweetUrl, quoteUrl, chirpAuthors, chirpImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisplayTooltip(string text){
|
public void DisplayTooltip(string text){
|
||||||
|
@ -13,7 +13,6 @@ class UpdateBridge{
|
|||||||
private UpdateInfo nextUpdate = null;
|
private UpdateInfo nextUpdate = null;
|
||||||
|
|
||||||
public event EventHandler<UpdateInfo> UpdateAccepted;
|
public event EventHandler<UpdateInfo> UpdateAccepted;
|
||||||
public event EventHandler<UpdateInfo> UpdateDelayed;
|
|
||||||
public event EventHandler<UpdateInfo> UpdateDismissed;
|
public event EventHandler<UpdateInfo> UpdateDismissed;
|
||||||
|
|
||||||
public UpdateBridge(UpdateHandler updates, Control sync){
|
public UpdateBridge(UpdateHandler updates, Control sync){
|
||||||
@ -56,10 +55,6 @@ public void OnUpdateAccepted(){
|
|||||||
HandleInteractionEvent(UpdateAccepted);
|
HandleInteractionEvent(UpdateAccepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUpdateDelayed(){
|
|
||||||
HandleInteractionEvent(UpdateDelayed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnUpdateDismissed(){
|
public void OnUpdateDismissed(){
|
||||||
HandleInteractionEvent(UpdateDismissed);
|
HandleInteractionEvent(UpdateDismissed);
|
||||||
|
|
||||||
|
@ -21,9 +21,8 @@ public static void InvokeAsyncSafe(this Control control, Action func){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float GetDPIScale(this Control control){
|
public static float GetDPIScale(this Control control){
|
||||||
using(Graphics graphics = control.CreateGraphics()){
|
using Graphics graphics = control.CreateGraphics();
|
||||||
return graphics.DpiY/96F;
|
return graphics.DpiY / 96F;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsFullyOutsideView(this Form form){
|
public static bool IsFullyOutsideView(this Form form){
|
||||||
@ -63,7 +62,8 @@ public static bool AlignValueToTick(this TrackBar trackBar){
|
|||||||
trackBar.Value = trackBar.SmallChange*(int)Math.Floor(((double)trackBar.Value/trackBar.SmallChange)+0.5);
|
trackBar.Value = trackBar.SmallChange*(int)Math.Floor(((double)trackBar.Value/trackBar.SmallChange)+0.5);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else return true;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EnableMultilineShortcuts(this TextBox textBox){
|
public static void EnableMultilineShortcuts(this TextBox textBox){
|
||||||
|
@ -8,15 +8,14 @@ sealed class LabelVertical : Label{
|
|||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e){
|
protected override void OnPaint(PaintEventArgs e){
|
||||||
int y = (int)Math.Floor((ClientRectangle.Height-Text.Length*LineHeight)/2F)-1;
|
int y = (int)Math.Floor((ClientRectangle.Height-Text.Length*LineHeight)/2F)-1;
|
||||||
|
using Brush brush = new SolidBrush(ForeColor);
|
||||||
|
|
||||||
using(Brush brush = new SolidBrush(ForeColor)){
|
foreach(char chr in Text){
|
||||||
foreach(char chr in Text){
|
string str = chr.ToString();
|
||||||
string str = chr.ToString();
|
float x = (ClientRectangle.Width-e.Graphics.MeasureString(str, Font).Width)/2F;
|
||||||
float x = (ClientRectangle.Width-e.Graphics.MeasureString(str, Font).Width)/2F;
|
|
||||||
|
|
||||||
e.Graphics.DrawString(str, Font, brush, x, y);
|
e.Graphics.DrawString(str, Font, brush, x, y);
|
||||||
y += LineHeight;
|
y += LineHeight;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,6 @@ public FormBrowser(){
|
|||||||
|
|
||||||
this.updateBridge = new UpdateBridge(updates, this);
|
this.updateBridge = new UpdateBridge(updates, this);
|
||||||
this.updateBridge.UpdateAccepted += updateBridge_UpdateAccepted;
|
this.updateBridge.UpdateAccepted += updateBridge_UpdateAccepted;
|
||||||
this.updateBridge.UpdateDelayed += updateBridge_UpdateDelayed;
|
|
||||||
this.updateBridge.UpdateDismissed += updateBridge_UpdateDismissed;
|
this.updateBridge.UpdateDismissed += updateBridge_UpdateDismissed;
|
||||||
|
|
||||||
this.browser = new TweetDeckBrowser(this, plugins, new TweetDeckBridge.Browser(this, notification), updateBridge);
|
this.browser = new TweetDeckBrowser(this, plugins, new TweetDeckBridge.Browser(this, notification), updateBridge);
|
||||||
@ -323,10 +322,6 @@ void OnFinished(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBridge_UpdateDelayed(object sender, UpdateInfo update){
|
|
||||||
// stops the timer
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBridge_UpdateDismissed(object sender, UpdateInfo update){
|
private void updateBridge_UpdateDismissed(object sender, UpdateInfo update){
|
||||||
Config.DismissedUpdate = update.VersionTag;
|
Config.DismissedUpdate = update.VersionTag;
|
||||||
Config.Save();
|
Config.Save();
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Core.Adapters;
|
using TweetDuck.Core.Adapters;
|
||||||
using TweetDuck.Core.Bridge;
|
|
||||||
using TweetDuck.Core.Management;
|
using TweetDuck.Core.Management;
|
||||||
using TweetDuck.Core.Notification;
|
using TweetDuck.Core.Notification;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
@ -17,8 +16,9 @@
|
|||||||
|
|
||||||
namespace TweetDuck.Core.Handling{
|
namespace TweetDuck.Core.Handling{
|
||||||
abstract class ContextMenuBase : IContextMenuHandler{
|
abstract class ContextMenuBase : IContextMenuHandler{
|
||||||
protected static UserConfig Config => Program.Config.User;
|
public static ContextInfo CurrentInfo { get; } = new ContextInfo();
|
||||||
|
|
||||||
|
protected static UserConfig Config => Program.Config.User;
|
||||||
private static ImageQuality ImageQuality => Config.TwitterImageQuality;
|
private static ImageQuality ImageQuality => Config.TwitterImageQuality;
|
||||||
|
|
||||||
private const CefMenuCommand MenuOpenLinkUrl = (CefMenuCommand)26500;
|
private const CefMenuCommand MenuOpenLinkUrl = (CefMenuCommand)26500;
|
||||||
@ -43,10 +43,10 @@ protected ContextMenuBase(AnalyticsFile.IProvider analytics){
|
|||||||
|
|
||||||
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
||||||
if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading){
|
if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading){
|
||||||
Context = TweetDeckBridge.ContextInfo.Reset();
|
Context = CurrentInfo.Reset();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Context = TweetDeckBridge.ContextInfo.Create(parameters);
|
Context = CurrentInfo.Create(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable)){
|
if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable)){
|
||||||
@ -55,10 +55,10 @@ public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser bro
|
|||||||
model.AddItem(MenuReadApplyROT13, "Apply ROT13");
|
model.AddItem(MenuReadApplyROT13, "Apply ROT13");
|
||||||
model.AddSeparator();
|
model.AddSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
string TextOpen(string name) => "Open "+name+" in browser";
|
static string TextOpen(string name) => "Open "+name+" in browser";
|
||||||
string TextCopy(string name) => "Copy "+name+" address";
|
static string TextCopy(string name) => "Copy "+name+" address";
|
||||||
string TextSave(string name) => "Save "+name+" as...";
|
static string TextSave(string name) => "Save "+name+" as...";
|
||||||
|
|
||||||
if (Context.Types.HasFlag(ContextInfo.ContextType.Link) && !Context.UnsafeLinkUrl.EndsWith("tweetdeck.twitter.com/#", StringComparison.Ordinal)){
|
if (Context.Types.HasFlag(ContextInfo.ContextType.Link) && !Context.UnsafeLinkUrl.EndsWith("tweetdeck.twitter.com/#", StringComparison.Ordinal)){
|
||||||
if (TwitterUrls.RegexAccount.IsMatch(Context.UnsafeLinkUrl)){
|
if (TwitterUrls.RegexAccount.IsMatch(Context.UnsafeLinkUrl)){
|
||||||
@ -186,7 +186,7 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame){
|
public virtual void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame){
|
||||||
Context = TweetDeckBridge.ContextInfo.Reset();
|
Context = CurrentInfo.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback){
|
public virtual bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback){
|
||||||
|
@ -11,12 +11,11 @@ public static Task UpdatePrefs(){
|
|||||||
|
|
||||||
private static void UpdatePrefsInternal(){
|
private static void UpdatePrefsInternal(){
|
||||||
UserConfig config = Program.Config.User;
|
UserConfig config = Program.Config.User;
|
||||||
|
using IRequestContext ctx = Cef.GetGlobalRequestContext();
|
||||||
|
|
||||||
using(IRequestContext ctx = Cef.GetGlobalRequestContext()){
|
ctx.SetPreference("browser.enable_spellchecking", config.EnableSpellCheck, out string _);
|
||||||
ctx.SetPreference("browser.enable_spellchecking", config.EnableSpellCheck, out string _);
|
ctx.SetPreference("spellcheck.dictionary", config.SpellCheckLanguage, out string _);
|
||||||
ctx.SetPreference("spellcheck.dictionary", config.SpellCheckLanguage, out string _);
|
ctx.SetPreference("settings.a11y.animation_policy", config.EnableAnimatedImages ? "allowed" : "none", out string _);
|
||||||
ctx.SetPreference("settings.a11y.animation_policy", config.EnableAnimatedImages ? "allowed" : "none", out string _);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IBrowserProcessHandler.OnContextInitialized(){
|
void IBrowserProcessHandler.OnContextInitialized(){
|
||||||
|
@ -73,28 +73,27 @@ public Items FindImportItems(){
|
|||||||
Items items = Items.None;
|
Items items = Items.None;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
using(CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))){
|
using CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None));
|
||||||
string key;
|
string key;
|
||||||
|
|
||||||
while((key = stream.SkipFile()) != null){
|
while((key = stream.SkipFile()) != null){
|
||||||
switch(key){
|
switch(key){
|
||||||
case "config":
|
case "config":
|
||||||
items |= Items.UserConfig;
|
items |= Items.UserConfig;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "system":
|
case "system":
|
||||||
items |= Items.SystemConfig;
|
items |= Items.SystemConfig;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "plugin.config":
|
case "plugin.config":
|
||||||
case "plugin.data":
|
case "plugin.data":
|
||||||
items |= Items.PluginData;
|
items |= Items.PluginData;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "cookies":
|
case "cookies":
|
||||||
items |= Items.Session;
|
items |= Items.Session;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(Exception){
|
}catch(Exception){
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Core.Bridge;
|
|
||||||
using TweetDuck.Core.Controls;
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Handling;
|
using TweetDuck.Core.Handling;
|
||||||
using TweetDuck.Core.Handling.General;
|
using TweetDuck.Core.Handling.General;
|
||||||
@ -17,10 +16,13 @@ namespace TweetDuck.Core.Notification{
|
|||||||
abstract partial class FormNotificationBase : Form, AnalyticsFile.IProvider{
|
abstract partial class FormNotificationBase : Form, AnalyticsFile.IProvider{
|
||||||
public static readonly ResourceLink AppLogo = new ResourceLink("https://ton.twimg.com/tduck/avatar", 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"));
|
||||||
|
|
||||||
protected static UserConfig Config => Program.Config.User;
|
public static string FontSize = null;
|
||||||
|
public static string HeadLayout = null;
|
||||||
|
|
||||||
|
protected static UserConfig Config => Program.Config.User;
|
||||||
|
|
||||||
protected static int FontSizeLevel{
|
protected static int FontSizeLevel{
|
||||||
get => TweetDeckBridge.FontSize switch{
|
get => FontSize switch{
|
||||||
"largest" => 4,
|
"largest" => 4,
|
||||||
"large" => 3,
|
"large" => 3,
|
||||||
"small" => 1,
|
"small" => 1,
|
||||||
|
@ -220,7 +220,7 @@ public override void ResumeNotification(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetTweetHTML(DesktopNotification tweet){
|
protected override string GetTweetHTML(DesktopNotification tweet){
|
||||||
string html = tweet.GenerateHtml(BodyClasses, TweetDeckBridge.NotificationHeadLayout, Config.CustomNotificationCSS);
|
string html = tweet.GenerateHtml(BodyClasses, HeadLayout, Config.CustomNotificationCSS);
|
||||||
|
|
||||||
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||||
html = injection.InjectInto(html);
|
html = injection.InjectInto(html);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
using TweetDuck.Core.Adapters;
|
using TweetDuck.Core.Adapters;
|
||||||
using TweetDuck.Core.Bridge;
|
|
||||||
using TweetDuck.Core.Controls;
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
@ -47,7 +46,7 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetTweetHTML(DesktopNotification tweet){
|
protected override string GetTweetHTML(DesktopNotification tweet){
|
||||||
string html = tweet.GenerateHtml("td-screenshot", TweetDeckBridge.NotificationHeadLayout, Config.CustomNotificationCSS);
|
string html = tweet.GenerateHtml("td-screenshot", HeadLayout, Config.CustomNotificationCSS);
|
||||||
|
|
||||||
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
foreach(InjectedHTML injection in plugins.NotificationInjections){
|
||||||
html = injection.InjectInto(html);
|
html = injection.InjectInto(html);
|
||||||
|
@ -143,19 +143,19 @@ static AnalyticsReportGenerator(){
|
|||||||
string osName, osEdition, osBuild;
|
string osName, osEdition, osBuild;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
using(RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false)){
|
using RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
|
||||||
// ReSharper disable once PossibleNullReferenceException
|
|
||||||
osName = key.GetValue("ProductName") as string;
|
|
||||||
osBuild = key.GetValue("CurrentBuild") as string;
|
|
||||||
osEdition = null;
|
|
||||||
|
|
||||||
if (osName != null){
|
|
||||||
Match match = Regex.Match(osName, @"^(.*?\d+(?:\.\d+)?) (.*)$");
|
|
||||||
|
|
||||||
if (match.Success){
|
// ReSharper disable once PossibleNullReferenceException
|
||||||
osName = match.Groups[1].Value;
|
osName = key.GetValue("ProductName") as string;
|
||||||
osEdition = match.Groups[2].Value;
|
osBuild = key.GetValue("CurrentBuild") as string;
|
||||||
}
|
osEdition = null;
|
||||||
|
|
||||||
|
if (osName != null){
|
||||||
|
Match match = Regex.Match(osName, @"^(.*?\d+(?:\.\d+)?) (.*)$");
|
||||||
|
|
||||||
|
if (match.Success){
|
||||||
|
osName = match.Groups[1].Value;
|
||||||
|
osEdition = match.Groups[2].Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch{
|
}catch{
|
||||||
@ -167,10 +167,10 @@ static AnalyticsReportGenerator(){
|
|||||||
SystemBuild = osBuild ?? "(unknown)";
|
SystemBuild = osBuild ?? "(unknown)";
|
||||||
|
|
||||||
try{
|
try{
|
||||||
using(ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Capacity FROM Win32_PhysicalMemory")){
|
using ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Capacity FROM Win32_PhysicalMemory");
|
||||||
foreach(ManagementBaseObject obj in searcher.Get()){
|
|
||||||
RamSize += (int)((ulong)obj["Capacity"]/(1024L*1024L));
|
foreach(ManagementBaseObject obj in searcher.Get()){
|
||||||
}
|
RamSize += (int)((ulong)obj["Capacity"]/(1024L*1024L));
|
||||||
}
|
}
|
||||||
}catch{
|
}catch{
|
||||||
RamSize = 0;
|
RamSize = 0;
|
||||||
@ -179,13 +179,13 @@ static AnalyticsReportGenerator(){
|
|||||||
string gpu = null;
|
string gpu = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
using(ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_VideoController")){
|
using ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_VideoController");
|
||||||
foreach(ManagementBaseObject obj in searcher.Get()){
|
|
||||||
string vendor = obj["Caption"] as string;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(vendor)){
|
foreach(ManagementBaseObject obj in searcher.Get()){
|
||||||
gpu = vendor;
|
string vendor = obj["Caption"] as string;
|
||||||
}
|
|
||||||
|
if (!string.IsNullOrEmpty(vendor)){
|
||||||
|
gpu = vendor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch{
|
}catch{
|
||||||
|
@ -9,7 +9,7 @@ class BaseTabSettings : UserControl{
|
|||||||
|
|
||||||
public IEnumerable<Control> InteractiveControls{
|
public IEnumerable<Control> InteractiveControls{
|
||||||
get{
|
get{
|
||||||
IEnumerable<Control> FindInteractiveControls(Control parent){
|
static IEnumerable<Control> FindInteractiveControls(Control parent){
|
||||||
foreach(Control control in parent.Controls){
|
foreach(Control control in parent.Controls){
|
||||||
if (control is Panel subPanel){
|
if (control is Panel subPanel){
|
||||||
foreach(Control subControl in FindInteractiveControls(subPanel)){
|
foreach(Control subControl in FindInteractiveControls(subPanel)){
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
using TweetLib.Core.Features.Plugins;
|
using TweetLib.Core.Features.Plugins;
|
||||||
using TweetLib.Core.Features.Plugins.Enums;
|
using TweetLib.Core.Features.Plugins.Enums;
|
||||||
using TweetLib.Core.Features.Twitter;
|
using TweetLib.Core.Features.Twitter;
|
||||||
|
using TweetLib.Core.Utils;
|
||||||
|
|
||||||
namespace TweetDuck.Core{
|
namespace TweetDuck.Core{
|
||||||
sealed class TweetDeckBrowser : IDisposable{
|
sealed class TweetDeckBrowser : IDisposable{
|
||||||
@ -178,7 +179,10 @@ private void browser_LoadError(object sender, LoadErrorEventArgs e){
|
|||||||
string errorPage = Program.Resources.LoadSilent("pages/error.html");
|
string errorPage = Program.Resources.LoadSilent("pages/error.html");
|
||||||
|
|
||||||
if (errorPage != null){
|
if (errorPage != null){
|
||||||
resourceHandlerFactory.RegisterHandler(ErrorUrl, ResourceHandler.FromString(errorPage.Replace("{err}", BrowserUtils.GetErrorName(e.ErrorCode))));
|
string errorName = Enum.GetName(typeof(CefErrorCode), e.ErrorCode);
|
||||||
|
string errorTitle = StringUtils.ConvertPascalCaseToScreamingSnakeCase(errorName ?? string.Empty);
|
||||||
|
|
||||||
|
resourceHandlerFactory.RegisterHandler(ErrorUrl, ResourceHandler.FromString(errorPage.Replace("{err}", errorTitle)));
|
||||||
browser.Load(ErrorUrl);
|
browser.Load(ErrorUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
using TweetDuck.Core.Other;
|
using TweetDuck.Core.Other;
|
||||||
using TweetLib.Core.Features.Twitter;
|
using TweetLib.Core.Features.Twitter;
|
||||||
using TweetLib.Core.Utils;
|
|
||||||
|
|
||||||
namespace TweetDuck.Core.Utils{
|
namespace TweetDuck.Core.Utils{
|
||||||
static class BrowserUtils{
|
static class BrowserUtils{
|
||||||
@ -61,8 +60,12 @@ public static ChromiumWebBrowser AsControl(this IWebBrowser browserControl){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void SetupZoomEvents(this ChromiumWebBrowser browser){
|
public static void SetupZoomEvents(this ChromiumWebBrowser browser){
|
||||||
|
static void SetZoomLevel(IBrowserHost host, int percentage){
|
||||||
|
host.SetZoomLevel(Math.Log(percentage / 100.0, 1.2));
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateZoomLevel(object sender, EventArgs args){
|
void UpdateZoomLevel(object sender, EventArgs args){
|
||||||
SetZoomLevel(browser.GetBrowser(), Config.ZoomLevel);
|
SetZoomLevel(browser.GetBrowserHost(), Config.ZoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.ZoomLevelChanged += UpdateZoomLevel;
|
Config.ZoomLevelChanged += UpdateZoomLevel;
|
||||||
@ -70,7 +73,7 @@ void UpdateZoomLevel(object sender, EventArgs args){
|
|||||||
|
|
||||||
browser.FrameLoadStart += (sender, args) => {
|
browser.FrameLoadStart += (sender, args) => {
|
||||||
if (args.Frame.IsMain && Config.ZoomLevel != 100){
|
if (args.Frame.IsMain && Config.ZoomLevel != 100){
|
||||||
SetZoomLevel(args.Browser, Config.ZoomLevel);
|
SetZoomLevel(args.Browser.GetHost(), Config.ZoomLevel);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -131,7 +134,9 @@ public static void OpenExternalBrowser(string url){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenExternalSearch(string query){
|
public static void OpenExternalSearch(string query){
|
||||||
if (string.IsNullOrWhiteSpace(query))return;
|
if (string.IsNullOrWhiteSpace(query)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string searchUrl = Config.SearchEngineUrl;
|
string searchUrl = Config.SearchEngineUrl;
|
||||||
|
|
||||||
@ -157,16 +162,8 @@ public static void OpenExternalSearch(string query){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetErrorName(CefErrorCode code){
|
|
||||||
return StringUtils.ConvertPascalCaseToScreamingSnakeCase(Enum.GetName(typeof(CefErrorCode), code) ?? string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int Scale(int baseValue, double scaleFactor){
|
public static int Scale(int baseValue, double scaleFactor){
|
||||||
return (int)Math.Round(baseValue*scaleFactor);
|
return (int)Math.Round(baseValue*scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetZoomLevel(IBrowser browser, int percentage){
|
|
||||||
browser.GetHost().SetZoomLevel(Math.Log(percentage/100.0, 1.2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ static class TwitterUtils{
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static void ViewImage(string url, ImageQuality quality){
|
public static void ViewImage(string url, ImageQuality quality){
|
||||||
void ViewImageInternal(string path){
|
static void ViewImageInternal(string path){
|
||||||
string ext = Path.GetExtension(path);
|
string ext = Path.GetExtension(path);
|
||||||
|
|
||||||
if (ImageUrl.ValidExtensions.Contains(ext)){
|
if (ImageUrl.ValidExtensions.Contains(ext)){
|
||||||
@ -73,7 +73,7 @@ public static void DownloadImages(string[] urls, string username, ImageQuality q
|
|||||||
Filter = (urls.Length == 1 ? "Image" : "Images")+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
|
Filter = (urls.Length == 1 ? "Image" : "Images")+(string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
|
||||||
}){
|
}){
|
||||||
if (dialog.ShowDialog() == DialogResult.OK){
|
if (dialog.ShowDialog() == DialogResult.OK){
|
||||||
void OnFailure(Exception ex){
|
static void OnFailure(Exception ex){
|
||||||
FormMessage.Error("Image Download", "An error occurred while downloading the image: "+ex.Message, FormMessage.OK);
|
FormMessage.Error("Image Download", "An error occurred while downloading the image: "+ex.Message, FormMessage.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,19 +11,17 @@
|
|||||||
|
|
||||||
namespace TweetDuck.Core.Utils{
|
namespace TweetDuck.Core.Utils{
|
||||||
static class WindowsUtils{
|
static class WindowsUtils{
|
||||||
|
private static readonly bool IsWindows8OrNewer = OSVersionEquals(major: 6, minor: 2); // windows 8/10
|
||||||
|
|
||||||
|
public static bool ShouldAvoidToolWindow { get; } = IsWindows8OrNewer;
|
||||||
|
public static bool IsAeroEnabled => IsWindows8OrNewer || (NativeMethods.DwmIsCompositionEnabled(out bool isCompositionEnabled) == 0 && isCompositionEnabled);
|
||||||
|
|
||||||
private static readonly Lazy<Regex> RegexStripHtmlStyles = new Lazy<Regex>(() => new Regex(@"\s?(?:style|class)="".*?"""), false);
|
private static readonly Lazy<Regex> RegexStripHtmlStyles = new Lazy<Regex>(() => new Regex(@"\s?(?:style|class)="".*?"""), false);
|
||||||
private static readonly Lazy<Regex> RegexOffsetClipboardHtml = new Lazy<Regex>(() => new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)"), false);
|
private static readonly Lazy<Regex> RegexOffsetClipboardHtml = new Lazy<Regex>(() => new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)"), false);
|
||||||
|
|
||||||
private static readonly bool IsWindows8OrNewer;
|
private static bool OSVersionEquals(int major, int minor){
|
||||||
|
|
||||||
public static bool ShouldAvoidToolWindow { get; }
|
|
||||||
public static bool IsAeroEnabled => IsWindows8OrNewer || (NativeMethods.DwmIsCompositionEnabled(out bool isCompositionEnabled) == 0 && isCompositionEnabled);
|
|
||||||
|
|
||||||
static WindowsUtils(){
|
|
||||||
Version ver = Environment.OSVersion.Version;
|
Version ver = Environment.OSVersion.Version;
|
||||||
IsWindows8OrNewer = ver.Major == 6 && ver.Minor == 2; // windows 8/10
|
return ver.Major == major && ver.Minor == minor;
|
||||||
|
|
||||||
ShouldAvoidToolWindow = IsWindows8OrNewer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool OpenAssociatedProgram(string file, string arguments = "", bool runElevated = false){
|
public static bool OpenAssociatedProgram(string file, string arguments = "", bool runElevated = false){
|
||||||
@ -109,34 +107,34 @@ private static void SetClipboardData(DataObject obj){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<Browser> FindInstalledBrowsers(){
|
public static IEnumerable<Browser> FindInstalledBrowsers(){
|
||||||
IEnumerable<Browser> ReadBrowsersFromKey(RegistryHive hive){
|
static IEnumerable<Browser> ReadBrowsersFromKey(RegistryHive hive){
|
||||||
using(RegistryKey root = RegistryKey.OpenBaseKey(hive, RegistryView.Default))
|
using RegistryKey root = RegistryKey.OpenBaseKey(hive, RegistryView.Default);
|
||||||
using(RegistryKey browserList = root.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet", false)){
|
using RegistryKey browserList = root.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet", false);
|
||||||
if (browserList == null){
|
|
||||||
yield break;
|
if (browserList == null){
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(string sub in browserList.GetSubKeyNames()){
|
||||||
|
using RegistryKey browserKey = browserList.OpenSubKey(sub, false);
|
||||||
|
using RegistryKey shellKey = browserKey?.OpenSubKey(@"shell\open\command");
|
||||||
|
|
||||||
|
if (shellKey == null){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(string sub in browserList.GetSubKeyNames()){
|
string browserName = browserKey.GetValue(null) as string;
|
||||||
using(RegistryKey browserKey = browserList.OpenSubKey(sub, false))
|
string browserPath = shellKey.GetValue(null) as string;
|
||||||
using(RegistryKey shellKey = browserKey?.OpenSubKey(@"shell\open\command")){
|
|
||||||
if (shellKey == null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string browserName = browserKey.GetValue(null) as string;
|
if (string.IsNullOrEmpty(browserName) || string.IsNullOrEmpty(browserPath)){
|
||||||
string browserPath = shellKey.GetValue(null) as string;
|
continue;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(browserName) || string.IsNullOrEmpty(browserPath)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (browserPath[0] == '"' && browserPath[browserPath.Length-1] == '"'){
|
|
||||||
browserPath = browserPath.Substring(1, browserPath.Length-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
yield return new Browser(browserName, browserPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (browserPath[0] == '"' && browserPath[browserPath.Length-1] == '"'){
|
||||||
|
browserPath = browserPath.Substring(1, browserPath.Length-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new Browser(browserName, browserPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public Reporter(string logFile){
|
|||||||
|
|
||||||
public void SetupUnhandledExceptionHandler(string caption){
|
public void SetupUnhandledExceptionHandler(string caption){
|
||||||
AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
|
AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
|
||||||
if (args.ExceptionObject is Exception ex) {
|
if (args.ExceptionObject is Exception ex){
|
||||||
HandleException(caption, "An unhandled exception has occurred.", false, ex);
|
HandleException(caption, "An unhandled exception has occurred.", false, ex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -92,7 +92,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
onClick(ele.querySelector(".tdu-btn-later"), function(){
|
onClick(ele.querySelector(".tdu-btn-later"), function(){
|
||||||
$TDU.onUpdateDelayed();
|
|
||||||
exitSlide();
|
exitSlide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -49,11 +49,11 @@ Task<UpdateInfo> IUpdateCheckClient.Check(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UpdateInfo ParseFromJson(string json){
|
private UpdateInfo ParseFromJson(string json){
|
||||||
bool IsUpdaterAsset(JsonObject obj){
|
static bool IsUpdaterAsset(JsonObject obj){
|
||||||
return UpdaterAssetName == (string)obj["name"];
|
return UpdaterAssetName == (string)obj["name"];
|
||||||
}
|
}
|
||||||
|
|
||||||
string AssetDownloadUrl(JsonObject obj){
|
static string AssetDownloadUrl(JsonObject obj){
|
||||||
return (string)obj["browser_download_url"];
|
return (string)obj["browser_download_url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ private void RefreshControlPanel(){
|
|||||||
bool needsUpdate = !timerSync.Enabled || (useCompactLayout ? tablePanelFull.Enabled : tablePanelCompactBottom.Enabled);
|
bool needsUpdate = !timerSync.Enabled || (useCompactLayout ? tablePanelFull.Enabled : tablePanelCompactBottom.Enabled);
|
||||||
|
|
||||||
if (needsUpdate){
|
if (needsUpdate){
|
||||||
void Disable(TableLayoutPanel panel){
|
static void Disable(TableLayoutPanel panel){
|
||||||
panel.Controls.Clear();
|
panel.Controls.Clear();
|
||||||
panel.Visible = false;
|
panel.Visible = false;
|
||||||
panel.Enabled = false;
|
panel.Enabled = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user