Skip to content

Commit

Permalink
fixup! Add file associations support
Browse files Browse the repository at this point in the history
[Desktop: Add support for file associations](#773)
  • Loading branch information
zhelenskiy committed Jun 21, 2024
1 parent 100aeef commit 811739d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.jetbrains.compose.desktop.application.dsl
import java.io.File
import java.io.Serializable

data class FileAssociation(
internal data class FileAssociation(
val mimeType: String,
val extension: String,
val description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,37 @@ private fun indentForLevel(level: Int) = indent.repeat(level)

internal class InfoPlistBuilder(private val extraPlistKeysRawXml: String? = null) {
internal sealed class InfoPlistValue {
abstract fun toString(nestingLevel: Int): String
override fun toString(): String = toString(0)
abstract fun asPlistEntry(nestingLevel: Int): String
data class InfoPlistListValue(val elements: List<InfoPlistValue>) : InfoPlistValue() {
override fun toString(nestingLevel: Int): String =
override fun asPlistEntry(nestingLevel: Int): String =
if (elements.isEmpty()) "${indentForLevel(nestingLevel)}<array/>"
else elements.joinToString(
separator = "\n",
prefix = "${indentForLevel(nestingLevel)}<array>\n",
postfix = "\n${indentForLevel(nestingLevel)}</array>"
) {
it.toString(nestingLevel + 1)
it.asPlistEntry(nestingLevel + 1)
}

override fun toString(): String = super.toString()

constructor(vararg elements: InfoPlistValue) : this(elements.asList())
}

data class InfoPlistMapValue(val elements: Map<InfoPlistKey, InfoPlistValue>) : InfoPlistValue() {
override fun toString(nestingLevel: Int): String =
override fun asPlistEntry(nestingLevel: Int): String =
if (elements.isEmpty()) "${indentForLevel(nestingLevel)}<dict/>"
else elements.entries.joinToString(
separator = "\n",
prefix = "${indentForLevel(nestingLevel)}<dict>\n",
postfix = "\n${indentForLevel(nestingLevel)}</dict>",
) { (key, value) ->
"${indentForLevel(nestingLevel + 1)}<key>${key.name}</key>\n${value.toString(nestingLevel + 1)}"
"${indentForLevel(nestingLevel + 1)}<key>${key.name}</key>\n${value.asPlistEntry(nestingLevel + 1)}"
}
override fun toString() = super.toString()

constructor(vararg elements: Pair<InfoPlistKey, InfoPlistValue>) : this(elements.toMap())
}

data class InfoPlistStringValue(val value: String) : InfoPlistValue() {
override fun toString(nestingLevel: Int): String = if (value.isEmpty()) "${indentForLevel(nestingLevel)}<string/>" else "${indentForLevel(nestingLevel)}<string>$value</string>"
override fun toString() = super.toString()
override fun asPlistEntry(nestingLevel: Int): String = if (value.isEmpty()) "${indentForLevel(nestingLevel)}<string/>" else "${indentForLevel(nestingLevel)}<string>$value</string>"
}
}

Expand Down Expand Up @@ -78,7 +73,7 @@ internal class InfoPlistBuilder(private val extraPlistKeysRawXml: String? = null
appendLine("${indentForLevel(1)}<dict>")
for ((k, v) in values) {
appendLine("${indentForLevel(2)}<key>${k.name}</key>")
appendLine(v.toString(2))
appendLine(v.asPlistEntry(2))
}
extraPlistKeysRawXml?.let { appendLine(it) }
appendLine("${indentForLevel(1)}</dict>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ internal fun JvmApplicationContext.configurePlatformSettings(
packageTask.linuxRpmLicenseType.set(provider { linux.rpmLicenseType })
packageTask.iconFile.set(linux.iconFile.orElse(defaultResources.get { linuxIcon }))
packageTask.installationPath.set(linux.installationPath)
packageTask.fileAssociations.set(linux.fileAssociations)
packageTask.fileAssociations.set(provider { linux.fileAssociations })
}
}
OS.Windows -> {
Expand All @@ -389,7 +389,7 @@ internal fun JvmApplicationContext.configurePlatformSettings(
packageTask.winUpgradeUuid.set(provider { win.upgradeUuid })
packageTask.iconFile.set(win.iconFile.orElse(defaultResources.get { windowsIcon }))
packageTask.installationPath.set(win.installationPath)
packageTask.fileAssociations.set(win.fileAssociations)
packageTask.fileAssociations.set(provider { win.fileAssociations })
}
}
OS.MacOS -> {
Expand All @@ -416,7 +416,7 @@ internal fun JvmApplicationContext.configurePlatformSettings(
packageTask.nonValidatedMacSigningSettings = app.nativeDistributions.macOS.signing
packageTask.iconFile.set(mac.iconFile.orElse(defaultResources.get { macIcon }))
packageTask.installationPath.set(mac.installationPath)
packageTask.fileAssociations.set(mac.fileAssociations)
packageTask.fileAssociations.set(provider { mac.fileAssociations })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ abstract class AbstractJPackageTask @Inject constructor(

@get:Input
@get:Optional
val fileAssociations: SetProperty<FileAssociation> = objects.setProperty(FileAssociation::class.java)
internal val fileAssociations: SetProperty<FileAssociation> = objects.setProperty(FileAssociation::class.java)

private val iconMapping by lazy {
val icons = fileAssociations.orNull.orEmpty().mapNotNull { it.iconFile }
Expand Down

0 comments on commit 811739d

Please sign in to comment.