Skip to content

Commit

Permalink
added support for Edge browser and bugfix for url with unescaped space
Browse files Browse the repository at this point in the history
  • Loading branch information
zumoshi committed Oct 26, 2015
1 parent 6c8ecaa commit 5a27275
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
29 changes: 28 additions & 1 deletion BrowserSelect/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,40 @@ public class Browser {
static class BrowserFinder {
public static List<Browser> find() {
List<Browser> browsers = new List<Browser>();
//special case , firefox+firefox developer both installed
//(only works if firefox installed in default directory)
var ff_path = Path.Combine(
Program.ProgramFilesx86() ,
@"Mozilla Firefox\firefox.exe");
if (File.Exists(ff_path))
browsers.Add(new Browser()
{
name = "FireFox",
exec = ff_path,
icon = IconExtractor.fromFile(ff_path)
});
//special case , Edge
var edge_path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Windows) ,
@"SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
if (File.Exists(edge_path))
browsers.Add(new Browser()
{
name="Edge",
//exec=edge_path,
// http://answers.microsoft.com/en-us/insider/forum/insider_internet-insider_spartan/how-to-start-microsoft-edge-from-command-line/25d0ba93-4e8b-41cb-adde-461d8fb58ec1
exec = "edge",
icon =IconExtractor.fromFile(edge_path)
});

//gather browsers from registry
using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
browsers.AddRange(find(hklm));
using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32))
browsers.AddRange(find(hkcu));

//remove myself
browsers=browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
browsers =browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
Path.GetFileName(Application.ExecutablePath).ToLower()).ToList();
//remove duplicates
browsers = browsers.GroupBy(browser => browser.exec)
Expand Down
10 changes: 9 additions & 1 deletion BrowserSelect/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -67,7 +68,14 @@ private void browser_click(object sender, EventArgs e) {
}

private void open_url(Browser b) {
System.Diagnostics.Process.Start(b.exec, Program.url);
if (b.exec == "edge"){
//edge is a universal app , which means we can't just run it like other browsers
Process.Start("microsoft-edge:"+Program.url
.Replace(" ","%20")
.Replace("\"", "%22"));
}
else
Process.Start(b.exec, "\""+Program.url.Replace("\"","%22")+"\"");
Application.Exit();
}

Expand Down
12 changes: 12 additions & 0 deletions BrowserSelect/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,17 @@ static void Main(string[] args) {
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

// http://stackoverflow.com/a/194223/1461004
public static string ProgramFilesx86()
{
if (8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
}

return Environment.GetEnvironmentVariable("ProgramFiles");
}
}
}
4 changes: 2 additions & 2 deletions BrowserSelect/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
Binary file added screenshots/photo_2015-10-27_16-46-14.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a27275

Please sign in to comment.