From 7c39d6659d4f4cdbd4cff7b94f8d4d8fa3158544 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:20:50 -0700 Subject: [PATCH] Add link to uYou page --- Sources/uYouPlus.h | 48 +++++++++++++++++++++++---------------- Sources/uYouPlus.xm | 41 ++++++++++++++++++++++++++++++++- Sources/uYouPlusPatches.h | 2 +- 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/Sources/uYouPlus.h b/Sources/uYouPlus.h index 0cd083d..9fd7edc 100644 --- a/Sources/uYouPlus.h +++ b/Sources/uYouPlus.h @@ -33,6 +33,7 @@ #import #import #import +#import // Hide buttons under the video player by @PoomSmart #import @@ -72,40 +73,49 @@ // Hide Premium Promo in You tab - @bhackel @interface YTIIconThumbnailRenderer : GPBMessage - @property (nonatomic, strong) YTIIcon *icon; - - (bool)hasIcon; +@property (nonatomic, strong) YTIIcon *icon; +- (bool)hasIcon; @end @interface YTICompactListItemThumbnailSupportedRenderers : GPBMessage - @property (nonatomic, strong) YTIIconThumbnailRenderer *iconThumbnailRenderer; - - (bool)hasIconThumbnailRenderer; +@property (nonatomic, strong) YTIIconThumbnailRenderer *iconThumbnailRenderer; +- (bool)hasIconThumbnailRenderer; @end @interface YTICompactListItemRenderer : GPBMessage - @property (nonatomic, strong) YTICompactListItemThumbnailSupportedRenderers *thumbnail; - @property (nonatomic, strong) YTIFormattedString *title; - - (bool)hasThumbnail; - - (bool)hasTitle; +@property (nonatomic, strong) YTICompactListItemThumbnailSupportedRenderers *thumbnail; +@property (nonatomic, strong) YTIFormattedString *title; +- (bool)hasThumbnail; +- (bool)hasTitle; @end @interface YTIIcon (uYouEnhanced) - - (bool)hasIconType; +- (bool)hasIconType; @end @interface YTICompactLinkRenderer : GPBMessage - @property (nonatomic, strong) YTIIcon *icon; - @property (nonatomic, strong) YTIFormattedString *title; - @property (nonatomic, strong) YTICompactListItemThumbnailSupportedRenderers *thumbnail; - - (bool)hasIcon; - - (bool)hasThumbnail; +@property (nonatomic, strong) YTIIcon *icon; +@property (nonatomic, strong) YTIFormattedString *title; +@property (nonatomic, strong) YTICompactListItemThumbnailSupportedRenderers *thumbnail; +- (bool)hasIcon; +- (bool)hasThumbnail; @end @interface YTIItemSectionSupportedRenderers (uYouEnhanced) - @property(readonly, nonatomic) YTICompactLinkRenderer *compactLinkRenderer; - @property(readonly, nonatomic) YTICompactListItemRenderer *compactListItemRenderer; - - (bool)hasCompactLinkRenderer; - - (bool)hasCompactListItemRenderer; +@property(readonly, nonatomic) YTICompactLinkRenderer *compactLinkRenderer; +@property(readonly, nonatomic) YTICompactListItemRenderer *compactListItemRenderer; +- (bool)hasCompactLinkRenderer; +- (bool)hasCompactListItemRenderer; @end @interface YTAppCollectionViewController : YTInnerTubeCollectionViewController - (void)uYouEnhancedFakePremiumModel:(YTISectionListRenderer *)model; @end @interface YTInnerTubeCollectionViewController (uYouEnhanced) - @property(readonly, nonatomic) YTISectionListRenderer *model; +@property(readonly, nonatomic) YTISectionListRenderer *model; +@end +@interface YTLinkCell : UICollectionViewCell +@end +@interface YTCompactListItemCellController : YTCellController +@property(nonatomic, weak, readwrite) id entry; +@end +@interface GLViewPagerViewController : UIViewController +@end +@interface DownloadsPagerVC : GLViewPagerViewController @end // uYouPlus diff --git a/Sources/uYouPlus.xm b/Sources/uYouPlus.xm index 9d67e34..15a533b 100644 --- a/Sources/uYouPlus.xm +++ b/Sources/uYouPlus.xm @@ -359,7 +359,6 @@ BOOL isAd(YTIElementRenderer *self) { if (yourVideosCellIndex != -1 && subContentsArray[yourVideosCellIndex].accessibilityLabel == nil) { // Create the fake Downloads page by copying the Your Videos page and modifying it // Note that this must be done outside the loop to avoid a runtime exception - // TODO Link this to the uYou downloads page YTIItemSectionSupportedRenderers *newItemSectionSupportedRenderers = [subContentsArray[yourVideosCellIndex] copy]; ((YTIStringRun *)(newItemSectionSupportedRenderers.compactListItemRenderer.title.runsArray.firstObject)).text = LOC(@"FAKE_DOWNLOADS"); newItemSectionSupportedRenderers.compactListItemRenderer.thumbnail.iconThumbnailRenderer.icon.iconType = 147; @@ -368,6 +367,8 @@ BOOL isAd(YTIElementRenderer *self) { // Inject a note to not modify this again subContentsArray[yourVideosCellIndex].accessibilityLabel = @"uYouEnhanced Modified"; yourVideosCellIndex = -1; + // Insert accessibility info into the YTLinkCell so that it can be hooked later + newItemSectionSupportedRenderers.compactListItemRenderer.title.accessibility.accessibilityData.label = @"uYouEnhanced Fake Downloads"; } } } @@ -382,6 +383,44 @@ BOOL isAd(YTIElementRenderer *self) { %orig; } %end +// Change the destination of the fake Downloads cell +%hook YTCompactListItemCellController +- (void)didSelectItem { + NSLog(@"bhackel: _handleMenuGesture"); + id entry = self.entry; + // Avoid modifying the wrong things + if (![entry isKindOfClass:NSClassFromString(@"YTICompactListItemRenderer")]) { + %orig; + return; + } + YTICompactListItemRenderer *compactListItemRenderer = (YTICompactListItemRenderer *)entry; + // Check title for accessibility label that was stored + if ([compactListItemRenderer.title.accessibility.accessibilityData.label isEqualToString:@"uYouEnhanced Fake Downloads"]) { + NSLog(@"bhackel: uYouEnhanced Fake Downloads"); + // Chatgpt generated code to show DownloadsPagerVC, which is the uYou page + // Instantiate your custom DownloadsPagerVC + // Avoid linker stuff + Class downloadsPagerVCClass = objc_getClass("DownloadsPagerVC"); + if (downloadsPagerVCClass) { + id downloadsPagerVCid = [[downloadsPagerVCClass alloc] init]; + // Now you can use `downloadsPagerVC` as needed + } + DownloadsPagerVC *downloadsPagerVC = (DownloadsPagerVC *)downloadsPagerVCid; + // Assuming you need navigation controller to push + UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; + UINavigationController *navigationController = (UINavigationController *)rootViewController; + if ([navigationController isKindOfClass:[UINavigationController class]]) { + [navigationController pushViewController:downloadsPagerVC animated:YES]; + } else { + // If not in a navigation controller context, present modally + [rootViewController presentViewController:downloadsPagerVC animated:YES completion:nil]; + } + } else { + NSLog(@"bhackel: Not uYouEnhanced Fake Downloads"); + %orig; + } +} +%end %end diff --git a/Sources/uYouPlusPatches.h b/Sources/uYouPlusPatches.h index a9231b6..9bf3238 100644 --- a/Sources/uYouPlusPatches.h +++ b/Sources/uYouPlusPatches.h @@ -32,7 +32,7 @@ // @end // Fix uYou's appearance not updating if the app is backgrounded -@interface DownloadsPagerVC : UIViewController +@interface DownloadsPagerVC (uYouEnhancedPatches) - (NSArray *)viewControllers; - (void)updatePageStyles; @end