Skip to content

updated browser filters rules to be more flexible #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions BrowserSelect/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ private static List<Browser> find(RegistryKey hklm)
icon = icon2String(IconExtractor.fromFile(exec))
});
}
catch (NullReferenceException)
catch (NullReferenceException ex)
{
System.Diagnostics.Debug.WriteLine(ex);
} // incomplete registry record for browser, ignore it
catch (Exception ex)
{
// todo: log errors
System.Diagnostics.Debug.WriteLine(ex);
}
}
return browsers;
Expand Down
31 changes: 28 additions & 3 deletions BrowserSelect/BrowserSelect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrowserSelect</RootNamespace>
<AssemblyName>BrowserSelect</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -30,16 +32,21 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>bs.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -70,6 +77,18 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="frm_settings_urlexpander.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frm_settings_urlexpander.Designer.cs">
<DependentUpon>frm_settings_urlexpander.cs</DependentUpon>
</Compile>
<Compile Include="frm_SplashScreen.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frm_SplashScreen.Designer.cs">
<DependentUpon>frm_SplashScreen.cs</DependentUpon>
</Compile>
<Compile Include="frm_About.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -110,6 +129,12 @@
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frm_settings_urlexpander.resx">
<DependentUpon>frm_settings_urlexpander.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frm_SplashScreen.resx">
<DependentUpon>frm_SplashScreen.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frm_About.resx">
<DependentUpon>frm_About.cs</DependentUpon>
</EmbeddedResource>
Expand Down
53 changes: 42 additions & 11 deletions BrowserSelect/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using BrowserSelect.Properties;
using Newtonsoft.Json;
using SHDocVw;

namespace BrowserSelect
Expand All @@ -19,6 +21,7 @@ public partial class Form1 : Form
public Form1()
{
InitializeComponent();
MaximizeBox = false;
}

public void updateBrowsers()
Expand Down Expand Up @@ -50,15 +53,18 @@ public void updateBrowsers()
}

private void Form1_Load(object sender, EventArgs e)
{
{
this.AutoSize = true;
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.KeyPreview = true;
this.Text = Program.url;
// set the form icon from .exe file icon
this.Icon = IconExtractor.fromFile(Application.ExecutablePath);
// create a wildcard rule for this domain (always button)
_alwaysRule = generate_rule(Program.url);
if (Program.url != "")
{
_alwaysRule = generate_rule(Program.url);
this.Text = Program.url;
}
// check for new version
if (Settings.Default.last_version != "nope")
{
Expand Down Expand Up @@ -118,12 +124,22 @@ public void add_rule(Browser b, string pattern)

private void save_rule(string pattern, Browser b)
{
// save a rule and save app settings
Settings.Default.AutoBrowser.Add((new AutoMatchRule()
// add a rule and save app settings
DataTable rules;
if (Settings.Default.Rules != null && Settings.Default.Rules != "")
rules = (DataTable)JsonConvert.DeserializeObject(Settings.Default.Rules, (typeof(DataTable)));
else
{
Pattern = pattern,
Browser = b.name
}).ToString());
rules = new DataTable();
rules.Columns.Add("Type");
rules.Columns.Add("Match");
rules.Columns.Add("Pattern");
rules.Columns.Add("Browser");
}
if (pattern.StartsWith("*."))
pattern = pattern.Substring(2);
rules.Rows.Add("Ends With", "Domain", pattern, b.name);
Settings.Default.Rules = JsonConvert.SerializeObject(rules);
Settings.Default.Save();
}

Expand Down Expand Up @@ -161,7 +177,9 @@ e.g. sealake.vic.au or something.fun.ir
x = parts[count - 2]; //second-level
y = parts[count - 3]; //third-level
}
catch (IndexOutOfRangeException) { } // in case domain did not have 3 parts.. (e.g. localhost, google.com)
catch (IndexOutOfRangeException ex) {
Debug.WriteLine(ex);
} // in case domain did not have 3 parts.. (e.g. localhost, google.com)

// creating the patterns
var rule_tld = String.Format("*.{0}.{1}", x, tld);
Expand Down Expand Up @@ -253,7 +271,12 @@ public static void open_url(Browser b, bool incognito = false)
}
else
{
Process.Start(b.exec, Program.Args2Str(args));
ProcessStartInfo startInfo = new ProcessStartInfo(b.exec);
// Clicking MS Edge takes more than 4 seconds to load, even with an existing window
// Disabling UseShellExecute to create the process directly from the browser executable file
startInfo.UseShellExecute = false;
startInfo.Arguments = Program.Args2Str(args);
Process.Start(startInfo);
}
Application.Exit();
}
Expand Down Expand Up @@ -284,7 +307,15 @@ private void center_me()
var top = wa.Height / 2 + wa.Top - Height / 2;

this.Location = new Point(left, top);
this.Activate();


// Borrowed from https://stackoverflow.com/a/5853542
// Get the window to the front
this.TopMost = true;
this.TopMost = false;

// "Steal" the focus
this.Activate();
}

private void btn_help_Click(object sender, EventArgs e)
Expand Down
Loading