chore(YouTube): Match some Extension with ReVanced

This commit is contained in:
inotia00 2024-12-21 13:41:15 +09:00
parent 1c06f2eee4
commit f848b9fcac
4 changed files with 64 additions and 35 deletions

View File

@ -54,8 +54,24 @@ public class Logger {
* so the performance cost of building strings is paid only if {@link BaseSettings#ENABLE_DEBUG_LOGGING} is enabled. * so the performance cost of building strings is paid only if {@link BaseSettings#ENABLE_DEBUG_LOGGING} is enabled.
*/ */
public static void printDebug(@NonNull LogMessage message) { public static void printDebug(@NonNull LogMessage message) {
printDebug(message, null);
}
/**
* Logs debug messages under the outer class name of the code calling this method.
* Whenever possible, the log string should be constructed entirely inside {@link LogMessage#buildMessageString()}
* so the performance cost of building strings is paid only if {@link BaseSettings#ENABLE_DEBUG_LOGGING} is enabled.
*/
public static void printDebug(@NonNull LogMessage message, @Nullable Exception ex) {
if (ENABLE_DEBUG_LOGGING.get()) { if (ENABLE_DEBUG_LOGGING.get()) {
Log.d(REVANCED_LOG_PREFIX + message.findOuterClassSimpleName(), message.buildMessageString()); String logTag = REVANCED_LOG_PREFIX + message.findOuterClassSimpleName();
String logMessage = message.buildMessageString();
if (ex == null) {
Log.d(logTag, logMessage);
} else {
Log.d(logTag, logMessage, ex);
}
} }
} }

View File

@ -79,37 +79,41 @@ public class PlaybackSpeedPatch {
* @param playbackSpeed The playback speed the user selected * @param playbackSpeed The playback speed the user selected
*/ */
public static void userSelectedPlaybackSpeed(float playbackSpeed) { public static void userSelectedPlaybackSpeed(float playbackSpeed) {
if (PatchStatus.RememberPlaybackSpeed() && try {
Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED.get()) { if (PatchStatus.RememberPlaybackSpeed() &&
// With the 0.05x menu, if the speed is set by integrations to higher than 2.0x Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED.get()) {
// then the menu will allow increasing without bounds but the max speed is // With the 0.05x menu, if the speed is set by integrations to higher than 2.0x
// still capped to under 8.0x. // then the menu will allow increasing without bounds but the max speed is
playbackSpeed = Math.min(playbackSpeed, CustomPlaybackSpeedPatch.PLAYBACK_SPEED_MAXIMUM - 0.05f); // still capped to under 8.0x.
playbackSpeed = Math.min(playbackSpeed, CustomPlaybackSpeedPatch.PLAYBACK_SPEED_MAXIMUM - 0.05f);
// Prevent toast spamming if using the 0.05x adjustments. // Prevent toast spamming if using the 0.05x adjustments.
// Show exactly one toast after the user stops interacting with the speed menu. // Show exactly one toast after the user stops interacting with the speed menu.
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
lastTimeSpeedChanged = now; lastTimeSpeedChanged = now;
final float finalPlaybackSpeed = playbackSpeed; final float finalPlaybackSpeed = playbackSpeed;
Utils.runOnMainThreadDelayed(() -> { Utils.runOnMainThreadDelayed(() -> {
if (lastTimeSpeedChanged != now) { if (lastTimeSpeedChanged != now) {
// The user made additional speed adjustments and this call is outdated. // The user made additional speed adjustments and this call is outdated.
return; return;
} }
if (Settings.DEFAULT_PLAYBACK_SPEED.get() == finalPlaybackSpeed) { if (Settings.DEFAULT_PLAYBACK_SPEED.get() == finalPlaybackSpeed) {
// User changed to a different speed and immediately changed back. // User changed to a different speed and immediately changed back.
// Or the user is going past 8.0x in the glitched out 0.05x menu. // Or the user is going past 8.0x in the glitched out 0.05x menu.
return; return;
} }
Settings.DEFAULT_PLAYBACK_SPEED.save(finalPlaybackSpeed); Settings.DEFAULT_PLAYBACK_SPEED.save(finalPlaybackSpeed);
if (!Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_TOAST.get()) { if (!Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_TOAST.get()) {
return; return;
} }
Utils.showToastShort(str("revanced_remember_playback_speed_toast", (finalPlaybackSpeed + "x"))); Utils.showToastShort(str("revanced_remember_playback_speed_toast", (finalPlaybackSpeed + "x")));
}, TOAST_DELAY_MILLISECONDS); }, TOAST_DELAY_MILLISECONDS);
}
} catch (Exception ex) {
Logger.printException(() -> "userSelectedPlaybackSpeed failure", ex);
} }
} }

View File

@ -369,7 +369,10 @@ public final class VideoInformation {
* @param newlyLoadedPlaybackSpeed The current playback speed. * @param newlyLoadedPlaybackSpeed The current playback speed.
*/ */
public static void setPlaybackSpeed(float newlyLoadedPlaybackSpeed) { public static void setPlaybackSpeed(float newlyLoadedPlaybackSpeed) {
playbackSpeed = newlyLoadedPlaybackSpeed; if (playbackSpeed != newlyLoadedPlaybackSpeed) {
Logger.printDebug(() -> "Video speed changed: " + newlyLoadedPlaybackSpeed);
playbackSpeed = newlyLoadedPlaybackSpeed;
}
} }
/** /**

View File

@ -2,13 +2,21 @@ package app.revanced.patches.youtube.utils.fix.cairo
import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.misc.backgroundplayback.backgroundPlaybackPatch import app.revanced.patches.youtube.misc.backgroundplayback.backgroundPlaybackPatch
import app.revanced.patches.youtube.utils.playservice.is_19_04_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
import app.revanced.util.fingerprint.resolvable import app.revanced.util.fingerprint.resolvable
val cairoSettingsPatch = bytecodePatch( val cairoSettingsPatch = bytecodePatch(
description = "cairoSettingsPatch" description = "cairoSettingsPatch"
) { ) {
dependsOn(versionCheckPatch)
execute { execute {
if (!is_19_04_or_greater) {
return@execute
}
/** /**
* Cairo Fragment was added since YouTube v19.04.38. * Cairo Fragment was added since YouTube v19.04.38.
* Disable this for the following reasons: * Disable this for the following reasons:
@ -19,11 +27,9 @@ val cairoSettingsPatch = bytecodePatch(
* or <a href="https://github.com/qnblackcat/uYouPlus/issues/1468">uYouPlus#1468</a> * or <a href="https://github.com/qnblackcat/uYouPlus/issues/1468">uYouPlus#1468</a>
* for screenshots of the Cairo Fragment. * for screenshots of the Cairo Fragment.
*/ */
if (carioFragmentConfigFingerprint.resolvable()) { carioFragmentConfigFingerprint.injectLiteralInstructionBooleanCall(
carioFragmentConfigFingerprint.injectLiteralInstructionBooleanCall( CAIRO_FRAGMENT_FEATURE_FLAG,
45532100L, "0x0"
"0x0" )
)
}
} }
} }