Browse Source

Provide default icon for native distributions

Resolves #274
pull/478/head
Alexey Tsvetkov 4 years ago committed by Alexey Tsvetkov
parent
commit
0314bc4b80
  1. 38
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/DefaultIcons.kt
  2. 6
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt
  3. BIN
      gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-linux.png
  4. BIN
      gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-mac.icns
  5. BIN
      gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-windows.ico

38
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/DefaultIcons.kt

@ -0,0 +1,38 @@
package org.jetbrains.compose.desktop.application.internal
import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.jetbrains.compose.ComposeBuildConfig
internal object DefaultIcons {
fun forLinux(project: Project): Provider<RegularFile> =
unpackIconIfNeeded(project, platformName = "linux", iconExt = "png")
fun forWindows(project: Project): Provider<RegularFile> =
unpackIconIfNeeded(project, platformName = "windows", iconExt = "ico")
fun forMac(project: Project): Provider<RegularFile> =
unpackIconIfNeeded(project, platformName = "mac", iconExt = "icns")
private fun unpackIconIfNeeded(project: Project, platformName: String, iconExt: String): Provider<RegularFile> {
val iconsDir = project.layout.buildDirectory.dir("compose/default-icons/${ComposeBuildConfig.composeVersion}")
val targetFile = iconsDir.map { it.file("icon-$platformName.$iconExt") }
val targetIoFile = targetFile.ioFile
val sourceIconName = "default-compose-desktop-icon-$platformName.$iconExt"
if (targetIoFile.exists()) return targetFile
val iconResourceStream = DefaultIcons.javaClass.classLoader.getResourceAsStream(sourceIconName)
?: error("Could not find default icon resource: $sourceIconName")
iconResourceStream.use { input ->
targetIoFile.parentFile.mkdirs()
targetIoFile.createNewFile()
targetIoFile.outputStream().buffered().use { output ->
input.copyTo(output)
}
}
return targetFile
}
}

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

@ -213,7 +213,7 @@ internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
linuxMenuGroup.set(provider { linux.menuGroup })
linuxPackageName.set(provider { linux.packageName })
linuxRpmLicenseType.set(provider { linux.rpmLicenseType })
iconFile.set(linux.iconFile)
iconFile.set(linux.iconFile.orElse(DefaultIcons.forLinux(project)))
installationPath.set(linux.installationPath)
}
}
@ -226,7 +226,7 @@ internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
winMenu.set(provider { win.menu })
winMenuGroup.set(provider { win.menuGroup })
winUpgradeUuid.set(provider { win.upgradeUuid })
iconFile.set(win.iconFile)
iconFile.set(win.iconFile.orElse(DefaultIcons.forWindows(project)))
installationPath.set(win.installationPath)
}
}
@ -241,7 +241,7 @@ internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) {
)
nonValidatedMacBundleID.set(provider { mac.bundleID })
nonValidatedMacSigningSettings = app.nativeDistributions.macOS.signing
iconFile.set(mac.iconFile)
iconFile.set(mac.iconFile.orElse(DefaultIcons.forMac(project)))
installationPath.set(mac.installationPath)
}
}

BIN
gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-linux.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

BIN
gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-mac.icns

Binary file not shown.

BIN
gradle-plugins/compose/src/main/resources/default-compose-desktop-icon-windows.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Loading…
Cancel
Save