From 3e4264e3c72ba1e7730dcafe3ea8edeeab0dd9fc Mon Sep 17 00:00:00 2001 From: BandarHelal <31299470+BandarHL@users.noreply.github.com> Date: Sat, 7 May 2022 19:53:13 +0300 Subject: [PATCH 1/2] Update YouPiP --- Tweaks/PSHeader | 2 +- Tweaks/YouPiP | 2 +- Tweaks/YouTubeHeader | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tweaks/PSHeader b/Tweaks/PSHeader index c9355cb..b83b5da 160000 --- a/Tweaks/PSHeader +++ b/Tweaks/PSHeader @@ -1 +1 @@ -Subproject commit c9355cb13688a7a44c58e5d3ad3f9fce51c50d5e +Subproject commit b83b5daf1c0403a075f515bc2c53442adcd52726 diff --git a/Tweaks/YouPiP b/Tweaks/YouPiP index 7a0a820..e566dfa 160000 --- a/Tweaks/YouPiP +++ b/Tweaks/YouPiP @@ -1 +1 @@ -Subproject commit 7a0a820109f6783f4614869ac72d8cd9962477c4 +Subproject commit e566dfa92bf0b1afe51deea47c355f23329f882a diff --git a/Tweaks/YouTubeHeader b/Tweaks/YouTubeHeader index 71372d2..59b5288 160000 --- a/Tweaks/YouTubeHeader +++ b/Tweaks/YouTubeHeader @@ -1 +1 @@ -Subproject commit 71372d2c4861c6f3c97d3dab511fe50e8b12f6ae +Subproject commit 59b5288d1579613bcaa7ba93605bfc1fa1fed4f0 From 34e34a4fefe93f17f409110ae51f9eaaade97c6d Mon Sep 17 00:00:00 2001 From: BandarHelal <31299470+BandarHL@users.noreply.github.com> Date: Sat, 7 May 2022 20:04:36 +0300 Subject: [PATCH 2/2] Move uYouPlus settings to new setting category --- Settings.xm | 213 ++++++++++++++++++++++++++++------------------------ 1 file changed, 114 insertions(+), 99 deletions(-) diff --git a/Settings.xm b/Settings.xm index e0aa2da..5ee7654 100644 --- a/Settings.xm +++ b/Settings.xm @@ -1,4 +1,12 @@ +#import "Tweaks/YouTubeHeader/YTSettingsViewController.h" #import "Tweaks/YouTubeHeader/YTSettingsSectionItem.h" +#import "Tweaks/YouTubeHeader/YTSettingsSectionItemManager.h" + +@interface YTSettingsSectionItemManager (YouPiP) +- (void)updateuYouPlusSectionWithEntry:(id)entry; +@end + +static const NSInteger uYouPlusSection = 500; extern BOOL hideHUD(); extern BOOL oled(); @@ -11,105 +19,112 @@ extern BOOL hideAutoplaySwitch(); extern BOOL castConfirm(); // Settings -%hook YTSettingsViewController -- (void)setSectionItems:(NSMutableArray *)sectionItems forCategory:(NSInteger)category title:(NSString *)title titleDescription:(NSString *)titleDescription headerHidden:(BOOL)headerHidden { - if (category == 1) { - NSUInteger statsForNerdsIndex = [sectionItems indexOfObjectPassingTest:^BOOL (YTSettingsSectionItem *item, NSUInteger idx, BOOL *stop) { - return item.settingItemId == 265; - }]; - if (statsForNerdsIndex != NSNotFound) { - // - YTSettingsSectionItem *castConfirm = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Confirm alert before casting (YTCastConfirm)" titleDescription:@"Show a confirm alert before casting to prevent accidentally hijacking TV."]; - castConfirm.hasSwitch = YES; - castConfirm.switchVisible = YES; - castConfirm.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"castConfirm_enabled"]; - castConfirm.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"castConfirm_enabled"]; - return YES; - }; - [sectionItems insertObject:castConfirm atIndex:statsForNerdsIndex + 1]; - // - YTSettingsSectionItem *hoverCardItem = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Show End screens hover cards (YTNoHoverCards)" titleDescription:@"Allows creator End screens (thumbnails) to appear at the end of videos."]; - hoverCardItem.hasSwitch = YES; - hoverCardItem.switchVisible = YES; - hoverCardItem.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hover_cards_enabled"]; - hoverCardItem.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hover_cards_enabled"]; - return YES; - }; - [sectionItems insertObject:hoverCardItem atIndex:statsForNerdsIndex + 1]; - // - YTSettingsSectionItem *bigYTMiniPlayer = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"New miniplayer bar style (BigYTMiniPlayer)" titleDescription:@"App restart is required."]; - bigYTMiniPlayer.hasSwitch = YES; - bigYTMiniPlayer.switchVisible = YES; - bigYTMiniPlayer.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"bigYTMiniPlayer_enabled"]; - bigYTMiniPlayer.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"bigYTMiniPlayer_enabled"]; - return YES; - }; - [sectionItems insertObject:bigYTMiniPlayer atIndex:statsForNerdsIndex + 2]; - // - YTSettingsSectionItem *reExplore = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Replace Shorts tab with Explore tab (YTReExplore)" titleDescription:@"App restart is required."]; - reExplore.hasSwitch = YES; - reExplore.switchVisible = YES; - reExplore.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"reExplore_enabled"]; - reExplore.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"reExplore_enabled"]; - return YES; - }; - [sectionItems insertObject:reExplore atIndex:statsForNerdsIndex + 2]; - // - YTSettingsSectionItem *hideCC = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide Subtitles button" titleDescription:@"Hide the Subtitles button in video controls overlay. "]; - hideCC.hasSwitch = YES; - hideCC.switchVisible = YES; - hideCC.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideCC_enabled"]; - hideCC.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideCC_enabled"]; - return YES; - }; - [sectionItems insertObject:hideCC atIndex:statsForNerdsIndex + 1]; - // - YTSettingsSectionItem *hideAutoplaySwitch = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide Autoplay switch" titleDescription:@"Hide the Autoplay switch button in video controls overlay."]; - hideAutoplaySwitch.hasSwitch = YES; - hideAutoplaySwitch.switchVisible = YES; - hideAutoplaySwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideAutoplaySwitch_enabled"]; - hideAutoplaySwitch.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideAutoplaySwitch_enabled"]; - return YES; - }; - [sectionItems insertObject:hideAutoplaySwitch atIndex:statsForNerdsIndex + 1]; - // - YTSettingsSectionItem *autoFUll = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Auto Full Screen (YTAutoFullScreen)" titleDescription:@"Autoplay videos at full screen."]; - autoFUll.hasSwitch = YES; - autoFUll.switchVisible = YES; - autoFUll.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"autofull_enabled"]; - autoFUll.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"autofull_enabled"]; - return YES; - }; - [sectionItems insertObject:autoFUll atIndex:statsForNerdsIndex + 3]; - // - YTSettingsSectionItem *hideHUD = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide HUD Messages" titleDescription:@"Example: CC is turned on/off, Video loop is on,..."]; - hideHUD.hasSwitch = YES; - hideHUD.switchVisible = YES; - hideHUD.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideHUD_enabled"]; - hideHUD.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideHUD_enabled"]; - return YES; - }; - [sectionItems insertObject:hideHUD atIndex:statsForNerdsIndex + 1]; - // - YTSettingsSectionItem *Oleditem = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"OLED Dark mode (Experimental)" titleDescription:@"WARNING: OLED Dark mode only works when YouTube is in Dark theme. App restart is required (In case OLED dark mode doesn't work: just switch between Light/Dark theme, then restart the app)."]; - Oleditem.hasSwitch = YES; - Oleditem.switchVisible = YES; - Oleditem.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"oled_enabled"]; - Oleditem.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { - [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"oled_enabled"]; - return YES; - }; - [sectionItems insertObject:Oleditem atIndex:statsForNerdsIndex + 1]; - } +%hook YTAppSettingsPresentationData ++ (NSArray *)settingsCategoryOrder { + NSArray *order = %orig; + NSMutableArray *mutableOrder = [order mutableCopy]; + NSUInteger insertIndex = [order indexOfObject:@(1)]; + if (insertIndex != NSNotFound) + [mutableOrder insertObject:@(uYouPlusSection) atIndex:insertIndex + 1]; + return mutableOrder; +} + +%end + +%hook YTSettingsSectionItemManager +%new - (void)updateuYouPlusSectionWithEntry:(id)entry { + YTSettingsViewController *delegate = [self valueForKey:@"_dataDelegate"]; + + YTSettingsSectionItem *castConfirm = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Confirm alert before casting (YTCastConfirm)" titleDescription:@"Show a confirm alert before casting to prevent accidentally hijacking TV."]; + castConfirm.hasSwitch = YES; + castConfirm.switchVisible = YES; + castConfirm.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"castConfirm_enabled"]; + castConfirm.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"castConfirm_enabled"]; + return YES; + }; + + YTSettingsSectionItem *hoverCardItem = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Show End screens hover cards (YTNoHoverCards)" titleDescription:@"Allows creator End screens (thumbnails) to appear at the end of videos."]; + hoverCardItem.hasSwitch = YES; + hoverCardItem.switchVisible = YES; + hoverCardItem.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hover_cards_enabled"]; + hoverCardItem.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hover_cards_enabled"]; + return YES; + }; + + YTSettingsSectionItem *bigYTMiniPlayer = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"New miniplayer bar style (BigYTMiniPlayer)" titleDescription:@"App restart is required."]; + bigYTMiniPlayer.hasSwitch = YES; + bigYTMiniPlayer.switchVisible = YES; + bigYTMiniPlayer.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"bigYTMiniPlayer_enabled"]; + bigYTMiniPlayer.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"bigYTMiniPlayer_enabled"]; + return YES; + }; + + YTSettingsSectionItem *reExplore = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Replace Shorts tab with Explore tab (YTReExplore)" titleDescription:@"App restart is required."]; + reExplore.hasSwitch = YES; + reExplore.switchVisible = YES; + reExplore.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"reExplore_enabled"]; + reExplore.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"reExplore_enabled"]; + return YES; + }; + + YTSettingsSectionItem *hideCC = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide Subtitles button" titleDescription:@"Hide the Subtitles button in video controls overlay. "]; + hideCC.hasSwitch = YES; + hideCC.switchVisible = YES; + hideCC.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideCC_enabled"]; + hideCC.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideCC_enabled"]; + return YES; + }; + + YTSettingsSectionItem *hideAutoplaySwitch = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide Autoplay switch" titleDescription:@"Hide the Autoplay switch button in video controls overlay."]; + hideAutoplaySwitch.hasSwitch = YES; + hideAutoplaySwitch.switchVisible = YES; + hideAutoplaySwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideAutoplaySwitch_enabled"]; + hideAutoplaySwitch.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideAutoplaySwitch_enabled"]; + return YES; + }; + + YTSettingsSectionItem *autoFUll = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Auto Full Screen (YTAutoFullScreen)" titleDescription:@"Autoplay videos at full screen."]; + autoFUll.hasSwitch = YES; + autoFUll.switchVisible = YES; + autoFUll.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"autofull_enabled"]; + autoFUll.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"autofull_enabled"]; + return YES; + }; + + YTSettingsSectionItem *hideHUD = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"Hide HUD Messages" titleDescription:@"Example: CC is turned on/off, Video loop is on,..."]; + hideHUD.hasSwitch = YES; + hideHUD.switchVisible = YES; + hideHUD.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"hideHUD_enabled"]; + hideHUD.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"hideHUD_enabled"]; + return YES; + }; + + YTSettingsSectionItem *Oleditem = [[%c(YTSettingsSectionItem) alloc] initWithTitle:@"OLED Dark mode (Experimental)" titleDescription:@"WARNING: OLED Dark mode only works when YouTube is in Dark theme. App restart is required (In case OLED dark mode doesn't work: just switch between Light/Dark theme, then restart the app)."]; + Oleditem.hasSwitch = YES; + Oleditem.switchVisible = YES; + Oleditem.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"oled_enabled"]; + Oleditem.switchBlock = ^BOOL (YTSettingsCell *cell, BOOL enabled) { + [[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"oled_enabled"]; + return YES; + }; + + NSMutableArray *sectionItems = [NSMutableArray arrayWithArray:@[castConfirm, hoverCardItem, bigYTMiniPlayer, reExplore, hideCC, hideAutoplaySwitch, autoFUll, hideHUD, Oleditem]]; + [delegate setSectionItems:sectionItems forCategory:uYouPlusSection title:@"uYouPlus" titleDescription:nil headerHidden:NO]; +} + +- (void)updateSectionForCategory:(NSUInteger)category withEntry:(id)entry { + if (category == uYouPlusSection) { + [self updateuYouPlusSectionWithEntry:entry]; + return; } %orig; - } +} %end \ No newline at end of file