mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-01 07:04:30 +02:00
feat(microg): hide-icon-from-launcher
patch https://github.com/inotia00/ReVanced_Extended/issues/923
This commit is contained in:
parent
d77c8a4c83
commit
ae677ed8dd
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user