1+ using Microsoft . Win32 ;
12using System ;
23using System . Diagnostics ;
34using System . IO ;
@@ -7,12 +8,37 @@ namespace Flow.Launcher.Plugin.SharedCommands
78{
89 public static class SearchWeb
910 {
11+ private static string GetDefaultBrowserPath ( )
12+ {
13+ string name = string . Empty ;
14+ try
15+ {
16+ using var regDefault = Registry . CurrentUser . OpenSubKey ( "Software\\ Microsoft\\ Windows\\ Shell\\ Associations\\ UrlAssociations\\ http\\ UserChoice" , false ) ;
17+ var stringDefault = regDefault . GetValue ( "ProgId" ) ;
18+
19+ using var regKey = Registry . ClassesRoot . OpenSubKey ( stringDefault + "\\ shell\\ open\\ command" , false ) ;
20+ name = regKey . GetValue ( null ) . ToString ( ) . ToLower ( ) . Replace ( "\" " , "" ) ;
21+
22+ if ( ! name . EndsWith ( "exe" ) )
23+ name = name . Substring ( 0 , name . LastIndexOf ( ".exe" ) + 4 ) ;
24+
25+ }
26+ catch
27+ {
28+ return string . Empty ;
29+ }
30+
31+ return name ;
32+ }
33+
1034 /// <summary>
1135 /// Opens search in a new browser. If no browser path is passed in then Chrome is used.
1236 /// Leave browser path blank to use Chrome.
1337 /// </summary>
1438 public static void NewBrowserWindow ( this string url , string browserPath = "" )
1539 {
40+ browserPath = string . IsNullOrEmpty ( browserPath ) ? GetDefaultBrowserPath ( ) : browserPath ;
41+
1642 var browserExecutableName = browserPath ?
1743 . Split ( new [ ] { Path . DirectorySeparatorChar } , StringSplitOptions . None )
1844 . Last ( ) ;
@@ -44,7 +70,9 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
4470 /// </summary>
4571 public static void NewTabInBrowser ( this string url , string browserPath = "" )
4672 {
47- var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
73+ browserPath = string . IsNullOrEmpty ( browserPath ) ? GetDefaultBrowserPath ( ) : browserPath ;
74+
75+ var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
4876 try
4977 {
5078 if ( ! string . IsNullOrEmpty ( browserPath ) )
0 commit comments