diff --git a/Core/Bridge/PropertyBridge.cs b/Core/Bridge/PropertyBridge.cs index 0aa5e197..a750cf91 100644 --- a/Core/Bridge/PropertyBridge.cs +++ b/Core/Bridge/PropertyBridge.cs @@ -8,8 +8,8 @@ public enum Environment{ } public static string GenerateScript(Environment environment){ - string Bool(bool value) => value ? "true;" : "false;"; - string Str(string value) => '"'+value+"\";"; + static string Bool(bool value) => value ? "true;" : "false;"; + static string Str(string value) => '"'+value+"\";"; UserConfig config = Program.Config.User; StringBuilder build = new StringBuilder(128).Append("(function(x){"); diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs index a56721d5..a754846c 100644 --- a/Core/Bridge/TweetDeckBridge.cs +++ b/Core/Bridge/TweetDeckBridge.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Windows.Forms; using TweetDuck.Core.Controls; -using TweetDuck.Core.Management; +using TweetDuck.Core.Handling; using TweetDuck.Core.Notification; using TweetDuck.Core.Other; using TweetDuck.Core.Utils; @@ -10,12 +10,9 @@ namespace TweetDuck.Core.Bridge{ [SuppressMessage("ReSharper", "UnusedMember.Global")] 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(){ - FontSize = NotificationHeadLayout = null; + FormNotificationBase.FontSize = null; + FormNotificationBase.HeadLayout = null; } private readonly FormBrowser form; @@ -47,17 +44,17 @@ public void OnIntroductionClosed(bool showGuide, bool allowDataCollection){ public void LoadNotificationLayout(string fontSize, string headLayout){ form.InvokeAsyncSafe(() => { - FontSize = fontSize; - NotificationHeadLayout = headLayout; + FormNotificationBase.FontSize = fontSize; + FormNotificationBase.HeadLayout = headLayout; }); } 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){ - ContextInfo.SetChirp(tweetUrl, quoteUrl, chirpAuthors, chirpImages); + ContextMenuBase.CurrentInfo.SetChirp(tweetUrl, quoteUrl, chirpAuthors, chirpImages); } public void DisplayTooltip(string text){ diff --git a/Core/Bridge/UpdateBridge.cs b/Core/Bridge/UpdateBridge.cs index 139e731a..ada1fdfb 100644 --- a/Core/Bridge/UpdateBridge.cs +++ b/Core/Bridge/UpdateBridge.cs @@ -13,7 +13,6 @@ class UpdateBridge{ private UpdateInfo nextUpdate = null; public event EventHandler<UpdateInfo> UpdateAccepted; - public event EventHandler<UpdateInfo> UpdateDelayed; public event EventHandler<UpdateInfo> UpdateDismissed; public UpdateBridge(UpdateHandler updates, Control sync){ @@ -56,10 +55,6 @@ public void OnUpdateAccepted(){ HandleInteractionEvent(UpdateAccepted); } - public void OnUpdateDelayed(){ - HandleInteractionEvent(UpdateDelayed); - } - public void OnUpdateDismissed(){ HandleInteractionEvent(UpdateDismissed); diff --git a/Core/Controls/ControlExtensions.cs b/Core/Controls/ControlExtensions.cs index 18aeee23..db41113f 100644 --- a/Core/Controls/ControlExtensions.cs +++ b/Core/Controls/ControlExtensions.cs @@ -21,9 +21,8 @@ public static void InvokeAsyncSafe(this Control control, Action func){ } public static float GetDPIScale(this Control control){ - using(Graphics graphics = control.CreateGraphics()){ - return graphics.DpiY/96F; - } + using Graphics graphics = control.CreateGraphics(); + return graphics.DpiY / 96F; } 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); return false; } - else return true; + + return true; } public static void EnableMultilineShortcuts(this TextBox textBox){ diff --git a/Core/Controls/LabelVertical.cs b/Core/Controls/LabelVertical.cs index 94e48ff2..aec4b5f2 100644 --- a/Core/Controls/LabelVertical.cs +++ b/Core/Controls/LabelVertical.cs @@ -8,15 +8,14 @@ sealed class LabelVertical : Label{ protected override void OnPaint(PaintEventArgs e){ 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){ - string str = chr.ToString(); - float x = (ClientRectangle.Width-e.Graphics.MeasureString(str, Font).Width)/2F; + foreach(char chr in Text){ + string str = chr.ToString(); + float x = (ClientRectangle.Width-e.Graphics.MeasureString(str, Font).Width)/2F; - e.Graphics.DrawString(str, Font, brush, x, y); - y += LineHeight; - } + e.Graphics.DrawString(str, Font, brush, x, y); + y += LineHeight; } } } diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 77723f3d..3c7a9bf7 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -78,7 +78,6 @@ public FormBrowser(){ this.updateBridge = new UpdateBridge(updates, this); this.updateBridge.UpdateAccepted += updateBridge_UpdateAccepted; - this.updateBridge.UpdateDelayed += updateBridge_UpdateDelayed; this.updateBridge.UpdateDismissed += updateBridge_UpdateDismissed; 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){ Config.DismissedUpdate = update.VersionTag; Config.Save(); diff --git a/Core/Handling/ContextMenuBase.cs b/Core/Handling/ContextMenuBase.cs index 74ea9d82..45380941 100644 --- a/Core/Handling/ContextMenuBase.cs +++ b/Core/Handling/ContextMenuBase.cs @@ -7,7 +7,6 @@ using System.Linq; using TweetDuck.Configuration; using TweetDuck.Core.Adapters; -using TweetDuck.Core.Bridge; using TweetDuck.Core.Management; using TweetDuck.Core.Notification; using TweetDuck.Core.Other; @@ -17,8 +16,9 @@ namespace TweetDuck.Core.Handling{ 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 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){ if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading){ - Context = TweetDeckBridge.ContextInfo.Reset(); + Context = CurrentInfo.Reset(); } else{ - Context = TweetDeckBridge.ContextInfo.Create(parameters); + Context = CurrentInfo.Create(parameters); } 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.AddSeparator(); } - - string TextOpen(string name) => "Open "+name+" in browser"; - string TextCopy(string name) => "Copy "+name+" address"; - string TextSave(string name) => "Save "+name+" as..."; + + static string TextOpen(string name) => "Open "+name+" in browser"; + static string TextCopy(string name) => "Copy "+name+" address"; + static string TextSave(string name) => "Save "+name+" as..."; if (Context.Types.HasFlag(ContextInfo.ContextType.Link) && !Context.UnsafeLinkUrl.EndsWith("tweetdeck.twitter.com/#", StringComparison.Ordinal)){ 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){ - Context = TweetDeckBridge.ContextInfo.Reset(); + Context = CurrentInfo.Reset(); } public virtual bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback){ diff --git a/Core/Handling/General/BrowserProcessHandler.cs b/Core/Handling/General/BrowserProcessHandler.cs index f3078559..4a010fe9 100644 --- a/Core/Handling/General/BrowserProcessHandler.cs +++ b/Core/Handling/General/BrowserProcessHandler.cs @@ -11,12 +11,11 @@ public static Task UpdatePrefs(){ private static void UpdatePrefsInternal(){ 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("spellcheck.dictionary", config.SpellCheckLanguage, out string _); - ctx.SetPreference("settings.a11y.animation_policy", config.EnableAnimatedImages ? "allowed" : "none", out string _); - } + ctx.SetPreference("browser.enable_spellchecking", config.EnableSpellCheck, out string _); + ctx.SetPreference("spellcheck.dictionary", config.SpellCheckLanguage, out string _); + ctx.SetPreference("settings.a11y.animation_policy", config.EnableAnimatedImages ? "allowed" : "none", out string _); } void IBrowserProcessHandler.OnContextInitialized(){ diff --git a/Core/Management/ProfileManager.cs b/Core/Management/ProfileManager.cs index 5e383fc3..7e3e1632 100644 --- a/Core/Management/ProfileManager.cs +++ b/Core/Management/ProfileManager.cs @@ -73,28 +73,27 @@ public Items FindImportItems(){ Items items = Items.None; try{ - using(CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))){ - string key; + using CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None)); + string key; - while((key = stream.SkipFile()) != null){ - switch(key){ - case "config": - items |= Items.UserConfig; - break; + while((key = stream.SkipFile()) != null){ + switch(key){ + case "config": + items |= Items.UserConfig; + break; - case "system": - items |= Items.SystemConfig; - break; + case "system": + items |= Items.SystemConfig; + break; - case "plugin.config": - case "plugin.data": - items |= Items.PluginData; - break; + case "plugin.config": + case "plugin.data": + items |= Items.PluginData; + break; - case "cookies": - items |= Items.Session; - break; - } + case "cookies": + items |= Items.Session; + break; } } }catch(Exception){ diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs index 05645324..5801f13b 100644 --- a/Core/Notification/FormNotificationBase.cs +++ b/Core/Notification/FormNotificationBase.cs @@ -3,7 +3,6 @@ using System.Windows.Forms; using CefSharp; using TweetDuck.Configuration; -using TweetDuck.Core.Bridge; using TweetDuck.Core.Controls; using TweetDuck.Core.Handling; using TweetDuck.Core.Handling.General; @@ -17,10 +16,13 @@ namespace TweetDuck.Core.Notification{ 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")); - 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{ - get => TweetDeckBridge.FontSize switch{ + get => FontSize switch{ "largest" => 4, "large" => 3, "small" => 1, diff --git a/Core/Notification/FormNotificationMain.cs b/Core/Notification/FormNotificationMain.cs index b88aadab..e45a6ef5 100644 --- a/Core/Notification/FormNotificationMain.cs +++ b/Core/Notification/FormNotificationMain.cs @@ -220,7 +220,7 @@ public override void ResumeNotification(){ } 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){ html = injection.InjectInto(html); diff --git a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs index d8417e05..0250f494 100644 --- a/Core/Notification/Screenshot/FormNotificationScreenshotable.cs +++ b/Core/Notification/Screenshot/FormNotificationScreenshotable.cs @@ -4,7 +4,6 @@ using System.Windows.Forms; using CefSharp; using TweetDuck.Core.Adapters; -using TweetDuck.Core.Bridge; using TweetDuck.Core.Controls; using TweetDuck.Core.Other; using TweetDuck.Core.Utils; @@ -47,7 +46,7 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin } 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){ html = injection.InjectInto(html); diff --git a/Core/Other/Analytics/AnalyticsReportGenerator.cs b/Core/Other/Analytics/AnalyticsReportGenerator.cs index 791161a0..7f1dd6c1 100644 --- a/Core/Other/Analytics/AnalyticsReportGenerator.cs +++ b/Core/Other/Analytics/AnalyticsReportGenerator.cs @@ -143,19 +143,19 @@ static AnalyticsReportGenerator(){ string osName, osEdition, osBuild; try{ - 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+)?) (.*)$"); + using RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false); - if (match.Success){ - osName = match.Groups[1].Value; - osEdition = match.Groups[2].Value; - } + // 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){ + osName = match.Groups[1].Value; + osEdition = match.Groups[2].Value; } } }catch{ @@ -167,10 +167,10 @@ static AnalyticsReportGenerator(){ SystemBuild = osBuild ?? "(unknown)"; try{ - using(ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Capacity FROM Win32_PhysicalMemory")){ - foreach(ManagementBaseObject obj in searcher.Get()){ - RamSize += (int)((ulong)obj["Capacity"]/(1024L*1024L)); - } + using ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Capacity FROM Win32_PhysicalMemory"); + + foreach(ManagementBaseObject obj in searcher.Get()){ + RamSize += (int)((ulong)obj["Capacity"]/(1024L*1024L)); } }catch{ RamSize = 0; @@ -179,13 +179,13 @@ static AnalyticsReportGenerator(){ string gpu = null; try{ - using(ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_VideoController")){ - foreach(ManagementBaseObject obj in searcher.Get()){ - string vendor = obj["Caption"] as string; + using ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_VideoController"); - if (!string.IsNullOrEmpty(vendor)){ - gpu = vendor; - } + foreach(ManagementBaseObject obj in searcher.Get()){ + string vendor = obj["Caption"] as string; + + if (!string.IsNullOrEmpty(vendor)){ + gpu = vendor; } } }catch{ diff --git a/Core/Other/Settings/BaseTabSettings.cs b/Core/Other/Settings/BaseTabSettings.cs index 7dcda2bd..f469a80b 100644 --- a/Core/Other/Settings/BaseTabSettings.cs +++ b/Core/Other/Settings/BaseTabSettings.cs @@ -9,7 +9,7 @@ class BaseTabSettings : UserControl{ public IEnumerable<Control> InteractiveControls{ get{ - IEnumerable<Control> FindInteractiveControls(Control parent){ + static IEnumerable<Control> FindInteractiveControls(Control parent){ foreach(Control control in parent.Controls){ if (control is Panel subPanel){ foreach(Control subControl in FindInteractiveControls(subPanel)){ diff --git a/Core/TweetDeckBrowser.cs b/Core/TweetDeckBrowser.cs index e7e4c707..b76c80ee 100644 --- a/Core/TweetDeckBrowser.cs +++ b/Core/TweetDeckBrowser.cs @@ -16,6 +16,7 @@ using TweetLib.Core.Features.Plugins; using TweetLib.Core.Features.Plugins.Enums; using TweetLib.Core.Features.Twitter; +using TweetLib.Core.Utils; namespace TweetDuck.Core{ sealed class TweetDeckBrowser : IDisposable{ @@ -178,7 +179,10 @@ private void browser_LoadError(object sender, LoadErrorEventArgs e){ string errorPage = Program.Resources.LoadSilent("pages/error.html"); 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); } } diff --git a/Core/Utils/BrowserUtils.cs b/Core/Utils/BrowserUtils.cs index 68673a7b..b7681d6a 100644 --- a/Core/Utils/BrowserUtils.cs +++ b/Core/Utils/BrowserUtils.cs @@ -8,7 +8,6 @@ using TweetDuck.Configuration; using TweetDuck.Core.Other; using TweetLib.Core.Features.Twitter; -using TweetLib.Core.Utils; namespace TweetDuck.Core.Utils{ static class BrowserUtils{ @@ -61,8 +60,12 @@ public static ChromiumWebBrowser AsControl(this IWebBrowser browserControl){ } 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){ - SetZoomLevel(browser.GetBrowser(), Config.ZoomLevel); + SetZoomLevel(browser.GetBrowserHost(), Config.ZoomLevel); } Config.ZoomLevelChanged += UpdateZoomLevel; @@ -70,7 +73,7 @@ void UpdateZoomLevel(object sender, EventArgs args){ browser.FrameLoadStart += (sender, args) => { 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){ - if (string.IsNullOrWhiteSpace(query))return; + if (string.IsNullOrWhiteSpace(query)){ + return; + } 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){ return (int)Math.Round(baseValue*scaleFactor); } - - public static void SetZoomLevel(IBrowser browser, int percentage){ - browser.GetHost().SetZoomLevel(Math.Log(percentage/100.0, 1.2)); - } } } diff --git a/Core/Utils/TwitterUtils.cs b/Core/Utils/TwitterUtils.cs index 87a66db8..d0350594 100644 --- a/Core/Utils/TwitterUtils.cs +++ b/Core/Utils/TwitterUtils.cs @@ -25,7 +25,7 @@ static class TwitterUtils{ }; public static void ViewImage(string url, ImageQuality quality){ - void ViewImageInternal(string path){ + static void ViewImageInternal(string path){ string ext = Path.GetExtension(path); 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}") }){ 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); } diff --git a/Core/Utils/WindowsUtils.cs b/Core/Utils/WindowsUtils.cs index b2a47080..501d0f9b 100644 --- a/Core/Utils/WindowsUtils.cs +++ b/Core/Utils/WindowsUtils.cs @@ -11,19 +11,17 @@ namespace TweetDuck.Core.Utils{ 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> RegexOffsetClipboardHtml = new Lazy<Regex>(() => new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)"), false); - private static readonly bool IsWindows8OrNewer; - - public static bool ShouldAvoidToolWindow { get; } - public static bool IsAeroEnabled => IsWindows8OrNewer || (NativeMethods.DwmIsCompositionEnabled(out bool isCompositionEnabled) == 0 && isCompositionEnabled); - - static WindowsUtils(){ + private static bool OSVersionEquals(int major, int minor){ Version ver = Environment.OSVersion.Version; - IsWindows8OrNewer = ver.Major == 6 && ver.Minor == 2; // windows 8/10 - - ShouldAvoidToolWindow = IsWindows8OrNewer; + return ver.Major == major && ver.Minor == minor; } 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(){ - IEnumerable<Browser> ReadBrowsersFromKey(RegistryHive hive){ - using(RegistryKey root = RegistryKey.OpenBaseKey(hive, RegistryView.Default)) - using(RegistryKey browserList = root.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet", false)){ - if (browserList == null){ - yield break; + static IEnumerable<Browser> ReadBrowsersFromKey(RegistryHive hive){ + using RegistryKey root = RegistryKey.OpenBaseKey(hive, RegistryView.Default); + using RegistryKey browserList = root.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet", false); + + 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()){ - using(RegistryKey browserKey = browserList.OpenSubKey(sub, false)) - using(RegistryKey shellKey = browserKey?.OpenSubKey(@"shell\open\command")){ - if (shellKey == null){ - continue; - } + string browserName = browserKey.GetValue(null) as string; + string browserPath = shellKey.GetValue(null) as string; - string browserName = browserKey.GetValue(null) as string; - string browserPath = shellKey.GetValue(null) as string; - - 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 (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); } } diff --git a/Reporter.cs b/Reporter.cs index 7c7c7b92..10d6abb6 100644 --- a/Reporter.cs +++ b/Reporter.cs @@ -19,7 +19,7 @@ public Reporter(string logFile){ public void SetupUnhandledExceptionHandler(string caption){ 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); } }; diff --git a/Resources/Scripts/update.js b/Resources/Scripts/update.js index 41dd9074..8d353f7b 100644 --- a/Resources/Scripts/update.js +++ b/Resources/Scripts/update.js @@ -92,7 +92,6 @@ }); onClick(ele.querySelector(".tdu-btn-later"), function(){ - $TDU.onUpdateDelayed(); exitSlide(); }); diff --git a/Updates/UpdateCheckClient.cs b/Updates/UpdateCheckClient.cs index 4013f56b..4862c07f 100644 --- a/Updates/UpdateCheckClient.cs +++ b/Updates/UpdateCheckClient.cs @@ -49,11 +49,11 @@ Task<UpdateInfo> IUpdateCheckClient.Check(){ } private UpdateInfo ParseFromJson(string json){ - bool IsUpdaterAsset(JsonObject obj){ + static bool IsUpdaterAsset(JsonObject obj){ return UpdaterAssetName == (string)obj["name"]; } - string AssetDownloadUrl(JsonObject obj){ + static string AssetDownloadUrl(JsonObject obj){ return (string)obj["browser_download_url"]; } diff --git a/video/FormPlayer.cs b/video/FormPlayer.cs index 312a6360..bc38772e 100644 --- a/video/FormPlayer.cs +++ b/video/FormPlayer.cs @@ -98,7 +98,7 @@ private void RefreshControlPanel(){ bool needsUpdate = !timerSync.Enabled || (useCompactLayout ? tablePanelFull.Enabled : tablePanelCompactBottom.Enabled); if (needsUpdate){ - void Disable(TableLayoutPanel panel){ + static void Disable(TableLayoutPanel panel){ panel.Controls.Clear(); panel.Visible = false; panel.Enabled = false;