From e12e2ad65c160b5079dc5a842aaf95e18ab2bbdc Mon Sep 17 00:00:00 2001 From: masta Date: Thu, 15 Oct 2015 14:20:31 +0200 Subject: [PATCH 1/2] Support for Microsoft Edge. --- DanTup.BrowserSelector/Program.cs | 16 +++++++++++++--- .../Properties/AssemblyInfo.cs | 4 ++-- README.md | 6 +++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/DanTup.BrowserSelector/Program.cs b/DanTup.BrowserSelector/Program.cs index 3495b17..b5c3bac 100644 --- a/DanTup.BrowserSelector/Program.cs +++ b/DanTup.BrowserSelector/Program.cs @@ -9,7 +9,10 @@ namespace DanTup.BrowserSelector { class Program { - static void Main(string[] args) + private const string EdgeLocation = "edge"; + private const string EdgeStartCommand = "microsoft-edge:"; + + static void Main(string[] args) { if (args == null || args.Length != 1 || !HandleArg(args[0])) ShowHelpInfo(); @@ -85,8 +88,15 @@ static void LaunchBrowser(string url) if (Regex.IsMatch(domain, pattern)) { - Process.Start(preference.Browser.Location, url); - return; + if (preference.Browser.Location == EdgeLocation) + { + Process.Start(string.Format("{0}{1}", EdgeStartCommand, url)); + } + else + { + Process.Start(preference.Browser.Location, url); + } + return; } } diff --git a/DanTup.BrowserSelector/Properties/AssemblyInfo.cs b/DanTup.BrowserSelector/Properties/AssemblyInfo.cs index 4003cbd..65b3ffb 100644 --- a/DanTup.BrowserSelector/Properties/AssemblyInfo.cs +++ b/DanTup.BrowserSelector/Properties/AssemblyInfo.cs @@ -3,5 +3,5 @@ [assembly: AssemblyTitle("DanTup.BrowserSelector")] [assembly: AssemblyProduct("DanTup.BrowserSelector")] [assembly: AssemblyCopyright("Copyright © Danny Tuppeny 2015")] -[assembly: AssemblyVersion("0.2.0.0")] -[assembly: AssemblyFileVersion("0.2.0.0")] +[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyFileVersion("0.3.0.0")] diff --git a/README.md b/README.md index 767393d..406d610 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ Config is a poor mans INI file: ; Default browser is first in list [browsers] + edge = edge chrome = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe + ff = C:\Program Files (x86)\Mozilla Firefox\firefox.exe ie = iexplore.exe ; Url preferences. @@ -28,10 +30,12 @@ Config is a poor mans INI file: [urls] microsoft.com = ie *.microsoft.com = ie + google.com = chrome + visualstudio.com = edge Notes: -- Browser paths must be exact paths to exes with no arguments (or in `PATH`). Values do not need to be quoted. +- Browser paths must be exact paths to exes with no arguments (or in `PATH`). Values do not need to be quoted. For Microsoft Edge just use "edge". - Only * is treated as a special character in URL patterns, and matches any characters. - Only the domain part (or IP address) of a URL is checked. - There is no implied wildcard at the start or end, so you must include these if you need them, but be aware that "microsoft.*" will not only match "microsoft.com" and "microsoft.co.uk" but also "microsoft.somethingelse.com". From 3afbe6244f0ba55a3a9db7249b59190e0e4fb8cb Mon Sep 17 00:00:00 2001 From: masta Date: Fri, 16 Oct 2015 08:36:15 +0200 Subject: [PATCH 2/2] Changed to use dictionary for special case browsers --- DanTup.BrowserSelector/BrowserSelector.ini | 3 +++ DanTup.BrowserSelector/Program.cs | 15 +++++++-------- README.md | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DanTup.BrowserSelector/BrowserSelector.ini b/DanTup.BrowserSelector/BrowserSelector.ini index 4ce52d4..0f81a25 100644 --- a/DanTup.BrowserSelector/BrowserSelector.ini +++ b/DanTup.BrowserSelector/BrowserSelector.ini @@ -1,6 +1,9 @@ ; Default browser is first in list +; Micrsoft Edge is a UWP app and requires no path [browsers] chrome = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe +ff = C:\Program Files (x86)\Mozilla Firefox\firefox.exe +edge = ie = iexplore.exe ; Url preferences. diff --git a/DanTup.BrowserSelector/Program.cs b/DanTup.BrowserSelector/Program.cs index b5c3bac..5754eb9 100644 --- a/DanTup.BrowserSelector/Program.cs +++ b/DanTup.BrowserSelector/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Security.Principal; @@ -9,8 +10,10 @@ namespace DanTup.BrowserSelector { class Program { - private const string EdgeLocation = "edge"; - private const string EdgeStartCommand = "microsoft-edge:"; + static readonly Dictionary SpecialCommands = new Dictionary + { + {"edge", "microsoft-edge:{0}"} + }; static void Main(string[] args) { @@ -88,14 +91,10 @@ static void LaunchBrowser(string url) if (Regex.IsMatch(domain, pattern)) { - if (preference.Browser.Location == EdgeLocation) - { - Process.Start(string.Format("{0}{1}", EdgeStartCommand, url)); - } + if (SpecialCommands.ContainsKey(preference.Browser.Name)) + Process.Start(string.Format(SpecialCommands[preference.Browser.Name], url)); else - { Process.Start(preference.Browser.Location, url); - } return; } } diff --git a/README.md b/README.md index 406d610..dee4879 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,11 @@ Small utility to launch a different browser depending on the domain of the url b Config is a poor mans INI file: ; Default browser is first in list + ; Micrsoft Edge is a UWP app and requires no path [browsers] - edge = edge chrome = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ff = C:\Program Files (x86)\Mozilla Firefox\firefox.exe + edge = ie = iexplore.exe ; Url preferences. @@ -35,7 +36,7 @@ Config is a poor mans INI file: Notes: -- Browser paths must be exact paths to exes with no arguments (or in `PATH`). Values do not need to be quoted. For Microsoft Edge just use "edge". +- Browser paths must be exact paths to exes with no arguments (or in `PATH`). Values do not need to be quoted. Microsoft Edge is a UWP app which cannot be started like other browsers. The path can thus remain empty. - Only * is treated as a special character in URL patterns, and matches any characters. - Only the domain part (or IP address) of a URL is checked. - There is no implied wildcard at the start or end, so you must include these if you need them, but be aware that "microsoft.*" will not only match "microsoft.com" and "microsoft.co.uk" but also "microsoft.somethingelse.com".