From ef2753f94d29e0424a5f916b1d2ec28ce59ca41d Mon Sep 17 00:00:00 2001 From: zainarbani Date: Tue, 24 Sep 2024 17:23:09 +0700 Subject: [PATCH 1/8] fix(YouTube - Remove background playback restrictions): Enable for Shorts as well --- .../youtube/patches/BackgroundPlaybackPatch.java | 14 +++++--------- .../integrations/youtube/settings/Settings.java | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index e6e449a0cb..d349989818 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -1,5 +1,6 @@ package app.revanced.integrations.youtube.patches; +import app.revanced.integrations.youtube.settings.Settings; import app.revanced.integrations.youtube.shared.PlayerType; @SuppressWarnings("unused") @@ -8,7 +9,7 @@ public class BackgroundPlaybackPatch { /** * Injection point. */ - public static boolean playbackIsNotShort() { + public static boolean isBackgroundPlaybackAllowed() { // Steps to verify most edge cases: // 1. Open a regular video // 2. Minimize app (PIP should appear) @@ -20,16 +21,11 @@ public static boolean playbackIsNotShort() { // 7. Close the Short // 8. Resume playing the regular video // 9. Minimize the app (PIP should appear) - - if (!VideoInformation.lastVideoIdIsShort()) { - return true; // Definitely is not a Short. + if (VideoInformation.lastVideoIdIsShort()) { + return !Settings.DISABLE_BACKGROUND_SHORTS.get(); } - // Might be a Short, or might be a prior regular video on screen again after a Short was closed. - // This incorrectly prevents PIP if player is in WATCH_WHILE_MINIMIZED after closing a Short, - // But there's no way around this unless an additional hook is added to definitively detect - // the Shorts player is on screen. This use case is unusual anyways so it's not a huge concern. - return !PlayerType.getCurrent().isNoneHiddenOrMinimized(); + return true; } /** diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index b95ed7f7b0..d6113c811f 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -209,6 +209,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); // Shorts + public static final BooleanSetting DISABLE_BACKGROUND_SHORTS = new BooleanSetting("revanced_disable_background_shorts", FALSE); public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); public static final BooleanSetting HIDE_SHORTS_HOME = new BooleanSetting("revanced_hide_shorts_home", FALSE); public static final BooleanSetting HIDE_SHORTS_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_subscriptions", FALSE); From 771bb3f996b686d261cb3722a21df548a6dd882a Mon Sep 17 00:00:00 2001 From: zainarbani Date: Wed, 25 Sep 2024 12:49:16 +0700 Subject: [PATCH 2/8] fix: Update prefs --- .../integrations/youtube/patches/BackgroundPlaybackPatch.java | 2 +- .../app/revanced/integrations/youtube/settings/Settings.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index d349989818..53a42f1749 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -22,7 +22,7 @@ public static boolean isBackgroundPlaybackAllowed() { // 8. Resume playing the regular video // 9. Minimize the app (PIP should appear) if (VideoInformation.lastVideoIdIsShort()) { - return !Settings.DISABLE_BACKGROUND_SHORTS.get(); + return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); } return true; diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index d6113c811f..6f73add938 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -209,7 +209,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); // Shorts - public static final BooleanSetting DISABLE_BACKGROUND_SHORTS = new BooleanSetting("revanced_disable_background_shorts", FALSE); + public static final BooleanSetting ALLOW_SHORTS_BACKGROUND_PLAYBACK = new BooleanSetting("revanced_shorts_background_playback", FALSE); public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); public static final BooleanSetting HIDE_SHORTS_HOME = new BooleanSetting("revanced_hide_shorts_home", FALSE); public static final BooleanSetting HIDE_SHORTS_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_subscriptions", FALSE); From b623c80a47f3c24cbda258c7b46e3dba8d122889 Mon Sep 17 00:00:00 2001 From: zainarbani Date: Wed, 25 Sep 2024 15:55:35 +0700 Subject: [PATCH 3/8] fix: Restore previous check --- .../youtube/patches/BackgroundPlaybackPatch.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index 53a42f1749..ddc3607aff 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -21,11 +21,21 @@ public static boolean isBackgroundPlaybackAllowed() { // 7. Close the Short // 8. Resume playing the regular video // 9. Minimize the app (PIP should appear) - if (VideoInformation.lastVideoIdIsShort()) { - return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); + if (!VideoInformation.lastVideoIdIsShort()) { + return true; // Definitely is not a Short. } - return true; + // TODO: Add better hook. + // Might be a Shorts, or might be a prior regular video on screen again after a Shorts was closed. + // This incorrectly prevents PIP if player is in WATCH_WHILE_MINIMIZED after closing a Shorts, + // But there's no way around this unless an additional hook is added to definitively detect + // the Shorts player is on screen. This use case is unusual anyways so it's not a huge concern. + if (!PlayerType.getCurrent().isNoneHiddenOrMinimized()) { + return true; + } + + // Only Shorts video should reach here. + return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); } /** From 4c46e19e46b2cd97ce29e5568fff52021d2e3b03 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 26 Sep 2024 07:15:03 -0400 Subject: [PATCH 4/8] refactor: Use a separate integrations method for Shorts --- .../youtube/patches/BackgroundPlaybackPatch.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index ddc3607aff..7609be45ef 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -10,7 +10,7 @@ public class BackgroundPlaybackPatch { * Injection point. */ public static boolean isBackgroundPlaybackAllowed() { - // Steps to verify most edge cases: + // Steps to verify most edge cases (with Shorts background playback set to off): // 1. Open a regular video // 2. Minimize app (PIP should appear) // 3. Reopen app @@ -30,11 +30,13 @@ public static boolean isBackgroundPlaybackAllowed() { // This incorrectly prevents PIP if player is in WATCH_WHILE_MINIMIZED after closing a Shorts, // But there's no way around this unless an additional hook is added to definitively detect // the Shorts player is on screen. This use case is unusual anyways so it's not a huge concern. - if (!PlayerType.getCurrent().isNoneHiddenOrMinimized()) { - return true; - } + return !PlayerType.getCurrent().isNoneHiddenOrMinimized(); + } - // Only Shorts video should reach here. + /** + * Injection point. + */ + public static boolean isBackgroundShortsPlaybackAllowed() { return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); } From 625b3a0801d4c86b0c3eb1f3a691c6a1671ddb53 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 20 Oct 2024 08:37:52 -0400 Subject: [PATCH 5/8] fix merge typo --- .../integrations/youtube/patches/BackgroundPlaybackPatch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index 4c50922bd2..707eaf15a5 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -9,7 +9,7 @@ public class BackgroundPlaybackPatch { /** * Injection point. */ - public static boolean allowBackgroundPlayback(boolean original) { + public static boolean isBackgroundPlaybackAllowed(boolean original) { if (original) return true; // Steps to verify most edge cases (with Shorts background playback set to off): From 1a11e49d8d55a5348ee21977e34431abf375492a Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 20 Oct 2024 08:42:48 -0400 Subject: [PATCH 6/8] fix more merge typos --- .../integrations/youtube/patches/BackgroundPlaybackPatch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index 707eaf15a5..0530f809e5 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -38,7 +38,7 @@ public static boolean isBackgroundPlaybackAllowed(boolean original) { /** * Injection point. */ - public static boolean isBackgroundShortsPlaybackAllowed() { + public static boolean isBackgroundShortsPlaybackAllowed(boolean original) { return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); } From bd33260e1897629c87df0573c3ccefb3d06104a0 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 21 Oct 2024 03:43:36 -0400 Subject: [PATCH 7/8] fix: Enable by default --- .../app/revanced/integrations/youtube/settings/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index 30815df45b..52b94e4082 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -216,7 +216,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); // Shorts - public static final BooleanSetting ALLOW_SHORTS_BACKGROUND_PLAYBACK = new BooleanSetting("revanced_shorts_background_playback", FALSE); + public static final BooleanSetting ALLOW_SHORTS_BACKGROUND_PLAYBACK = new BooleanSetting("revanced_shorts_background_playback", TRUE); public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); public static final BooleanSetting HIDE_SHORTS_HOME = new BooleanSetting("revanced_hide_shorts_home", FALSE); public static final BooleanSetting HIDE_SHORTS_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_subscriptions", FALSE); From e1f31b114baac8ddfa1fcd61e89194ab5f325c86 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:06:53 -0400 Subject: [PATCH 8/8] fix: Use UI convention of 'switch off' = 'stock app' --- .../integrations/youtube/patches/BackgroundPlaybackPatch.java | 2 +- .../app/revanced/integrations/youtube/settings/Settings.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java index 0530f809e5..cc8f77ce92 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/BackgroundPlaybackPatch.java @@ -39,7 +39,7 @@ public static boolean isBackgroundPlaybackAllowed(boolean original) { * Injection point. */ public static boolean isBackgroundShortsPlaybackAllowed(boolean original) { - return Settings.ALLOW_SHORTS_BACKGROUND_PLAYBACK.get(); + return !Settings.DISABLE_SHORTS_BACKGROUND_PLAYBACK.get(); } /** diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index 52b94e4082..a0013ad14b 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -216,7 +216,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true); // Shorts - public static final BooleanSetting ALLOW_SHORTS_BACKGROUND_PLAYBACK = new BooleanSetting("revanced_shorts_background_playback", TRUE); + public static final BooleanSetting DISABLE_SHORTS_BACKGROUND_PLAYBACK = new BooleanSetting("revanced_shorts_disable_background_playback", FALSE); public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", FALSE); public static final BooleanSetting HIDE_SHORTS_HOME = new BooleanSetting("revanced_hide_shorts_home", FALSE); public static final BooleanSetting HIDE_SHORTS_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_subscriptions", FALSE);