Skip to content

Commit

Permalink
fix(YouTube - Exit fullscreen mode): Exit fullscreen mode of first vi…
Browse files Browse the repository at this point in the history
…deo opened after cold start
  • Loading branch information
LisoUseInAIKyrios committed Dec 27, 2024
1 parent c5b3255 commit be5cf2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ public static void endOfVideoReached() {
}
}

ImageView fullscreenButton = PlayerControlsPatch.fullscreenButtonRef.get();
if (fullscreenButton == null) {
Logger.printDebug(() -> "Fullscreen button is null, cannot click");
} else {
Logger.printDebug(() -> "Clicking fullscreen button");
fullscreenButton.performClick();
}
// If the user cold launches the app and plays a video but does not
// tap to show the overlay controls, the fullscreen button is not
// set because the overlay controls are not attached.
// To fix this, push the perform click to the back fo the main thread,
// and by then the overlay controls will be visible since the video is now finished.
Utils.runOnMainThread(() -> {
ImageView button = PlayerControlsPatch.fullscreenButtonRef.get();
if (button == null) {
Logger.printDebug(() -> "Fullscreen button is null, cannot click");
} else {
Logger.printDebug(() -> "Clicking fullscreen button");
button.performClick();
}
});
}
} catch (Exception ex) {
Logger.printException(() -> "endOfVideoReached failure", ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.revanced.patches.youtube.layout.player.fullscreen

import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
Expand All @@ -12,6 +11,7 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.patches.youtube.shared.autoRepeatFingerprint
import app.revanced.patches.youtube.shared.autoRepeatParentFingerprint
import app.revanced.util.addInstructionsAtControlFlowLabel

@Suppress("unused")
internal val exitFullscreenPatch = bytecodePatch(
Expand Down Expand Up @@ -57,9 +57,11 @@ internal val exitFullscreenPatch = bytecodePatch(
)
)

autoRepeatFingerprint.match(autoRepeatParentFingerprint.originalClassDef).method.addInstruction(
0,
"invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->endOfVideoReached()V",
)
autoRepeatFingerprint.match(autoRepeatParentFingerprint.originalClassDef).method.apply {
addInstructionsAtControlFlowLabel(
implementation!!.instructions.lastIndex,
"invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->endOfVideoReached()V",
)
}
}
}

0 comments on commit be5cf2e

Please sign in to comment.