Browse Source

Set dock and menu names on macOS (#433)

Resolves #246
pull/443/head 0.3.1
Alexey Tsvetkov 4 years ago committed by GitHub
parent
commit
40f4ad0fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt
  2. 6
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt
  3. 7
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt
  4. 13
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt
  5. 1
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProjects.kt
  6. 3
      gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle
  7. 32
      gradle-plugins/compose/src/test/test-projects/application/macOptions/build.gradle
  8. 10
      gradle-plugins/compose/src/test/test-projects/application/macOptions/settings.gradle
  9. 3
      gradle-plugins/compose/src/test/test-projects/application/macOptions/src/main/kotlin/main.kt

2
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt

@ -13,6 +13,8 @@ abstract class PlatformSettings (objects: ObjectFactory) {
open class MacOSPlatformSettings @Inject constructor(objects: ObjectFactory): PlatformSettings(objects) {
var packageName: String? = null
var dockName: String? = null
var setDockNameSameAsPackageName: Boolean = true
var dmgPackageVersion: String? = null
var pkgPackageVersion: String? = null

6
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt

@ -221,6 +221,12 @@ internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
OS.MacOS -> {
app.nativeDistributions.macOS.also { mac ->
macPackageName.set(provider { mac.packageName })
macDockName.set(
if (mac.setDockNameSameAsPackageName)
provider { mac.dockName }.orElse(macPackageName).orElse(packageName)
else
provider { mac.dockName }
)
nonValidatedMacBundleID.set(provider { mac.bundleID })
nonValidatedMacSigningSettings = app.nativeDistributions.macOS.signing
iconFile.set(mac.iconFile)

7
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt

@ -118,6 +118,10 @@ abstract class AbstractJPackageTask @Inject constructor(
@get:Optional
val macPackageName: Property<String?> = objects.nullableProperty()
@get:Input
@get:Optional
val macDockName: Property<String?> = objects.nullableProperty()
@get:Input
@get:Optional
val winConsole: Property<Boolean?> = objects.nullableProperty()
@ -252,6 +256,9 @@ abstract class AbstractJPackageTask @Inject constructor(
OS.MacOS -> {
cliArg("--mac-package-name", macPackageName)
cliArg("--mac-package-identifier", nonValidatedMacBundleID)
macDockName.orNull?.let { dockName ->
cliArg("--java-options", "-Xdock:name=\"$dockName\"")
}
withValidatedMacOSSigning { signing ->
cliArg("--mac-sign", true)

13
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/DesktopApplicationTest.kt

@ -7,6 +7,7 @@ import org.jetbrains.compose.desktop.application.internal.currentOS
import org.jetbrains.compose.desktop.application.internal.currentTarget
import org.jetbrains.compose.test.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.Test
import java.util.jar.JarFile
@ -135,4 +136,16 @@ class DesktopApplicationTest : GradlePluginTestBase() {
check.logContains("Compose Gradle plugin test log warning!")
}
}
@Test
fun testMacOptions() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
with(testProject(TestProjects.macOptions)) {
gradle(":runDistributable").build().checks { check ->
check.taskOutcome(":runDistributable", TaskOutcome.SUCCESS)
check.logContains("Hello, from Mac OS!")
}
}
}
}

1
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/TestProjects.kt

@ -6,4 +6,5 @@ object TestProjects {
const val jvmKotlinDsl = "application/jvmKotlinDsl"
const val moduleClashCli = "application/moduleClashCli"
const val javaLogger = "application/javaLogger"
const val macOptions = "application/macOptions"
}

3
gradle-plugins/compose/src/test/test-projects/application/jvm/build.gradle

@ -46,6 +46,9 @@ compose.desktop {
menuGroup = "compose"
upgradeUuid = "2d6ff464-75be-40ad-a256-56420b9cc374"
}
macOS {
dockName = "CustomDockName"
}
}
}
}

32
gradle-plugins/compose/src/test/test-projects/application/macOptions/build.gradle

@ -0,0 +1,32 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
id "org.jetbrains.kotlin.jvm"
id "org.jetbrains.compose"
}
repositories {
google()
mavenCentral()
jcenter()
maven {
url "https://maven.pkg.jetbrains.space/public/p/compose/dev"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation compose.desktop.currentOs
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
packageName = "TestPackage"
macOS {
dockName = "CustomDockName"
}
}
}
}

10
gradle-plugins/compose/src/test/test-projects/application/macOptions/settings.gradle

@ -0,0 +1,10 @@
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.jvm' version 'KOTLIN_VERSION_PLACEHOLDER'
id 'org.jetbrains.compose' version 'COMPOSE_VERSION_PLACEHOLDER'
}
repositories {
mavenLocal()
gradlePluginPortal()
}
}

3
gradle-plugins/compose/src/test/test-projects/application/macOptions/src/main/kotlin/main.kt

@ -0,0 +1,3 @@
fun main() {
println("Hello, from Mac OS!")
}
Loading…
Cancel
Save