From df0be8c66eb36872d2306d12ce51e7d355b5409a Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Sun, 1 Sep 2024 19:31:28 -0700 Subject: [PATCH] Change hiding method --- YTLitePlus.xm | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/YTLitePlus.xm b/YTLitePlus.xm index 766395a..517fdd4 100644 --- a/YTLitePlus.xm +++ b/YTLitePlus.xm @@ -171,21 +171,53 @@ BOOL isSelf() { %end // Disable YouTube Plus incompatibility warning popup - @bhackel -%hook HelperVC +%hook UIView -- (void)viewWillAppear:(BOOL)animated { - %orig; // Call the original implementation +- (void)willMoveToWindow:(UIWindow *)newWindow { + UIResponder *responder = self; + while (responder) { + responder = [responder nextResponder]; + if ([responder isKindOfClass:NSClassFromString(@"HelperVC")]) { + // View belongs to HelperVC, now proceed with getting the UIButton - // // Hide the view before it appears - // self.view.hidden = YES; + if ([self.subviews count] > 4 && [[self.subviews objectAtIndex:4] isKindOfClass:[UIButton class]]) { + UIButton *button = [self.subviews objectAtIndex:4]; - // // Optionally, you can remove the view from the superview to ensure it's gone - // [self.view removeFromSuperview]; + // Access the _targetActions ivar using KVC (Key-Value Coding) + NSArray *targetActions = [button valueForKey:@"_targetActions"]; + + if ([targetActions count] > 0) { + id controlTargetAction = [targetActions objectAtIndex:0]; + + // Use KVC to get the _actionHandler (which is of type UIAction) + UIAction *actionHandler = [controlTargetAction valueForKey:@"_actionHandler"]; + + if (actionHandler && [actionHandler isKindOfClass:[UIAction class]]) { + // Access the handler property of UIAction + void (^handlerBlock)(void) = [actionHandler valueForKey:@"handler"]; + + // Invoke the handler block + if (handlerBlock) { + handlerBlock(); // Call the block + } + } + } + } + + // Prevent the view from being added to the window + [self removeFromSuperview]; + return; // Exit early to prevent further processing + } + } + + %orig(newWindow); // Call the original method if the view doesn't belong to HelperVC } %end + + // A/B flags %hook YTColdConfig - (BOOL)respectDeviceCaptionSetting { return NO; } // YouRememberCaption: https://poomsmart.github.io/repo/depictions/youremembercaption.html