This commit is contained in:
inotia00 2023-05-06 02:05:14 +09:00
parent d77c8a4c83
commit ae677ed8dd
3 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package app.revanced.patches.microg.layout.hideicon.patch
import app.revanced.extensions.doRecursively
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.MicroGCompatibility
import org.w3c.dom.Element
@Patch(false)
@Name("hide-icon-from-launcher")
@Description("Hide MicroG icon from launcher.")
@MicroGCompatibility
@Version("0.0.1")
class HideIconPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor["AndroidManifest.xml"].use { editor ->
editor.file.doRecursively loop@{
if (it !is Element) return@loop
it.getAttributeNode("android:name")?.let { attribute ->
if (attribute.textContent == "android.intent.category.LAUNCHER") {
attribute.textContent = "android.intent.category.DEFAULT"
}
}
}
}
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,9 @@
package app.revanced.patches.shared.annotation
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package
@Compatibility([Package("com.mgoogle.android.gms")])
@Target(AnnotationTarget.CLASS)
internal annotation class MicroGCompatibility

View File

@ -0,0 +1,63 @@
package app.revanced.util.resources
import app.revanced.extensions.doRecursively
import app.revanced.patcher.data.ResourceContext
import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.copyXmlNode
import org.w3c.dom.Element
internal object MicroGResourceUtils {
internal fun ResourceContext.copyFiles(path: String) {
fun copyResources(resourceGroups: List<ResourceUtils.ResourceGroup>) {
resourceGroups.forEach { this.copyResources(path, it) }
}
val iconResourceFileNames = arrayOf(
"ic_microg_launcher"
).map { "$it.png" }.toTypedArray()
fun createGroup(directory: String) = ResourceUtils.ResourceGroup(
directory, *iconResourceFileNames
)
// change the app icon
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi")
.map { "mipmap-$it" }
.map(::createGroup)
.let(::copyResources)
arrayOf(
ResourceUtils.ResourceGroup(
"drawable",
"ic_app_icons_themed_microg.xml",
"ic_microg_launcher_foreground.xml"
),
ResourceUtils.ResourceGroup(
"mipmap-anydpi-v26",
"ic_microg_launcher.xml"
)
).forEach { this.copyResources(path, it) }
this.copyXmlNode(path, "values/colors.xml", "resources")
this.setManifestIcon()
}
private fun ResourceContext.setManifestIcon() {
this.xmlEditor["AndroidManifest.xml"].use {
val attributes = arrayOf("icon", "roundIcon")
it.file.doRecursively {
attributes.forEach replacement@{ replacement ->
if (it !is Element) return@replacement
it.getAttributeNode("android:$replacement")?.let { attribute ->
if (attribute.textContent.startsWith("@mipmap/"))
attribute.textContent = "@mipmap/ic_microg_launcher"
}
}
}
}
}
}