generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Twitter/X): Use chooser when opening links
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/app/revanced/patches/twitter/misc/browserchooser/BrowserChooserPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package app.revanced.patches.twitter.misc.browserchooser | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.twitter.misc.browserchooser.fingerprints.OpenLinkFingerprint | ||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable | ||
import app.revanced.util.exception | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation | ||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod | ||
import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import java.lang.IllegalStateException | ||
|
||
@Patch( | ||
name = "Open browser chooser on opening links", | ||
description = "Instead of open the link directly in one of the installed browsers", | ||
compatiblePackages = [CompatiblePackage("com.twitter.android")] | ||
) | ||
@Suppress("unused") | ||
object BrowserChooserPatch : BytecodePatch( | ||
setOf(OpenLinkFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
|
||
val result = OpenLinkFingerprint.result | ||
?: throw IllegalStateException("Fingerprint not found") | ||
|
||
val inject = """ | ||
invoke-static {p0, p1}, Lapp/revanced/integrations/twitter/patches/hook/patch/browserchooser/BrowserChooserHook->open(Landroid/content/Context;Landroid/content/Intent;)V | ||
return-void | ||
""".trimIndent() | ||
|
||
result.mutableMethod.addInstructions(0, inject) | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...tlin/app/revanced/patches/twitter/misc/browserchooser/fingerprints/OpenLinkFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.revanced.patches.twitter.misc.browserchooser.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
|
||
internal object OpenLinkFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
parameters = listOf("Landroid/content/Context;", "Landroid/content/Intent;", "Landroid/os/Bundle;") | ||
) |