1
+ using Microsoft . Win32 ;
1
2
using System ;
2
3
using System . Diagnostics ;
3
4
using System . IO ;
@@ -7,12 +8,37 @@ namespace Flow.Launcher.Plugin.SharedCommands
7
8
{
8
9
public static class SearchWeb
9
10
{
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
+
10
34
/// <summary>
11
35
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
12
36
/// Leave browser path blank to use Chrome.
13
37
/// </summary>
14
38
public static void NewBrowserWindow ( this string url , string browserPath = "" )
15
39
{
40
+ browserPath = string . IsNullOrEmpty ( browserPath ) ? GetDefaultBrowserPath ( ) : browserPath ;
41
+
16
42
var browserExecutableName = browserPath ?
17
43
. Split ( new [ ] { Path . DirectorySeparatorChar } , StringSplitOptions . None )
18
44
. Last ( ) ;
@@ -44,7 +70,9 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
44
70
/// </summary>
45
71
public static void NewTabInBrowser ( this string url , string browserPath = "" )
46
72
{
47
- var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
73
+ browserPath = string . IsNullOrEmpty ( browserPath ) ? GetDefaultBrowserPath ( ) : browserPath ;
74
+
75
+ var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
48
76
try
49
77
{
50
78
if ( ! string . IsNullOrEmpty ( browserPath ) )
0 commit comments