Skip to content

Commit 8e9764f

Browse files
committed
linux and windows support
1 parent 1a2aafe commit 8e9764f

File tree

10 files changed

+833
-270
lines changed

10 files changed

+833
-270
lines changed

core/build.gradle.kts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ kotlin {
3939
// Native targets
4040
macosX64()
4141
macosArm64()
42-
//linuxX64()
43-
//linuxArm64()
44-
//mingwX64()
42+
linuxX64()
43+
linuxArm64()
44+
mingwX64()
4545

4646
// jvm & js
4747
jvmToolchain(21)
@@ -92,6 +92,16 @@ kotlin {
9292
api(libs.ktor.client.darwin)
9393
}
9494
}
95+
val linuxMain by getting {
96+
dependencies {
97+
api(libs.ktor.client.curl)
98+
}
99+
}
100+
val mingwMain by getting {
101+
dependencies {
102+
api(libs.ktor.client.winhttp)
103+
}
104+
}
95105
val jvmTest by getting {
96106
dependencies {
97107
implementation(kotlin("test"))
@@ -103,6 +113,16 @@ kotlin {
103113
implementation(kotlin("test"))
104114
}
105115
}
116+
val linuxTest by getting {
117+
dependencies {
118+
implementation(kotlin("test"))
119+
}
120+
}
121+
val mingwTest by getting {
122+
dependencies {
123+
implementation(kotlin("test"))
124+
}
125+
}
106126
}
107127
}
108128

core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,79 @@ fun isGzipCompressed(data: ByteArray): Boolean {
6262
return header == listOf(0x1F, 0x8B)
6363
}
6464

65+
/**
66+
* Browser search configuration flags
67+
*/
68+
data class BrowserSearchConfig(
69+
val searchInPath: Boolean = true,
70+
val searchMacosApplications: Boolean = false,
71+
val searchWindowsProgramFiles: Boolean = false,
72+
val searchLinuxCommonPaths: Boolean = false,
73+
)
74+
75+
/**
76+
* Common helper to search for browser executables based on platform configuration.
77+
* @param config Platform-specific search configuration
78+
* @param pathSeparator The path separator character (":" for POSIX, ";" for Windows)
79+
* @param pathEnv The PATH environment variable value
80+
* @param executableNames List of executable names to search for (e.g., ["chrome", "google-chrome"])
81+
* @param macosAppPaths macOS .app bundle paths (only used if searchMacosApplications is true)
82+
* @param windowsProgramFilesSuffixes Windows Program Files subdirectories (only used if searchWindowsProgramFiles is true)
83+
* @param linuxCommonPaths Common Linux installation paths (only used if searchLinuxCommonPaths is true)
84+
* @param windowsExecutableNames Windows executable names with .exe extension
85+
* @param windowsProgramFilesGetter Callback to get Windows program files directories
86+
*/
87+
internal fun findBrowserExecutableCommon(
88+
config: BrowserSearchConfig,
89+
pathSeparator: String,
90+
pathEnv: String?,
91+
executableNames: List<String>,
92+
macosAppPaths: List<String> = emptyList(),
93+
windowsProgramFilesSuffixes: List<String> = emptyList(),
94+
windowsExecutableNames: List<String> = emptyList(),
95+
linuxCommonPaths: List<String> = emptyList(),
96+
windowsProgramFilesGetter: () -> List<String> = { emptyList() },
97+
): Path? {
98+
val candidates = mutableListOf<Path>()
99+
100+
// macOS applications
101+
if (config.searchMacosApplications) {
102+
candidates.addAll(macosAppPaths.map { Path(it) })
103+
}
104+
105+
// Windows Program Files
106+
if (config.searchWindowsProgramFiles) {
107+
val programFiles = windowsProgramFilesGetter()
108+
for (base in programFiles) {
109+
for (suffix in windowsProgramFilesSuffixes) {
110+
for (exe in windowsExecutableNames) {
111+
candidates.add(Path("$base/$suffix/$exe"))
112+
}
113+
}
114+
}
115+
}
116+
117+
// Linux common paths
118+
if (config.searchLinuxCommonPaths) {
119+
candidates.addAll(linuxCommonPaths.map { Path(it) })
120+
}
121+
122+
// Search in PATH
123+
if (config.searchInPath) {
124+
val paths = pathEnv?.split(pathSeparator) ?: emptyList()
125+
for (pathDir in paths) {
126+
for (exe in executableNames) {
127+
candidates.add(Path("$pathDir/$exe"))
128+
}
129+
}
130+
}
131+
132+
// Return the shortest path that exists
133+
return candidates
134+
.filter { exists(it) }
135+
.minByOrNull { it.toString().length }
136+
}
137+
65138
expect abstract class Process {
66139
fun isAlive(): Boolean
67140
fun pid(): Long
@@ -74,6 +147,7 @@ expect fun isPosix(): Boolean
74147
expect fun isRoot(): Boolean
75148
expect fun tempProfileDir(): Path
76149
expect fun exists(path: Path): Boolean
150+
expect fun getEnv(name: String): String?
77151
expect fun findChromeExecutable(): Path?
78152
expect fun findOperaExecutable(): Path?
79153
expect fun findBraveExecutable(): Path?

core/src/jsMain/kotlin/dev/kdriver/core/utils/Utils.js.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ actual fun exists(path: Path): Boolean {
4242
throw UnsupportedOperationException()
4343
}
4444

45+
actual fun getEnv(name: String): String? {
46+
throw UnsupportedOperationException()
47+
}
48+
4549
actual fun findChromeExecutable(): Path? {
4650
throw UnsupportedOperationException()
4751
}

0 commit comments

Comments
 (0)