Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
// Native targets
macosX64()
macosArm64()
//linuxX64()
//linuxArm64()
//mingwX64()
linuxX64()
linuxArm64()
mingwX64()

// jvm & js
jvmToolchain(21)
Expand Down Expand Up @@ -92,6 +92,16 @@
api(libs.ktor.client.darwin)
}
}
val linuxMain by getting {

Check warning on line 95 in core/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

core/build.gradle.kts#L95

Private property `linuxMain` is unused. (detekt.UnusedPrivateProperty)
dependencies {
api(libs.ktor.client.curl)
}
}
val mingwMain by getting {

Check warning on line 100 in core/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

core/build.gradle.kts#L100

Private property `mingwMain` is unused. (detekt.UnusedPrivateProperty)
dependencies {
api(libs.ktor.client.winhttp)
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
Expand All @@ -103,6 +113,16 @@
implementation(kotlin("test"))
}
}
val linuxTest by getting {

Check warning on line 116 in core/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

core/build.gradle.kts#L116

Private property `linuxTest` is unused. (detekt.UnusedPrivateProperty)
dependencies {
implementation(kotlin("test"))
}
}
val mingwTest by getting {

Check warning on line 121 in core/build.gradle.kts

View check run for this annotation

codefactor.io / CodeFactor

core/build.gradle.kts#L121

Private property `mingwTest` is unused. (detekt.UnusedPrivateProperty)
dependencies {
implementation(kotlin("test"))
}
}
}
}

Expand Down
74 changes: 74 additions & 0 deletions core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,79 @@
return header == listOf(0x1F, 0x8B)
}

/**
* Browser search configuration flags
*/
data class BrowserSearchConfig(
val searchInPath: Boolean = true,

Check warning on line 69 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The property searchInPath is missing documentation. (detekt.UndocumentedPublicProperty)
val searchMacosApplications: Boolean = false,

Check warning on line 70 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The property searchMacosApplications is missing documentation. (detekt.UndocumentedPublicProperty)
val searchWindowsProgramFiles: Boolean = false,

Check warning on line 71 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The property searchWindowsProgramFiles is missing documentation. (detekt.UndocumentedPublicProperty)
val searchLinuxCommonPaths: Boolean = false,

Check warning on line 72 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The property searchLinuxCommonPaths is missing documentation. (detekt.UndocumentedPublicProperty)
)

/**
* Common helper to search for browser executables based on platform configuration.
* @param config Platform-specific search configuration
* @param pathSeparator The path separator character (":" for POSIX, ";" for Windows)
* @param pathEnv The PATH environment variable value
* @param executableNames List of executable names to search for (e.g., ["chrome", "google-chrome"])
* @param macosAppPaths macOS .app bundle paths (only used if searchMacosApplications is true)
* @param windowsProgramFilesSuffixes Windows Program Files subdirectories (only used if searchWindowsProgramFiles is true)

Check warning on line 82 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

Line detected, which is longer than the defined maximum line length in the code style. (detekt.MaxLineLength)
* @param linuxCommonPaths Common Linux installation paths (only used if searchLinuxCommonPaths is true)
* @param windowsExecutableNames Windows executable names with .exe extension
* @param windowsProgramFilesGetter Callback to get Windows program files directories
*/
internal fun findBrowserExecutableCommon(

Check warning on line 87 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

Function findBrowserExecutableCommon is nested too deeply. (detekt.NestedBlockDepth)

Check warning on line 87 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The function findBrowserExecutableCommon(config: BrowserSearchConfig, pathSeparator: String, pathEnv: String?, executableNames: List<String>, macosAppPaths: List<String>, windowsProgramFilesSuffixes: List<String>, windowsExecutableNames: List<String>, linuxCommonPaths: List<String>, windowsProgramFilesGetter: () -> List<String>) has too many parameters. The current threshold is set to 6. (detekt.LongParameterList)

Check warning on line 87 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

Documentation of findBrowserExecutableCommon is outdated. (detekt.OutdatedDocumentation)
config: BrowserSearchConfig,
pathSeparator: String,
pathEnv: String?,
executableNames: List<String>,
macosAppPaths: List<String> = emptyList(),
windowsProgramFilesSuffixes: List<String> = emptyList(),
windowsExecutableNames: List<String> = emptyList(),
linuxCommonPaths: List<String> = emptyList(),
windowsProgramFilesGetter: () -> List<String> = { emptyList() },
): Path? {
val candidates = mutableListOf<Path>()

// macOS applications
if (config.searchMacosApplications) {
candidates.addAll(macosAppPaths.map { Path(it) })
}

// Windows Program Files
if (config.searchWindowsProgramFiles) {
val programFiles = windowsProgramFilesGetter()
for (base in programFiles) {
for (suffix in windowsProgramFilesSuffixes) {
for (exe in windowsExecutableNames) {
candidates.add(Path("$base/$suffix/$exe"))
}
}
}
}

// Linux common paths
if (config.searchLinuxCommonPaths) {
candidates.addAll(linuxCommonPaths.map { Path(it) })
}

// Search in PATH
if (config.searchInPath) {
val paths = pathEnv?.split(pathSeparator) ?: emptyList()
for (pathDir in paths) {
for (exe in executableNames) {
candidates.add(Path("$pathDir/$exe"))
}
}
}

// Return the shortest path that exists
return candidates
.filter { exists(it) }
.minByOrNull { it.toString().length }
}

expect abstract class Process {
fun isAlive(): Boolean
fun pid(): Long
Expand All @@ -74,6 +147,7 @@
expect fun isRoot(): Boolean
expect fun tempProfileDir(): Path
expect fun exists(path: Path): Boolean
expect fun getEnv(name: String): String?

Check warning on line 150 in core/src/commonMain/kotlin/dev/kdriver/core/utils/Utils.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The function getEnv is missing documentation. (detekt.UndocumentedPublicFunction)
expect fun findChromeExecutable(): Path?
expect fun findOperaExecutable(): Path?
expect fun findBraveExecutable(): Path?
Expand Down
4 changes: 4 additions & 0 deletions core/src/jsMain/kotlin/dev/kdriver/core/utils/Utils.js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
throw UnsupportedOperationException()
}

actual fun getEnv(name: String): String? {

Check warning on line 45 in core/src/jsMain/kotlin/dev/kdriver/core/utils/Utils.js.kt

View check run for this annotation

codefactor.io / CodeFactor

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

The function getEnv is missing documentation. (detekt.UndocumentedPublicFunction)
throw UnsupportedOperationException()
}

actual fun findChromeExecutable(): Path? {
throw UnsupportedOperationException()
}
Expand Down
Loading