Skip to content

Commit

Permalink
👷 Build script automatically downloads configured webdriver and headl…
Browse files Browse the repository at this point in the history
…ess browser
  • Loading branch information
guiyanakuang committed Feb 26, 2024
1 parent df92441 commit 0cce384
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ logs
composeApp/docs
/composeApp/DawnCache/
/composeApp/GPUCache/
chrome-headless-shell-*/
chromedriver-*/
55 changes: 54 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import java.io.FileReader
import java.util.Properties

repositories {
mavenCentral()
Expand All @@ -12,6 +14,7 @@ plugins {
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.realmKotlin)
alias(libs.plugins.download)
}

kotlin {
Expand Down Expand Up @@ -94,11 +97,27 @@ compose.desktop {

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
modules("jdk.charsets")

appResourcesRootDir = project.layout.projectDirectory.dir("resources")
packageName = "Clipevery"
packageVersion = "1.0.0"

modules("jdk.charsets")

val properties = Properties()
val webDriverFile = project.projectDir.toPath().resolve("webDriver.properties").toFile()
properties.load(FileReader(webDriverFile))

macOS {

val process = Runtime.getRuntime().exec("uname -m")
val result = process.inputStream.bufferedReader().use { it.readText() }.trim()

when (result) {
"x86_64" -> getChromeDriver("mac-x64", properties, appResourcesRootDir.get().dir("macos-x64"))
"arm64" -> getChromeDriver("mac-arm64", properties, appResourcesRootDir.get().dir("macos-arm64"))
}

iconFile = file("src/desktopMain/resources/icons/clipevery.icns")
bundleID = "com.clipevery"
appCategory = "public.app-category.utilities"
Expand All @@ -111,8 +130,42 @@ compose.desktop {
}
}
windows {

val architecture = System.getProperty("os.arch")

if (architecture.contains("64")) {
getChromeDriver("win64", properties, appResourcesRootDir.get().dir("windows-x64"))
} else {
getChromeDriver("win32", properties, appResourcesRootDir.get().dir("windows-x86"))
}

iconFile = file("src/desktopMain/resources/icons/clipevery.ico")
}
}
}
}

fun getChromeDriver(driverOsArch: String, properties: Properties, resourceDir: Directory) {
val chromeDriver = "chromedriver-$driverOsArch"
val chromeHeadlessShell = "chrome-headless-shell-$driverOsArch"

download(chromeDriver, properties, resourceDir)
download(chromeHeadlessShell, properties, resourceDir)
}

fun download(name: String, properties: Properties, resourceDir: Directory) {
if (resourceDir.dir(name).asFileTree.isEmpty) {
val chromeHeadlessShellUrl = properties.getProperty(name)!!
download.run {
src { chromeHeadlessShellUrl }
dest { resourceDir }
overwrite(true)
tempAndMove(true)
}
copy {
from(zipTree(resourceDir.file("$name.zip")))
into(resourceDir)
}
delete(resourceDir.file("$name.zip"))
}
}
10 changes: 10 additions & 0 deletions composeApp/webDriver.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chromedriver-linux64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/linux64/chromedriver-linux64.zip
chromedriver-mac-arm64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/mac-arm64/chromedriver-mac-arm64.zip
chromedriver-mac-x64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/mac-x64/chromedriver-mac-x64.zip
chromedriver-win32=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/win32/chromedriver-win32.zip
chromedriver-win64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/win64/chromedriver-win64.zip
chrome-headless-shell-linux64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/linux64/chrome-headless-shell-linux64.zip
chrome-headless-shell-mac-arm64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/mac-arm64/chrome-headless-shell-mac-arm64.zip
chrome-headless-shell-mac-x64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/mac-x64/chrome-headless-shell-mac-x64.zip
chrome-headless-shell-win32=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/win32/chrome-headless-shell-win32.zip
chrome-headless-shell-win64=https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.69/win64/chrome-headless-shell-win64.zip
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ compose-plugin = "1.6.0-rc03"
compose-compiler = "1.5.8"
compose-shimmer = "1.2.0"
compose-webview-multiplatform = "1.8.8"
download = "5.5.0"
guava = "33.0.0-jre"
jmdns = "3.5.9"
jna = "5.14.0"
Expand Down Expand Up @@ -66,7 +67,8 @@ junit = { group = "junit", name = "junit", version.ref = "junit" }


[plugins]
download = { id = "de.undercouch.download", version.ref = "download" }
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
realmKotlin = { id = "io.realm.kotlin", version.ref = "realm" }
realmKotlin = { id = "io.realm.kotlin", version.ref = "realm" }

0 comments on commit 0cce384

Please sign in to comment.