diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableShortsOnStartupPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt similarity index 65% rename from src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableShortsOnStartupPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt index a8e0212f..83ddb911 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableShortsOnStartupPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.startupshortsreset +import app.revanced.extensions.exception import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.patch.BytecodePatch @@ -12,8 +13,8 @@ import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch @Patch( - name = "Disable Shorts on startup", - description = "Disables playing YouTube Shorts when launching YouTube.", + name = "Disable resuming Shorts on startup", + description = "Disables resuming the Shorts player on app startup if a Short was last opened.", dependencies = [IntegrationsPatch::class, SettingsPatch::class], compatiblePackages = [ CompatiblePackage( @@ -33,33 +34,37 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch ] ) @Suppress("unused") -object DisableShortsOnStartupPatch : BytecodePatch( +object DisableResumingShortsOnStartupPatch : BytecodePatch( setOf(UserWasInShortsFingerprint) ) { + + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/patches/DisableResumingStartupShortsPlayerPatch;" + override fun execute(context: BytecodeContext) { SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( SwitchPreference( "revanced_disable_resuming_shorts_player", - StringResource("revanced_disable_resuming_shorts_player_title", "Disable Shorts player at app startup"), - StringResource("revanced_disable_resuming_shorts_player_summary_on", "Shorts player is disabled at app startup"), - StringResource("revanced_disable_resuming_shorts_player_summary_off", "Shorts player is enabled at app startup") + StringResource("revanced_disable_resuming_shorts_player_title", "Disable resuming Shorts player"), + StringResource("revanced_disable_resuming_shorts_player_summary_on", "Shorts player will not resume on app startup"), + StringResource("revanced_disable_resuming_shorts_player_summary_off", "Shorts player will resume on app startup") ) ) - val userWasInShortsResult = UserWasInShortsFingerprint.result!! - val userWasInShortsMethod = userWasInShortsResult.mutableMethod - val moveResultIndex = userWasInShortsResult.scanResult.patternScanResult!!.endIndex + UserWasInShortsFingerprint.result?.apply { + val moveResultIndex = scanResult.patternScanResult!!.endIndex - userWasInShortsMethod.addInstructionsWithLabels( - moveResultIndex + 1, - """ - invoke-static { }, Lapp/revanced/integrations/patches/DisableStartupShortsPlayerPatch;->disableStartupShortsPlayer()Z + mutableMethod.addInstructionsWithLabels( + moveResultIndex + 1, + """ + invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->disableResumingStartupShortsPlayer()Z move-result v5 if-eqz v5, :disable_shorts_player return-void :disable_shorts_player nop """ - ) + ) + } ?: throw UserWasInShortsFingerprint.exception } }