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

Add option for custom browser args w/ new dialog & disallow quotes in URLs

This commit is contained in:
chylex 2020-02-15 20:26:07 +01:00
parent 447697ba45
commit 0ee22a30ad
8 changed files with 312 additions and 45 deletions

View File

@ -30,6 +30,7 @@ sealed class UserConfig : BaseConfig{
private string _customCefArgs = null; private string _customCefArgs = null;
public string BrowserPath { get; set; } = null; public string BrowserPath { get; set; } = null;
public string BrowserPathArgs { get; set; } = null;
public bool IgnoreTrackingUrlWarning { get; set; } = false; public bool IgnoreTrackingUrlWarning { get; set; } = false;
public string SearchEngineUrl { get; set; } = null; public string SearchEngineUrl { get; set; } = null;
private int _zoomLevel = 100; private int _zoomLevel = 100;

View File

@ -0,0 +1,154 @@
namespace TweetDuck.Core.Other.Settings.Dialogs {
partial class DialogSettingsExternalProgram {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.textBoxPath = new System.Windows.Forms.TextBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnApply = new System.Windows.Forms.Button();
this.labelPath = new System.Windows.Forms.Label();
this.labelArgs = new System.Windows.Forms.Label();
this.textBoxArgs = new System.Windows.Forms.TextBox();
this.btnBrowse = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxPath
//
this.textBoxPath.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxPath.Font = new System.Drawing.Font("Segoe UI", 9F);
this.textBoxPath.Location = new System.Drawing.Point(12, 30);
this.textBoxPath.Name = "textBoxPath";
this.textBoxPath.Size = new System.Drawing.Size(336, 23);
this.textBoxPath.TabIndex = 1;
//
// btnCancel
//
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);
this.btnCancel.Location = new System.Drawing.Point(307, 118);
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);
this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnApply
//
this.btnApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnApply.AutoSize = true;
this.btnApply.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnApply.Location = new System.Drawing.Point(370, 118);
this.btnApply.Name = "btnApply";
this.btnApply.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.btnApply.Size = new System.Drawing.Size(52, 25);
this.btnApply.TabIndex = 5;
this.btnApply.Text = "Apply";
this.btnApply.UseVisualStyleBackColor = true;
this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
//
// labelPath
//
this.labelPath.AutoSize = true;
this.labelPath.Font = new System.Drawing.Font("Segoe UI", 9F);
this.labelPath.Location = new System.Drawing.Point(12, 9);
this.labelPath.Margin = new System.Windows.Forms.Padding(3, 0, 3, 3);
this.labelPath.Name = "labelPath";
this.labelPath.Size = new System.Drawing.Size(109, 15);
this.labelPath.TabIndex = 0;
this.labelPath.Text = "Path to Application";
//
// labelArgs
//
this.labelArgs.AutoSize = true;
this.labelArgs.Font = new System.Drawing.Font("Segoe UI", 9F);
this.labelArgs.Location = new System.Drawing.Point(12, 68);
this.labelArgs.Margin = new System.Windows.Forms.Padding(3, 12, 3, 3);
this.labelArgs.Name = "labelArgs";
this.labelArgs.Size = new System.Drawing.Size(124, 15);
this.labelArgs.TabIndex = 3;
this.labelArgs.Text = "Additional Arguments";
//
// textBoxArgs
//
this.textBoxArgs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxArgs.Font = new System.Drawing.Font("Segoe UI", 9F);
this.textBoxArgs.Location = new System.Drawing.Point(12, 89);
this.textBoxArgs.Name = "textBoxArgs";
this.textBoxArgs.Size = new System.Drawing.Size(410, 23);
this.textBoxArgs.TabIndex = 4;
//
// btnBrowse
//
this.btnBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnBrowse.AutoSize = true;
this.btnBrowse.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnBrowse.Location = new System.Drawing.Point(354, 28);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.btnBrowse.Size = new System.Drawing.Size(68, 25);
this.btnBrowse.TabIndex = 2;
this.btnBrowse.Text = "Browse...";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
//
// DialogSettingsExternalProgram
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(434, 155);
this.Controls.Add(this.btnBrowse);
this.Controls.Add(this.textBoxArgs);
this.Controls.Add(this.labelArgs);
this.Controls.Add(this.labelPath);
this.Controls.Add(this.btnApply);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.textBoxPath);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DialogSettingsExternalProgram";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBoxPath;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnApply;
private System.Windows.Forms.Label labelPath;
private System.Windows.Forms.Label labelArgs;
private System.Windows.Forms.TextBox textBoxArgs;
private System.Windows.Forms.Button btnBrowse;
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Windows.Forms;
using TweetLib.Core.Utils;
using IOPath = System.IO.Path;
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsExternalProgram : Form{
public string Path{
get => StringUtils.NullIfEmpty(textBoxPath.Text);
set => textBoxPath.Text = value ?? string.Empty;
}
public string Args{
get => StringUtils.NullIfEmpty(textBoxArgs.Text);
set => textBoxArgs.Text = value ?? string.Empty;
}
private readonly string fileDialogTitle;
public DialogSettingsExternalProgram(string windowTitle, string fileDialogTitle){
InitializeComponent();
Text = Program.BrandName + " Options - " + windowTitle;
AcceptButton = btnApply;
CancelButton = btnCancel;
this.fileDialogTitle = fileDialogTitle;
}
private void btnBrowse_Click(object sender, EventArgs e){
using OpenFileDialog dialog = new OpenFileDialog{
AutoUpgradeEnabled = true,
DereferenceLinks = true,
InitialDirectory = IOPath.GetDirectoryName(Path), // returns null if argument is null
Title = fileDialogTitle,
Filter = "Executables (*.exe;*.bat;*.cmd)|*.exe;*.bat;*.cmd|All Files (*.*)|*.*"
};
if (dialog.ShowDialog() == DialogResult.OK && Path != dialog.FileName){
Path = dialog.FileName;
Args = string.Empty;
}
}
private void btnApply_Click(object sender, EventArgs e){
DialogResult = DialogResult.OK;
Close();
}
private void btnCancel_Click(object sender, EventArgs e){
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -49,11 +49,13 @@ private void InitializeComponent() {
this.checkSmoothScrolling = new System.Windows.Forms.CheckBox(); this.checkSmoothScrolling = new System.Windows.Forms.CheckBox();
this.checkTouchAdjustment = new System.Windows.Forms.CheckBox(); this.checkTouchAdjustment = new System.Windows.Forms.CheckBox();
this.labelBrowserPath = new System.Windows.Forms.Label(); this.labelBrowserPath = new System.Windows.Forms.Label();
this.comboBoxBrowserPath = new System.Windows.Forms.ComboBox(); this.comboBoxCustomBrowser = new System.Windows.Forms.ComboBox();
this.labelSearchEngine = new System.Windows.Forms.Label(); this.labelSearchEngine = new System.Windows.Forms.Label();
this.comboBoxSearchEngine = new System.Windows.Forms.ComboBox(); this.comboBoxSearchEngine = new System.Windows.Forms.ComboBox();
this.flowPanelRight = new System.Windows.Forms.FlowLayoutPanel(); this.flowPanelRight = new System.Windows.Forms.FlowLayoutPanel();
this.checkHardwareAcceleration = new System.Windows.Forms.CheckBox(); this.checkHardwareAcceleration = new System.Windows.Forms.CheckBox();
this.panelCustomBrowser = new System.Windows.Forms.Panel();
this.btnCustomBrowserChange = new System.Windows.Forms.Button();
this.labelLocales = new System.Windows.Forms.Label(); this.labelLocales = new System.Windows.Forms.Label();
this.checkSpellCheck = new System.Windows.Forms.CheckBox(); this.checkSpellCheck = new System.Windows.Forms.CheckBox();
this.labelSpellCheckLanguage = new System.Windows.Forms.Label(); this.labelSpellCheckLanguage = new System.Windows.Forms.Label();
@ -65,6 +67,7 @@ private void InitializeComponent() {
this.panelZoom.SuspendLayout(); this.panelZoom.SuspendLayout();
this.flowPanelLeft.SuspendLayout(); this.flowPanelLeft.SuspendLayout();
this.flowPanelRight.SuspendLayout(); this.flowPanelRight.SuspendLayout();
this.panelCustomBrowser.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// checkExpandLinks // checkExpandLinks
@ -357,16 +360,16 @@ private void InitializeComponent() {
this.labelBrowserPath.TabIndex = 4; this.labelBrowserPath.TabIndex = 4;
this.labelBrowserPath.Text = "Open Links With..."; this.labelBrowserPath.Text = "Open Links With...";
// //
// comboBoxBrowserPath // comboBoxCustomBrowser
// //
this.comboBoxBrowserPath.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxCustomBrowser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxBrowserPath.Font = new System.Drawing.Font("Segoe UI", 9F); this.comboBoxCustomBrowser.Font = new System.Drawing.Font("Segoe UI", 9F);
this.comboBoxBrowserPath.FormattingEnabled = true; this.comboBoxCustomBrowser.FormattingEnabled = true;
this.comboBoxBrowserPath.Location = new System.Drawing.Point(5, 126); this.comboBoxCustomBrowser.Location = new System.Drawing.Point(5, 1);
this.comboBoxBrowserPath.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3); this.comboBoxCustomBrowser.Margin = new System.Windows.Forms.Padding(5, 1, 3, 0);
this.comboBoxBrowserPath.Name = "comboBoxBrowserPath"; this.comboBoxCustomBrowser.Name = "comboBoxCustomBrowser";
this.comboBoxBrowserPath.Size = new System.Drawing.Size(173, 23); this.comboBoxCustomBrowser.Size = new System.Drawing.Size(176, 23);
this.comboBoxBrowserPath.TabIndex = 5; this.comboBoxCustomBrowser.TabIndex = 0;
// //
// labelSearchEngine // labelSearchEngine
// //
@ -387,7 +390,7 @@ private void InitializeComponent() {
this.comboBoxSearchEngine.Location = new System.Drawing.Point(5, 183); this.comboBoxSearchEngine.Location = new System.Drawing.Point(5, 183);
this.comboBoxSearchEngine.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3); this.comboBoxSearchEngine.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3);
this.comboBoxSearchEngine.Name = "comboBoxSearchEngine"; this.comboBoxSearchEngine.Name = "comboBoxSearchEngine";
this.comboBoxSearchEngine.Size = new System.Drawing.Size(173, 23); this.comboBoxSearchEngine.Size = new System.Drawing.Size(176, 23);
this.comboBoxSearchEngine.TabIndex = 7; this.comboBoxSearchEngine.TabIndex = 7;
// //
// flowPanelRight // flowPanelRight
@ -399,7 +402,7 @@ private void InitializeComponent() {
this.flowPanelRight.Controls.Add(this.checkTouchAdjustment); this.flowPanelRight.Controls.Add(this.checkTouchAdjustment);
this.flowPanelRight.Controls.Add(this.checkHardwareAcceleration); this.flowPanelRight.Controls.Add(this.checkHardwareAcceleration);
this.flowPanelRight.Controls.Add(this.labelBrowserPath); this.flowPanelRight.Controls.Add(this.labelBrowserPath);
this.flowPanelRight.Controls.Add(this.comboBoxBrowserPath); this.flowPanelRight.Controls.Add(this.panelCustomBrowser);
this.flowPanelRight.Controls.Add(this.labelSearchEngine); this.flowPanelRight.Controls.Add(this.labelSearchEngine);
this.flowPanelRight.Controls.Add(this.comboBoxSearchEngine); this.flowPanelRight.Controls.Add(this.comboBoxSearchEngine);
this.flowPanelRight.Controls.Add(this.labelLocales); this.flowPanelRight.Controls.Add(this.labelLocales);
@ -427,6 +430,30 @@ private void InitializeComponent() {
this.checkHardwareAcceleration.Text = "Hardware Acceleration"; this.checkHardwareAcceleration.Text = "Hardware Acceleration";
this.checkHardwareAcceleration.UseVisualStyleBackColor = true; this.checkHardwareAcceleration.UseVisualStyleBackColor = true;
// //
// panelCustomBrowser
//
this.panelCustomBrowser.Controls.Add(this.comboBoxCustomBrowser);
this.panelCustomBrowser.Controls.Add(this.btnCustomBrowserChange);
this.panelCustomBrowser.Location = new System.Drawing.Point(0, 125);
this.panelCustomBrowser.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
this.panelCustomBrowser.Name = "panelCustomBrowser";
this.panelCustomBrowser.Size = new System.Drawing.Size(300, 24);
this.panelCustomBrowser.TabIndex = 5;
//
// btnCustomBrowserChange
//
this.btnCustomBrowserChange.AutoSize = true;
this.btnCustomBrowserChange.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnCustomBrowserChange.Location = new System.Drawing.Point(189, 0);
this.btnCustomBrowserChange.Margin = new System.Windows.Forms.Padding(5, 0, 3, 0);
this.btnCustomBrowserChange.Name = "btnCustomBrowserChange";
this.btnCustomBrowserChange.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.btnCustomBrowserChange.Size = new System.Drawing.Size(71, 25);
this.btnCustomBrowserChange.TabIndex = 1;
this.btnCustomBrowserChange.Text = "Change...";
this.btnCustomBrowserChange.UseVisualStyleBackColor = true;
this.btnCustomBrowserChange.Visible = false;
//
// labelLocales // labelLocales
// //
this.labelLocales.AutoSize = true; this.labelLocales.AutoSize = true;
@ -520,6 +547,8 @@ private void InitializeComponent() {
this.flowPanelLeft.PerformLayout(); this.flowPanelLeft.PerformLayout();
this.flowPanelRight.ResumeLayout(false); this.flowPanelRight.ResumeLayout(false);
this.flowPanelRight.PerformLayout(); this.flowPanelRight.PerformLayout();
this.panelCustomBrowser.ResumeLayout(false);
this.panelCustomBrowser.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -543,7 +572,7 @@ private void InitializeComponent() {
private System.Windows.Forms.FlowLayoutPanel flowPanelLeft; private System.Windows.Forms.FlowLayoutPanel flowPanelLeft;
private System.Windows.Forms.CheckBox checkKeepLikeFollowDialogsOpen; private System.Windows.Forms.CheckBox checkKeepLikeFollowDialogsOpen;
private System.Windows.Forms.Label labelBrowserPath; private System.Windows.Forms.Label labelBrowserPath;
private System.Windows.Forms.ComboBox comboBoxBrowserPath; private System.Windows.Forms.ComboBox comboBoxCustomBrowser;
private System.Windows.Forms.Label labelBrowserSettings; private System.Windows.Forms.Label labelBrowserSettings;
private System.Windows.Forms.CheckBox checkSmoothScrolling; private System.Windows.Forms.CheckBox checkSmoothScrolling;
private System.Windows.Forms.Label labelSearchEngine; private System.Windows.Forms.Label labelSearchEngine;
@ -563,5 +592,7 @@ private void InitializeComponent() {
private System.Windows.Forms.ComboBox comboBoxTranslationTarget; private System.Windows.Forms.ComboBox comboBoxTranslationTarget;
private System.Windows.Forms.CheckBox checkHardwareAcceleration; private System.Windows.Forms.CheckBox checkHardwareAcceleration;
private System.Windows.Forms.CheckBox checkFocusDmInput; private System.Windows.Forms.CheckBox checkFocusDmInput;
private System.Windows.Forms.Panel panelCustomBrowser;
private System.Windows.Forms.Button btnCustomBrowserChange;
} }
} }

View File

@ -80,7 +80,7 @@ public TabSettingsGeneral(Action reloadColumns, UpdateHandler updates){
toolTip.SetToolTip(checkSmoothScrolling, "Toggles smooth mouse wheel scrolling."); toolTip.SetToolTip(checkSmoothScrolling, "Toggles smooth mouse wheel scrolling.");
toolTip.SetToolTip(checkTouchAdjustment, "Toggles Chromium touch screen adjustment.\r\nDisabled by default, because it is very imprecise with TweetDeck."); toolTip.SetToolTip(checkTouchAdjustment, "Toggles Chromium touch screen adjustment.\r\nDisabled by default, because it is very imprecise with TweetDeck.");
toolTip.SetToolTip(checkHardwareAcceleration, "Uses graphics card to improve performance.\r\nDisable if you experience visual glitches, or to save a small amount of RAM."); toolTip.SetToolTip(checkHardwareAcceleration, "Uses graphics card to improve performance.\r\nDisable if you experience visual glitches, or to save a small amount of RAM.");
toolTip.SetToolTip(comboBoxBrowserPath, "Sets the default browser for opening links."); toolTip.SetToolTip(comboBoxCustomBrowser, "Sets the default browser for opening links.");
toolTip.SetToolTip(comboBoxSearchEngine, "Sets the default website for opening searches."); toolTip.SetToolTip(comboBoxSearchEngine, "Sets the default website for opening searches.");
checkSmoothScrolling.Checked = Config.EnableSmoothScrolling; checkSmoothScrolling.Checked = Config.EnableSmoothScrolling;
@ -88,11 +88,11 @@ public TabSettingsGeneral(Action reloadColumns, UpdateHandler updates){
checkHardwareAcceleration.Checked = SysConfig.HardwareAcceleration; checkHardwareAcceleration.Checked = SysConfig.HardwareAcceleration;
foreach(WindowsUtils.Browser browserInfo in WindowsUtils.FindInstalledBrowsers()){ foreach(WindowsUtils.Browser browserInfo in WindowsUtils.FindInstalledBrowsers()){
comboBoxBrowserPath.Items.Add(browserInfo); comboBoxCustomBrowser.Items.Add(browserInfo);
} }
browserListIndexDefault = comboBoxBrowserPath.Items.Add("(default browser)"); browserListIndexDefault = comboBoxCustomBrowser.Items.Add("(default browser)");
browserListIndexCustom = comboBoxBrowserPath.Items.Add("(custom program...)"); browserListIndexCustom = comboBoxCustomBrowser.Items.Add("(custom program...)");
UpdateBrowserPathSelection(); UpdateBrowserPathSelection();
comboBoxSearchEngine.Items.Add(new SearchEngine("DuckDuckGo", "https://duckduckgo.com/?q=")); comboBoxSearchEngine.Items.Add(new SearchEngine("DuckDuckGo", "https://duckduckgo.com/?q="));
@ -146,7 +146,8 @@ public override void OnReady(){
checkSmoothScrolling.CheckedChanged += checkSmoothScrolling_CheckedChanged; checkSmoothScrolling.CheckedChanged += checkSmoothScrolling_CheckedChanged;
checkTouchAdjustment.CheckedChanged += checkTouchAdjustment_CheckedChanged; checkTouchAdjustment.CheckedChanged += checkTouchAdjustment_CheckedChanged;
checkHardwareAcceleration.CheckedChanged += checkHardwareAcceleration_CheckedChanged; checkHardwareAcceleration.CheckedChanged += checkHardwareAcceleration_CheckedChanged;
comboBoxBrowserPath.SelectedIndexChanged += comboBoxBrowserPath_SelectedIndexChanged; comboBoxCustomBrowser.SelectedIndexChanged += comboBoxCustomBrowser_SelectedIndexChanged;
btnCustomBrowserChange.Click += btnCustomBrowserChange_Click;
comboBoxSearchEngine.SelectedIndexChanged += comboBoxSearchEngine_SelectedIndexChanged; comboBoxSearchEngine.SelectedIndexChanged += comboBoxSearchEngine_SelectedIndexChanged;
checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged; checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged;
@ -253,43 +254,53 @@ private void checkHardwareAcceleration_CheckedChanged(object sender, EventArgs e
SysConfig.HardwareAcceleration = checkHardwareAcceleration.Checked; SysConfig.HardwareAcceleration = checkHardwareAcceleration.Checked;
} }
private void UpdateBrowserChangeButton(){
btnCustomBrowserChange.Visible = comboBoxCustomBrowser.SelectedIndex == browserListIndexCustom;
}
private void UpdateBrowserPathSelection(){ private void UpdateBrowserPathSelection(){
if (string.IsNullOrEmpty(Config.BrowserPath) || !File.Exists(Config.BrowserPath)){ if (string.IsNullOrEmpty(Config.BrowserPath) || !File.Exists(Config.BrowserPath)){
comboBoxBrowserPath.SelectedIndex = browserListIndexDefault; comboBoxCustomBrowser.SelectedIndex = browserListIndexDefault;
} }
else{ else{
WindowsUtils.Browser browserInfo = comboBoxBrowserPath.Items.OfType<WindowsUtils.Browser>().FirstOrDefault(browser => browser.Path == Config.BrowserPath); WindowsUtils.Browser browserInfo = comboBoxCustomBrowser.Items.OfType<WindowsUtils.Browser>().FirstOrDefault(browser => browser.Path == Config.BrowserPath);
if (browserInfo == null){ if (browserInfo == null || Config.BrowserPathArgs != null){
comboBoxBrowserPath.SelectedIndex = browserListIndexCustom; comboBoxCustomBrowser.SelectedIndex = browserListIndexCustom;
} }
else{ else{
comboBoxBrowserPath.SelectedItem = browserInfo; comboBoxCustomBrowser.SelectedItem = browserInfo;
} }
} }
UpdateBrowserChangeButton();
}
private void comboBoxCustomBrowser_SelectedIndexChanged(object sender, EventArgs e){
if (comboBoxCustomBrowser.SelectedIndex == browserListIndexCustom){
btnCustomBrowserChange_Click(sender, e);
}
else{
Config.BrowserPath = (comboBoxCustomBrowser.SelectedItem as WindowsUtils.Browser)?.Path; // default browser item is a string and casts to null
Config.BrowserPathArgs = null;
UpdateBrowserChangeButton();
}
} }
private void comboBoxBrowserPath_SelectedIndexChanged(object sender, EventArgs e){ private void btnCustomBrowserChange_Click(object sender, EventArgs e){
if (comboBoxBrowserPath.SelectedIndex == browserListIndexCustom){ using(DialogSettingsExternalProgram dialog = new DialogSettingsExternalProgram("External Browser", "Open Links With..."){
using(OpenFileDialog dialog = new OpenFileDialog{ Path = Config.BrowserPath,
AutoUpgradeEnabled = true, Args = Config.BrowserPathArgs
DereferenceLinks = true, }){
InitialDirectory = Path.GetDirectoryName(Config.BrowserPath), // returns null if argument is null if (dialog.ShowDialog() == DialogResult.OK){
Title = "Open Links With...", Config.BrowserPath = dialog.Path;
Filter = "Executables (*.exe;*.bat;*.cmd)|*.exe;*.bat;*.cmd|All Files (*.*)|*.*" Config.BrowserPathArgs = dialog.Args;
}){
if (dialog.ShowDialog() == DialogResult.OK){
Config.BrowserPath = dialog.FileName;
}
} }
}
comboBoxBrowserPath.SelectedIndexChanged -= comboBoxBrowserPath_SelectedIndexChanged; comboBoxCustomBrowser.SelectedIndexChanged -= comboBoxCustomBrowser_SelectedIndexChanged;
UpdateBrowserPathSelection(); UpdateBrowserPathSelection();
comboBoxBrowserPath.SelectedIndexChanged += comboBoxBrowserPath_SelectedIndexChanged; comboBoxCustomBrowser.SelectedIndexChanged += comboBoxCustomBrowser_SelectedIndexChanged;
}
else{
Config.BrowserPath = (comboBoxBrowserPath.SelectedItem as WindowsUtils.Browser)?.Path; // default browser item is a string and casts to null
}
} }
private void comboBoxSearchEngine_SelectedIndexChanged(object sender, EventArgs e){ private void comboBoxSearchEngine_SelectedIndexChanged(object sender, EventArgs e){

View File

@ -85,7 +85,9 @@ public static void OpenDevToolsCustom(this IWebBrowser browser){
} }
public static void OpenExternalBrowser(string url){ public static void OpenExternalBrowser(string url){
if (string.IsNullOrWhiteSpace(url))return; if (string.IsNullOrWhiteSpace(url)){
return;
}
switch(TwitterUrls.Check(url)){ switch(TwitterUrls.Check(url)){
case TwitterUrls.UrlType.Fine: case TwitterUrls.UrlType.Fine:
@ -99,8 +101,11 @@ public static void OpenExternalBrowser(string url){
WindowsUtils.OpenAssociatedProgram(url); WindowsUtils.OpenAssociatedProgram(url);
} }
else{ else{
string quotedUrl = '"' + url + '"';
string browserArgs = Config.BrowserPathArgs == null ? quotedUrl : Config.BrowserPathArgs + ' ' + quotedUrl;
try{ try{
using(Process.Start(browserPath, url)){} using(Process.Start(browserPath, browserArgs)){}
}catch(Exception e){ }catch(Exception e){
Program.Reporter.HandleException("Error Opening Browser", "Could not open the browser.", true, e); Program.Reporter.HandleException("Error Opening Browser", "Could not open the browser.", true, e);
} }
@ -134,7 +139,7 @@ public static void OpenExternalBrowser(string url){
break; break;
case TwitterUrls.UrlType.Invalid: case TwitterUrls.UrlType.Invalid:
FormMessage.Warning("Blocked URL", "A potentially malicious URL was blocked from opening:\n" + url, FormMessage.OK); FormMessage.Warning("Blocked URL", "A potentially malicious or invalid URL was blocked from opening:\n" + url, FormMessage.OK);
break; break;
} }
} }

View File

@ -156,6 +156,12 @@
<Compile Include="Core\Other\Settings\Dialogs\DialogSettingsAnalytics.Designer.cs"> <Compile Include="Core\Other\Settings\Dialogs\DialogSettingsAnalytics.Designer.cs">
<DependentUpon>DialogSettingsAnalytics.cs</DependentUpon> <DependentUpon>DialogSettingsAnalytics.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Core\Other\Settings\Dialogs\DialogSettingsExternalProgram.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Core\Other\Settings\Dialogs\DialogSettingsExternalProgram.Designer.cs">
<DependentUpon>DialogSettingsExternalProgram.cs</DependentUpon>
</Compile>
<Compile Include="Core\Other\Settings\Dialogs\DialogSettingsSearchEngine.cs"> <Compile Include="Core\Other\Settings\Dialogs\DialogSettingsSearchEngine.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -39,6 +39,10 @@ public enum UrlType{
} }
public static UrlType Check(string url){ public static UrlType Check(string url){
if (url.Contains("\"")){
return UrlType.Invalid;
}
if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri)){ if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri)){
string scheme = uri.Scheme; string scheme = uri.Scheme;