diff --git a/.gitignore b/.gitignore index 5d99c80c0..fe8c2efdc 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ logs composeApp/docs /composeApp/DawnCache/ /composeApp/GPUCache/ +chrome-headless-shell-*/ +chromedriver-*/ diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index a521c8b78..0985d8ff0 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -1,4 +1,6 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat +import java.io.FileReader +import java.util.Properties repositories { mavenCentral() @@ -12,6 +14,7 @@ plugins { alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.kotlinSerialization) alias(libs.plugins.realmKotlin) + alias(libs.plugins.download) } kotlin { @@ -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" @@ -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")) + } +} diff --git a/composeApp/webDriver.properties b/composeApp/webDriver.properties new file mode 100644 index 000000000..7cac13e61 --- /dev/null +++ b/composeApp/webDriver.properties @@ -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 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 990459748..cc99c09d6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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" } \ No newline at end of file +realmKotlin = { id = "io.realm.kotlin", version.ref = "realm" }