@@ -15,12 +15,9 @@ public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };
15
15
16
16
public class BrowserStackTunnel : IDisposable
17
17
{
18
- // Need to get rid of this variable, instead use getBinaryName()
19
- static readonly string binaryName = isDarwin ( ) ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe" ;
20
- static readonly string downloadURL = isDarwin ( ) ?
21
- "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" :
22
- "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal.exe" ;
23
- static readonly string homepath = isDarwin ( ) ?
18
+ static string binaryName = GetBinaryName ( ) ;
19
+ static readonly string downloadURL = "https://www.browserstack.com/local-testing/downloads/binaries/" + binaryName ;
20
+ static readonly string homepath = IsDarwin ( ) || IsLinux ( ) ?
24
21
Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) :
25
22
Environment . ExpandEnvironmentVariables ( "%HOMEDRIVE%%HOMEPATH%" ) ;
26
23
public static readonly string [ ] basePaths = new string [ ] {
@@ -39,79 +36,80 @@ public class BrowserStackTunnel : IDisposable
39
36
40
37
Process process = null ;
41
38
42
- static Boolean isDarwin ( )
39
+ static bool IsDarwin ( )
43
40
{
44
41
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
45
42
{
46
43
return true ;
47
44
}
45
+ return false ;
48
46
}
47
+
49
48
50
- static Boolean isWindows ( )
49
+ static bool IsWindows ( )
51
50
{
52
51
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
53
52
{
54
53
return true ;
55
54
}
55
+ return false ;
56
56
}
57
57
58
- static Boolean isLinux ( )
58
+ static bool IsLinux ( )
59
59
{
60
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
60
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
61
61
{
62
62
return true ;
63
63
}
64
+ return false ;
64
65
}
65
66
66
- static Boolean isAlpine ( )
67
+ static bool IsAlpine ( )
67
68
{
68
- const string osReleaseFile = "/etc/os-release" ;
69
-
70
- if ( File . Exists ( osReleaseFile ) )
69
+ try
71
70
{
72
- string [ ] lines = File . ReadAllLines ( osReleaseFile ) ;
73
- foreach ( string line in lines )
71
+ string [ ] output = Util . RunShellCommand ( "grep -w 'NAME' /etc/os-release" ) ;
72
+ if ( string . IsNullOrEmpty ( output [ 0 ] ) && output [ 0 ] . Contains ( "Alpine" ) )
74
73
{
75
- if ( line . StartsWith ( "ID=" ) )
76
- {
77
- string id = line . Substring ( 3 ) . Trim ( '"' ) ; // Remove 'ID=' and quotes
78
- if ( id . Equals ( "alpine" , StringComparison . OrdinalIgnoreCase ) )
79
- {
80
- return true ;
81
- }
82
- }
74
+ return true ;
83
75
}
84
76
}
77
+ catch ( System . Exception )
78
+ {
79
+ return false ;
80
+ }
81
+ return false ;
85
82
}
86
- static staring getBinaryName ( )
83
+
84
+ static string GetBinaryName ( )
87
85
{
88
- if isDarwin ( )
86
+ if ( IsDarwin ( ) )
89
87
{
90
- binaryName = "BrowserStackLocal-darwin-x64"
88
+ return "BrowserStackLocal-darwin-x64" ;
91
89
}
92
- else if isWindows ( )
90
+ else if ( IsWindows ( ) )
93
91
{
94
- binaryName = "BrowserStackLocal.exe"
92
+ return "BrowserStackLocal.exe" ;
95
93
}
96
- else if isLinux ( )
94
+ else if ( IsLinux ( ) )
97
95
{
98
- if ( RuntimeInformation . OSArchitecture == Architecture . X64
99
- || RuntimeInformation . OSArchitecture == Architecture . Arm64 )
96
+ if ( Environment . Is64BitOperatingSystem )
100
97
{
101
- if isAlpine ( )
98
+ if ( IsAlpine ( ) )
102
99
{
103
- binaryName = "BrowserStackLocal-alpine"
100
+ return "BrowserStackLocal-alpine" ;
104
101
}
105
102
else
106
103
{
107
- binaryName = "BrowserStackLocal-linux-x64"
104
+ return "BrowserStackLocal-linux-x64" ;
108
105
}
109
106
}
110
107
else
111
108
{
112
- binaryName = "BrowserStackLocal- linux - ia32"
109
+ return "BrowserStackLocal-linux-ia32" ;
113
110
}
114
111
}
112
+ return "BrowserStackLocal.exe" ;
115
113
}
116
114
117
115
public virtual void addBinaryPath ( string binaryAbsolute )
@@ -150,7 +148,7 @@ public virtual void fallbackPaths()
150
148
151
149
public void modifyBinaryPermission ( )
152
150
{
153
- if ( isDarwin ( ) )
151
+ if ( IsDarwin ( ) || IsLinux ( ) )
154
152
{
155
153
try
156
154
{
0 commit comments