mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-13 17:34:08 +02:00
Add a command line argument to use Chrome user agent
This commit is contained in:
parent
a82b0e3622
commit
988fae75c3
@ -5,6 +5,7 @@ namespace TweetDuck.Configuration{
|
||||
static class Arguments{
|
||||
// public args
|
||||
public const string ArgDataFolder = "-datafolder";
|
||||
public const string ArgChromeUA = "-chromeagent";
|
||||
public const string ArgLogging = "-log";
|
||||
|
||||
// internal args
|
||||
|
@ -29,6 +29,7 @@ private void InitializeComponent() {
|
||||
this.cbLogging = new System.Windows.Forms.CheckBox();
|
||||
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.tbDataFolder = new System.Windows.Forms.TextBox();
|
||||
this.cbChromeAgent = new System.Windows.Forms.CheckBox();
|
||||
this.tbShortcutTarget = new System.Windows.Forms.TextBox();
|
||||
this.labelDataFolder = new System.Windows.Forms.Label();
|
||||
this.labelShortcutTarget = new System.Windows.Forms.Label();
|
||||
@ -41,7 +42,7 @@ private void InitializeComponent() {
|
||||
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnCancel.AutoSize = true;
|
||||
this.btnCancel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.btnCancel.Location = new System.Drawing.Point(214, 148);
|
||||
this.btnCancel.Location = new System.Drawing.Point(215, 170);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.btnCancel.Size = new System.Drawing.Size(57, 25);
|
||||
@ -55,7 +56,7 @@ private void InitializeComponent() {
|
||||
this.btnRestart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnRestart.AutoSize = true;
|
||||
this.btnRestart.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.btnRestart.Location = new System.Drawing.Point(151, 148);
|
||||
this.btnRestart.Location = new System.Drawing.Point(152, 170);
|
||||
this.btnRestart.Name = "btnRestart";
|
||||
this.btnRestart.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.btnRestart.Size = new System.Drawing.Size(57, 25);
|
||||
@ -74,18 +75,31 @@ private void InitializeComponent() {
|
||||
this.cbLogging.Size = new System.Drawing.Size(70, 19);
|
||||
this.cbLogging.TabIndex = 0;
|
||||
this.cbLogging.Text = "Logging";
|
||||
this.toolTip.SetToolTip(this.cbLogging, "Logging JavaScript output into TD_Console.txt file in the data folder.");
|
||||
this.toolTip.SetToolTip(this.cbLogging, "Logs JavaScript output into TD_Console.txt file in the data folder.");
|
||||
this.cbLogging.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// tbDataFolder
|
||||
//
|
||||
this.tbDataFolder.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.tbDataFolder.Location = new System.Drawing.Point(3, 54);
|
||||
this.tbDataFolder.Location = new System.Drawing.Point(3, 78);
|
||||
this.tbDataFolder.Name = "tbDataFolder";
|
||||
this.tbDataFolder.Size = new System.Drawing.Size(260, 23);
|
||||
this.tbDataFolder.TabIndex = 2;
|
||||
this.tbDataFolder.TabIndex = 3;
|
||||
this.toolTip.SetToolTip(this.tbDataFolder, "Path to the data folder. Must be either an absolute path,\r\nor a simple folder nam" +
|
||||
"e that will be created in LocalAppData.");
|
||||
//
|
||||
// cbChromeAgent
|
||||
//
|
||||
this.cbChromeAgent.AutoSize = true;
|
||||
this.cbChromeAgent.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.cbChromeAgent.Location = new System.Drawing.Point(3, 27);
|
||||
this.cbChromeAgent.Margin = new System.Windows.Forms.Padding(3, 3, 3, 2);
|
||||
this.cbChromeAgent.Name = "cbChromeAgent";
|
||||
this.cbChromeAgent.Size = new System.Drawing.Size(130, 19);
|
||||
this.cbChromeAgent.TabIndex = 1;
|
||||
this.cbChromeAgent.Text = "Chrome User Agent";
|
||||
this.toolTip.SetToolTip(this.cbChromeAgent, "Masks user agent using a generic Chrome UA.");
|
||||
this.cbChromeAgent.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// tbShortcutTarget
|
||||
//
|
||||
@ -93,33 +107,33 @@ private void InitializeComponent() {
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.tbShortcutTarget.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.tbShortcutTarget.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.tbShortcutTarget.Location = new System.Drawing.Point(3, 110);
|
||||
this.tbShortcutTarget.Location = new System.Drawing.Point(3, 134);
|
||||
this.tbShortcutTarget.Name = "tbShortcutTarget";
|
||||
this.tbShortcutTarget.ReadOnly = true;
|
||||
this.tbShortcutTarget.Size = new System.Drawing.Size(260, 23);
|
||||
this.tbShortcutTarget.TabIndex = 4;
|
||||
this.tbShortcutTarget.TabIndex = 5;
|
||||
this.tbShortcutTarget.Click += new System.EventHandler(this.tbShortcutTarget_Click);
|
||||
//
|
||||
// labelDataFolder
|
||||
//
|
||||
this.labelDataFolder.AutoSize = true;
|
||||
this.labelDataFolder.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.labelDataFolder.Location = new System.Drawing.Point(3, 36);
|
||||
this.labelDataFolder.Location = new System.Drawing.Point(3, 60);
|
||||
this.labelDataFolder.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
|
||||
this.labelDataFolder.Name = "labelDataFolder";
|
||||
this.labelDataFolder.Size = new System.Drawing.Size(67, 15);
|
||||
this.labelDataFolder.TabIndex = 1;
|
||||
this.labelDataFolder.TabIndex = 2;
|
||||
this.labelDataFolder.Text = "Data Folder";
|
||||
//
|
||||
// labelShortcutTarget
|
||||
//
|
||||
this.labelShortcutTarget.AutoSize = true;
|
||||
this.labelShortcutTarget.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
|
||||
this.labelShortcutTarget.Location = new System.Drawing.Point(3, 92);
|
||||
this.labelShortcutTarget.Location = new System.Drawing.Point(3, 116);
|
||||
this.labelShortcutTarget.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
|
||||
this.labelShortcutTarget.Name = "labelShortcutTarget";
|
||||
this.labelShortcutTarget.Size = new System.Drawing.Size(171, 15);
|
||||
this.labelShortcutTarget.TabIndex = 3;
|
||||
this.labelShortcutTarget.TabIndex = 4;
|
||||
this.labelShortcutTarget.Text = "Shortcut Target (click to select)";
|
||||
//
|
||||
// flowPanel
|
||||
@ -128,6 +142,7 @@ private void InitializeComponent() {
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.flowPanel.Controls.Add(this.cbLogging);
|
||||
this.flowPanel.Controls.Add(this.cbChromeAgent);
|
||||
this.flowPanel.Controls.Add(this.labelDataFolder);
|
||||
this.flowPanel.Controls.Add(this.tbDataFolder);
|
||||
this.flowPanel.Controls.Add(this.labelShortcutTarget);
|
||||
@ -136,7 +151,7 @@ private void InitializeComponent() {
|
||||
this.flowPanel.Location = new System.Drawing.Point(9, 9);
|
||||
this.flowPanel.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.flowPanel.Name = "flowPanel";
|
||||
this.flowPanel.Size = new System.Drawing.Size(266, 138);
|
||||
this.flowPanel.Size = new System.Drawing.Size(266, 160);
|
||||
this.flowPanel.TabIndex = 0;
|
||||
this.flowPanel.WrapContents = false;
|
||||
//
|
||||
@ -144,7 +159,7 @@ private void InitializeComponent() {
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(284, 185);
|
||||
this.ClientSize = new System.Drawing.Size(284, 207);
|
||||
this.Controls.Add(this.flowPanel);
|
||||
this.Controls.Add(this.btnRestart);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
@ -172,5 +187,6 @@ private void InitializeComponent() {
|
||||
private System.Windows.Forms.TextBox tbShortcutTarget;
|
||||
private System.Windows.Forms.Label labelShortcutTarget;
|
||||
private System.Windows.Forms.FlowLayoutPanel flowPanel;
|
||||
private System.Windows.Forms.CheckBox cbChromeAgent;
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ public DialogSettingsRestart(CommandLineArgs currentArgs){
|
||||
cbLogging.Checked = currentArgs.HasFlag(Arguments.ArgLogging);
|
||||
cbLogging.CheckedChanged += control_Change;
|
||||
|
||||
cbChromeAgent.Checked = currentArgs.HasFlag(Arguments.ArgChromeUA);
|
||||
cbChromeAgent.CheckedChanged += control_Change;
|
||||
|
||||
if (Program.IsPortable){
|
||||
tbDataFolder.Text = "Not available in portable version";
|
||||
tbDataFolder.Enabled = false;
|
||||
@ -34,6 +37,10 @@ private void control_Change(object sender, EventArgs e){
|
||||
Args.AddFlag(Arguments.ArgLogging);
|
||||
}
|
||||
|
||||
if (cbChromeAgent.Checked){
|
||||
Args.AddFlag(Arguments.ArgChromeUA);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tbDataFolder.Text) && tbDataFolder.Enabled){
|
||||
Args.SetValue(Arguments.ArgDataFolder, tbDataFolder.Text);
|
||||
}
|
||||
|
@ -11,7 +11,10 @@
|
||||
|
||||
namespace TweetDuck.Core.Utils{
|
||||
static class BrowserUtils{
|
||||
public static string HeaderUserAgent => Program.BrandName+" "+Application.ProductVersion;
|
||||
public static string CreateUserAgent(bool useChromeUA){
|
||||
return useChromeUA ? "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/"+Cef.ChromiumVersion+" Safari/537.36"
|
||||
: Program.BrandName+" "+Application.ProductVersion;
|
||||
}
|
||||
|
||||
public static void SetupCefArgs(IDictionary<string, string> args){
|
||||
if (!Program.SystemConfig.HardwareAcceleration){
|
||||
@ -167,7 +170,7 @@ public static WebClient CreateWebClient(){
|
||||
WindowsUtils.EnsureTLS12();
|
||||
|
||||
WebClient client = new WebClient{ Proxy = null };
|
||||
client.Headers[HttpRequestHeader.UserAgent] = HeaderUserAgent;
|
||||
client.Headers[HttpRequestHeader.UserAgent] = CreateUserAgent(false);
|
||||
return client;
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ private static void Main(){
|
||||
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
|
||||
|
||||
CefSettings settings = new CefSettings{
|
||||
UserAgent = BrowserUtils.HeaderUserAgent,
|
||||
UserAgent = BrowserUtils.CreateUserAgent(Arguments.HasFlag(Arguments.ArgChromeUA)),
|
||||
BrowserSubprocessPath = BrandName+".Browser.exe",
|
||||
CachePath = StoragePath,
|
||||
UserDataPath = CefDataPath,
|
||||
|
Loading…
Reference in New Issue
Block a user