1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-06 23:34:05 +02:00

Add option to use system proxy for all connections

Closes 
This commit is contained in:
chylex 2021-12-25 06:36:30 +01:00
parent 4a9590c1d9
commit e0025e02d1
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
5 changed files with 145 additions and 56 deletions

View File

@ -82,6 +82,8 @@ sealed class UserConfig : BaseConfig {
public string CustomBrowserCSS { get; set; } = null;
public string CustomNotificationCSS { get; set; } = null;
private bool _useSystemProxyForAllConnections;
public bool DevToolsInContextMenu { get; set; } = false;
public bool DevToolsWindowOnTop { get; set; } = true;
@ -133,6 +135,11 @@ public bool EnableColorProfileDetection {
set => UpdatePropertyWithRestartRequest(ref _enableColorProfileDetection, value);
}
public bool UseSystemProxyForAllConnections {
get => _useSystemProxyForAllConnections;
set => UpdatePropertyWithRestartRequest(ref _useSystemProxyForAllConnections, value);
}
public string CustomCefArgs {
get => _customCefArgs;
set => UpdatePropertyWithRestartRequest(ref _customCefArgs, value);

View File

@ -41,18 +41,20 @@ private void InitializeComponent() {
this.panelConfiguration = new System.Windows.Forms.Panel();
this.labelConfiguration = new System.Windows.Forms.Label();
this.flowPanel = new System.Windows.Forms.FlowLayoutPanel();
this.labelProxy = new System.Windows.Forms.Label();
this.checkUseSystemProxyForAllConnections = new System.Windows.Forms.CheckBox();
this.labelDevTools = new System.Windows.Forms.Label();
this.checkDevToolsInContextMenu = new System.Windows.Forms.CheckBox();
this.checkDevToolsWindowOnTop = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize) (this.numClearCacheThreshold)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numClearCacheThreshold)).BeginInit();
this.panelAppButtons.SuspendLayout();
this.panelClearCacheAuto.SuspendLayout();
this.panelConfiguration.SuspendLayout();
this.flowPanel.SuspendLayout();
this.SuspendLayout();
//
//
// btnClearCache
//
//
this.btnClearCache.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnClearCache.Location = new System.Drawing.Point(5, 135);
this.btnClearCache.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
@ -61,9 +63,9 @@ private void InitializeComponent() {
this.btnClearCache.TabIndex = 3;
this.btnClearCache.Text = "Clear Cache (...)";
this.btnClearCache.UseVisualStyleBackColor = true;
//
//
// btnEditCefArgs
//
//
this.btnEditCefArgs.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnEditCefArgs.Location = new System.Drawing.Point(5, 3);
this.btnEditCefArgs.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
@ -72,9 +74,9 @@ private void InitializeComponent() {
this.btnEditCefArgs.TabIndex = 0;
this.btnEditCefArgs.Text = "Edit CEF Arguments";
this.btnEditCefArgs.UseVisualStyleBackColor = true;
//
//
// btnEditCSS
//
//
this.btnEditCSS.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnEditCSS.Location = new System.Drawing.Point(154, 3);
this.btnEditCSS.Name = "btnEditCSS";
@ -82,9 +84,9 @@ private void InitializeComponent() {
this.btnEditCSS.TabIndex = 1;
this.btnEditCSS.Text = "Edit CSS";
this.btnEditCSS.UseVisualStyleBackColor = true;
//
//
// btnRestartArgs
//
//
this.btnRestartArgs.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnRestartArgs.Location = new System.Drawing.Point(154, 32);
this.btnRestartArgs.Name = "btnRestartArgs";
@ -92,9 +94,9 @@ private void InitializeComponent() {
this.btnRestartArgs.TabIndex = 3;
this.btnRestartArgs.Text = "Restart with Arguments";
this.btnRestartArgs.UseVisualStyleBackColor = true;
//
//
// btnRestart
//
//
this.btnRestart.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnRestart.Location = new System.Drawing.Point(154, 3);
this.btnRestart.Name = "btnRestart";
@ -102,9 +104,9 @@ private void InitializeComponent() {
this.btnRestart.TabIndex = 2;
this.btnRestart.Text = "Restart the Program";
this.btnRestart.UseVisualStyleBackColor = true;
//
//
// btnOpenAppFolder
//
//
this.btnOpenAppFolder.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnOpenAppFolder.Location = new System.Drawing.Point(5, 3);
this.btnOpenAppFolder.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
@ -113,9 +115,9 @@ private void InitializeComponent() {
this.btnOpenAppFolder.TabIndex = 0;
this.btnOpenAppFolder.Text = "Open Program Folder";
this.btnOpenAppFolder.UseVisualStyleBackColor = true;
//
//
// btnOpenDataFolder
//
//
this.btnOpenDataFolder.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnOpenDataFolder.Location = new System.Drawing.Point(5, 32);
this.btnOpenDataFolder.Margin = new System.Windows.Forms.Padding(5, 3, 3, 3);
@ -124,23 +126,39 @@ private void InitializeComponent() {
this.btnOpenDataFolder.TabIndex = 1;
this.btnOpenDataFolder.Text = "Open Data Folder";
this.btnOpenDataFolder.UseVisualStyleBackColor = true;
//
//
// numClearCacheThreshold
//
//
this.numClearCacheThreshold.Font = new System.Drawing.Font("Segoe UI", 9F);
this.numClearCacheThreshold.Increment = new decimal(new int[] { 50, 0, 0, 0 });
this.numClearCacheThreshold.Increment = new decimal(new int[] {
50,
0,
0,
0});
this.numClearCacheThreshold.Location = new System.Drawing.Point(210, 5);
this.numClearCacheThreshold.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
this.numClearCacheThreshold.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
this.numClearCacheThreshold.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numClearCacheThreshold.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numClearCacheThreshold.Name = "numClearCacheThreshold";
this.numClearCacheThreshold.Size = new System.Drawing.Size(89, 23);
this.numClearCacheThreshold.TabIndex = 1;
this.numClearCacheThreshold.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.numClearCacheThreshold.TextSuffix = " MB";
this.numClearCacheThreshold.Value = new decimal(new int[] { 250, 0, 0, 0 });
//
this.numClearCacheThreshold.Value = new decimal(new int[] {
250,
0,
0,
0});
//
// checkClearCacheAuto
//
//
this.checkClearCacheAuto.AutoSize = true;
this.checkClearCacheAuto.Font = new System.Drawing.Font("Segoe UI", 9F);
this.checkClearCacheAuto.Location = new System.Drawing.Point(6, 6);
@ -150,9 +168,9 @@ private void InitializeComponent() {
this.checkClearCacheAuto.TabIndex = 0;
this.checkClearCacheAuto.Text = "Clear Automatically When Above";
this.checkClearCacheAuto.UseVisualStyleBackColor = true;
//
//
// labelApp
//
//
this.labelApp.AutoSize = true;
this.labelApp.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelApp.Location = new System.Drawing.Point(0, 0);
@ -161,9 +179,9 @@ private void InitializeComponent() {
this.labelApp.Size = new System.Drawing.Size(97, 19);
this.labelApp.TabIndex = 0;
this.labelApp.Text = "APPLICATION";
//
//
// panelAppButtons
//
//
this.panelAppButtons.Controls.Add(this.btnOpenDataFolder);
this.panelAppButtons.Controls.Add(this.btnOpenAppFolder);
this.panelAppButtons.Controls.Add(this.btnRestart);
@ -173,9 +191,9 @@ private void InitializeComponent() {
this.panelAppButtons.Name = "panelAppButtons";
this.panelAppButtons.Size = new System.Drawing.Size(300, 62);
this.panelAppButtons.TabIndex = 1;
//
//
// labelCache
//
//
this.labelCache.AutoSize = true;
this.labelCache.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelCache.Location = new System.Drawing.Point(0, 112);
@ -184,9 +202,9 @@ private void InitializeComponent() {
this.labelCache.Size = new System.Drawing.Size(123, 19);
this.labelCache.TabIndex = 2;
this.labelCache.Text = "BROWSER CACHE";
//
//
// panelClearCacheAuto
//
//
this.panelClearCacheAuto.Controls.Add(this.checkClearCacheAuto);
this.panelClearCacheAuto.Controls.Add(this.numClearCacheThreshold);
this.panelClearCacheAuto.Location = new System.Drawing.Point(0, 163);
@ -194,9 +212,9 @@ private void InitializeComponent() {
this.panelClearCacheAuto.Name = "panelClearCacheAuto";
this.panelClearCacheAuto.Size = new System.Drawing.Size(300, 28);
this.panelClearCacheAuto.TabIndex = 4;
//
//
// panelConfiguration
//
//
this.panelConfiguration.Controls.Add(this.btnEditCSS);
this.panelConfiguration.Controls.Add(this.btnEditCefArgs);
this.panelConfiguration.Location = new System.Drawing.Point(0, 241);
@ -204,9 +222,9 @@ private void InitializeComponent() {
this.panelConfiguration.Name = "panelConfiguration";
this.panelConfiguration.Size = new System.Drawing.Size(300, 31);
this.panelConfiguration.TabIndex = 6;
//
//
// labelConfiguration
//
//
this.labelConfiguration.AutoSize = true;
this.labelConfiguration.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelConfiguration.Location = new System.Drawing.Point(0, 221);
@ -215,10 +233,11 @@ private void InitializeComponent() {
this.labelConfiguration.Size = new System.Drawing.Size(123, 19);
this.labelConfiguration.TabIndex = 5;
this.labelConfiguration.Text = "CONFIGURATION";
//
//
// flowPanel
//
this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left)));
//
this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.flowPanel.Controls.Add(this.labelApp);
this.flowPanel.Controls.Add(this.panelAppButtons);
this.flowPanel.Controls.Add(this.labelCache);
@ -226,6 +245,8 @@ private void InitializeComponent() {
this.flowPanel.Controls.Add(this.panelClearCacheAuto);
this.flowPanel.Controls.Add(this.labelConfiguration);
this.flowPanel.Controls.Add(this.panelConfiguration);
this.flowPanel.Controls.Add(this.labelProxy);
this.flowPanel.Controls.Add(this.checkUseSystemProxyForAllConnections);
this.flowPanel.Controls.Add(this.labelDevTools);
this.flowPanel.Controls.Add(this.checkDevToolsInContextMenu);
this.flowPanel.Controls.Add(this.checkDevToolsWindowOnTop);
@ -235,50 +256,73 @@ private void InitializeComponent() {
this.flowPanel.Size = new System.Drawing.Size(300, 462);
this.flowPanel.TabIndex = 0;
this.flowPanel.WrapContents = false;
//
//
// labelProxy
//
this.labelProxy.AutoSize = true;
this.labelProxy.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelProxy.Location = new System.Drawing.Point(0, 302);
this.labelProxy.Margin = new System.Windows.Forms.Padding(0, 30, 0, 1);
this.labelProxy.Name = "labelProxy";
this.labelProxy.Size = new System.Drawing.Size(54, 19);
this.labelProxy.TabIndex = 7;
this.labelProxy.Text = "PROXY";
//
// checkUseSystemProxyForAllConnections
//
this.checkUseSystemProxyForAllConnections.AutoSize = true;
this.checkUseSystemProxyForAllConnections.Font = new System.Drawing.Font("Segoe UI", 9F);
this.checkUseSystemProxyForAllConnections.Location = new System.Drawing.Point(6, 328);
this.checkUseSystemProxyForAllConnections.Margin = new System.Windows.Forms.Padding(6, 6, 3, 2);
this.checkUseSystemProxyForAllConnections.Name = "checkUseSystemProxyForAllConnections";
this.checkUseSystemProxyForAllConnections.Size = new System.Drawing.Size(223, 19);
this.checkUseSystemProxyForAllConnections.TabIndex = 8;
this.checkUseSystemProxyForAllConnections.Text = "Use System Proxy for All Connections";
this.checkUseSystemProxyForAllConnections.UseVisualStyleBackColor = true;
//
// labelDevTools
//
//
this.labelDevTools.AutoSize = true;
this.labelDevTools.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelDevTools.Location = new System.Drawing.Point(0, 302);
this.labelDevTools.Location = new System.Drawing.Point(0, 379);
this.labelDevTools.Margin = new System.Windows.Forms.Padding(0, 30, 0, 1);
this.labelDevTools.Name = "labelDevTools";
this.labelDevTools.Size = new System.Drawing.Size(156, 19);
this.labelDevTools.TabIndex = 7;
this.labelDevTools.TabIndex = 9;
this.labelDevTools.Text = "DEVELOPMENT TOOLS";
//
//
// checkDevToolsInContextMenu
//
//
this.checkDevToolsInContextMenu.AutoSize = true;
this.checkDevToolsInContextMenu.Font = new System.Drawing.Font("Segoe UI", 9F);
this.checkDevToolsInContextMenu.Location = new System.Drawing.Point(6, 328);
this.checkDevToolsInContextMenu.Location = new System.Drawing.Point(6, 405);
this.checkDevToolsInContextMenu.Margin = new System.Windows.Forms.Padding(6, 6, 3, 2);
this.checkDevToolsInContextMenu.Name = "checkDevToolsInContextMenu";
this.checkDevToolsInContextMenu.Size = new System.Drawing.Size(201, 19);
this.checkDevToolsInContextMenu.TabIndex = 8;
this.checkDevToolsInContextMenu.TabIndex = 10;
this.checkDevToolsInContextMenu.Text = "Show Dev Tools in Context Menu";
this.checkDevToolsInContextMenu.UseVisualStyleBackColor = true;
//
//
// checkDevToolsWindowOnTop
//
//
this.checkDevToolsWindowOnTop.AutoSize = true;
this.checkDevToolsWindowOnTop.Font = new System.Drawing.Font("Segoe UI", 9F);
this.checkDevToolsWindowOnTop.Location = new System.Drawing.Point(6, 352);
this.checkDevToolsWindowOnTop.Location = new System.Drawing.Point(6, 429);
this.checkDevToolsWindowOnTop.Margin = new System.Windows.Forms.Padding(6, 3, 3, 2);
this.checkDevToolsWindowOnTop.Name = "checkDevToolsWindowOnTop";
this.checkDevToolsWindowOnTop.Size = new System.Drawing.Size(168, 19);
this.checkDevToolsWindowOnTop.TabIndex = 9;
this.checkDevToolsWindowOnTop.TabIndex = 11;
this.checkDevToolsWindowOnTop.Text = "Dev Tools Window On Top";
this.checkDevToolsWindowOnTop.UseVisualStyleBackColor = true;
//
//
// TabSettingsAdvanced
//
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.flowPanel);
this.Name = "TabSettingsAdvanced";
this.Size = new System.Drawing.Size(631, 480);
((System.ComponentModel.ISupportInitialize) (this.numClearCacheThreshold)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numClearCacheThreshold)).EndInit();
this.panelAppButtons.ResumeLayout(false);
this.panelClearCacheAuto.ResumeLayout(false);
this.panelClearCacheAuto.PerformLayout();
@ -286,8 +330,11 @@ private void InitializeComponent() {
this.flowPanel.ResumeLayout(false);
this.flowPanel.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnClearCache;
private System.Windows.Forms.ToolTip toolTip;
private System.Windows.Forms.Button btnEditCefArgs;
@ -308,7 +355,7 @@ private void InitializeComponent() {
private System.Windows.Forms.Label labelDevTools;
private System.Windows.Forms.CheckBox checkDevToolsInContextMenu;
private System.Windows.Forms.CheckBox checkDevToolsWindowOnTop;
#endregion
private System.Windows.Forms.Label labelProxy;
private System.Windows.Forms.CheckBox checkUseSystemProxyForAllConnections;
}
}

View File

@ -44,6 +44,12 @@ public TabSettingsAdvanced(Action<string> reinjectBrowserCSS, Action openDevTool
toolTip.SetToolTip(btnEditCefArgs, "Set custom command line arguments for Chromium Embedded Framework.");
toolTip.SetToolTip(btnEditCSS, "Set custom CSS for browser and notification windows.");
// proxy
toolTip.SetToolTip(checkUseSystemProxyForAllConnections, "Sets whether all connections should automatically detect and use the system proxy.\r\nBy default, only the browser component uses the system proxy, while other parts (such as update checks) ignore it.\r\nDisabled by default because Windows' proxy detection can be really slow.");
checkUseSystemProxyForAllConnections.Checked = Config.UseSystemProxyForAllConnections;
// development tools
toolTip.SetToolTip(checkDevToolsInContextMenu, "Sets whether all context menus include an option to open dev tools.");
@ -65,6 +71,8 @@ public override void OnReady() {
btnEditCefArgs.Click += btnEditCefArgs_Click;
btnEditCSS.Click += btnEditCSS_Click;
checkUseSystemProxyForAllConnections.CheckedChanged += checkUseSystemProxyForAllConnections_CheckedChanged;
checkDevToolsWindowOnTop.CheckedChanged += checkDevToolsWindowOnTop_CheckedChanged;
checkDevToolsInContextMenu.CheckedChanged += checkDevToolsInContextMenuOnCheckedChanged;
}
@ -162,6 +170,14 @@ private void RestoreParentForm() {
#endregion
#region Proxy
private void checkUseSystemProxyForAllConnections_CheckedChanged(object sender, EventArgs e) {
Config.UseSystemProxyForAllConnections = checkUseSystemProxyForAllConnections.Checked;
}
#endregion
#region Development Tools
private void checkDevToolsInContextMenuOnCheckedChanged(object sender, EventArgs e) {

View File

@ -111,6 +111,10 @@ private static void Main() {
return;
}
if (Config.User.UseSystemProxyForAllConnections) {
WebUtils.EnableSystemProxy();
}
BrowserCache.RefreshTimer();
CefSharpSettings.WcfEnabled = false;

View File

@ -6,6 +6,7 @@
namespace TweetLib.Core.Utils {
public static class WebUtils {
private static bool hasMicrosoftBeenBroughtTo2008Yet;
private static bool hasSystemProxyBeenEnabled;
private static void EnsureTLS12() {
if (!hasMicrosoftBeenBroughtTo2008Yet) {
@ -15,10 +16,24 @@ private static void EnsureTLS12() {
}
}
private static bool UseSystemProxy { get; set; } = false;
public static void EnableSystemProxy() {
if (!hasSystemProxyBeenEnabled) {
UseSystemProxy = true;
hasSystemProxyBeenEnabled = true;
}
}
public static WebClient NewClient(string userAgent) {
EnsureTLS12();
WebClient client = new WebClient { Proxy = null };
WebClient client = new WebClient();
if (!UseSystemProxy) {
client.Proxy = null;
}
client.Headers[HttpRequestHeader.UserAgent] = userAgent;
return client;
}