Skip to content

Commit

Permalink
Support extract ManifestXml application attrributes (#2242)
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 18, 2024
1 parent 9b83d39 commit 2f6548b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ open class KorgeExtension(
val androidGradleClasspaths = LinkedHashSet<String>()
val androidManifestApplicationChunks = LinkedHashSet<String>()
val androidManifestChunks = LinkedHashSet<String>()
val androidCustomApplicationAttributes = LinkedHashMap<String, String>()
var androidMsaa: Int? = null

fun plugin(name: String, args: Map<String, String> = mapOf()) {
Expand All @@ -511,6 +512,11 @@ open class KorgeExtension(
androidManifestApplicationChunks += text
}

/** For example: androidCustomApplicationAttribute("android:usesCleartextTraffic", "true") */
fun androidCustomApplicationAttribute(key: String, value: String) {
androidCustomApplicationAttributes[key] = value
}

fun androidGradlePlugin(name: String) {
androidGradlePlugins += name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun Project.toAndroidGenerated(isKorge: Boolean, info: AndroidInfo = AndroidInfo
androidManifestApplicationChunks = korge.androidManifestApplicationChunks,
androidManifest = korge.plugins.pluginExts.getAndroidManifestApplication() + info.androidManifest,
androidLibrary = if (isKorge) korge.androidLibrary else false,
androidCustomApplicationAttributes = korge.androidCustomApplicationAttributes,
projectName = project.name,
buildDir = project.buildDir,
)
Expand All @@ -66,6 +67,7 @@ data class AndroidGenerated constructor(
val androidManifestChunks: Set<String> = emptySet(),
val androidManifestApplicationChunks: Set<String> = emptySet(),
val androidManifest: List<String> = emptyList(),
val androidCustomApplicationAttributes: Map<String, String> = emptyMap(),
val androidLibrary: Boolean = true,
val projectName: String,
val buildDir: File,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ object AndroidManifestXml {
line("<resources>")
indent {
line("<style name=\"AppThemeOverride\" parent=\"@android:style/Theme\">")
line("<item name=\"android:windowNoTitle\">true</item>")
line("<item name=\"android:windowFullscreen\">true</item>")
line("<item name=\"android:windowContentOverlay\">@null</item>")
line("<item name=\"android:windowLayoutInDisplayCutoutMode\">${config.displayCutout.lc}</item>")
line("<item name=\"android:windowTranslucentStatus\">true</item>")
line("<item name=\"android:windowTranslucentNavigation\">true</item>")
line("<item name=\"android:windowDrawsSystemBarBackgrounds\">false</item>")
line("<item name=\"android:windowNoTitle\">true</item>")
line("<item name=\"android:windowFullscreen\">true</item>")
line("<item name=\"android:windowContentOverlay\">@null</item>")
line("<item name=\"android:windowLayoutInDisplayCutoutMode\">${config.displayCutout.lc}</item>")
line("<item name=\"android:windowTranslucentStatus\">true</item>")
line("<item name=\"android:windowTranslucentNavigation\">true</item>")
line("<item name=\"android:windowDrawsSystemBarBackgrounds\">false</item>")
line("</style>")
}
line("</resources>")
Expand All @@ -40,6 +40,10 @@ object AndroidManifestXml {
//line("tools:replace=\"android:appComponentFactory\"")
line("android:allowBackup=\"true\"")

for ((key, value) in config.androidCustomApplicationAttributes) {
line("$key=\"${value.htmlspecialchars()}\"")
}

if (!config.androidLibrary) {
line("android:label=\"${config.androidAppName}\"")
line("android:icon=\"@mipmap/icon\"")
Expand Down Expand Up @@ -98,3 +102,16 @@ object AndroidManifestXml {
line("</manifest>")
}.toString()
}

private fun String.htmlspecialchars(): String = buildString(this@htmlspecialchars.length + 16) {
for (it in this@htmlspecialchars) {
when (it) {
'"' -> append("&quot;")
'\'' -> append("&apos;")
'<' -> append("&lt;")
'>' -> append("&gt;")
'&' -> append("&amp;")
else -> append(it)
}
}
}

0 comments on commit 2f6548b

Please sign in to comment.