From ec7eec660b833337866d823de9a5c657ffb69a0a Mon Sep 17 00:00:00 2001 From: qnblackcat Date: Sat, 21 May 2022 12:51:11 +0700 Subject: [PATCH] fix YTCastconfirm, code clean up --- uYouPlus.xm | 68 ++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/uYouPlus.xm b/uYouPlus.xm index 3af1e30..41f25a4 100644 --- a/uYouPlus.xm +++ b/uYouPlus.xm @@ -112,40 +112,41 @@ BOOL ytMiniPlayer() { %end //YTCastConfirm: https://github.com/JamieBerghmans/YTCastConfirm -%group gYTCastconfirm %hook MDXPlaybackRouteButtonController - (void)didPressButton:(id)arg1 { - UIAlertController* alertController = [%c(UIAlertController) alertControllerWithTitle:@"Casting" - message:@"Are you sure you want to start casting?" - preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction* defaultAction = [%c(UIAlertAction) actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { - %orig; - }]; + if (castConfirm()) { + UIAlertController* alertController = [%c(UIAlertController) alertControllerWithTitle:@"Casting" + message:@"Are you sure you want to start casting?" + preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* defaultAction = [%c(UIAlertAction) actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + %orig; + }]; - UIAlertAction* noButton = [%c(UIAlertAction) - actionWithTitle:@"Cancel" - style:UIAlertActionStyleDefault - handler: ^(UIAlertAction * action) { return; } - ]; + UIAlertAction* noButton = [%c(UIAlertAction) + actionWithTitle:@"Cancel" + style:UIAlertActionStyleDefault + handler: ^(UIAlertAction * action) { + return; + }]; - [alertController addAction:defaultAction]; - [alertController addAction:noButton]; + [alertController addAction:defaultAction]; + [alertController addAction:noButton]; + + id rootViewController = [%c(UIApplication) sharedApplication].delegate.window.rootViewController; + if ([rootViewController isKindOfClass:[%c(UINavigationController) class]]) { + rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject; + } + if ([rootViewController isKindOfClass:[%c(UITabBarController) class]]) { + rootViewController = ((UITabBarController *)rootViewController).selectedViewController; + } + if ([rootViewController presentedViewController] != nil) { + rootViewController = [rootViewController presentedViewController]; + } + [rootViewController presentViewController:alertController animated:YES completion:nil]; + } else { return %orig; } - id rootViewController = [%c(UIApplication) sharedApplication].delegate.window.rootViewController; - if ([rootViewController isKindOfClass:[%c(UINavigationController) class]]) { - rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject; - } - if ([rootViewController isKindOfClass:[%c(UITabBarController) class]]) { - rootViewController = ((UITabBarController *)rootViewController).selectedViewController; - } - if ([rootViewController presentedViewController] != nil) { - rootViewController = [rootViewController presentedViewController]; - } - [rootViewController presentViewController:alertController animated:YES completion:nil]; - return %orig; } %end -%end // Workaround for https://github.com/MiRO92/uYou-for-YouTube/issues/12 %hook YTAdsInnerTubeContextDecorator @@ -317,9 +318,7 @@ UIColor* oledColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { %orig; self.tableView.backgroundColor = oledColor; - } else { - return %orig(); - } + } else { return %orig; } } %end @@ -417,9 +416,7 @@ UIColor* oledColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; %hook YTCollectionSeparatorView - (void)didMoveToWindow { if (isDarkMode()) {} - else { - return %orig(); - } + else { return %orig; } } %end @@ -443,8 +440,8 @@ UIColor* oledColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; %hook ASWAppSwitcherCollectionViewCell - (void)didMoveToWindow { if (isDarkMode()) { - %orig; self.subviews[1].backgroundColor = oledColor; + %orig; } } %end @@ -568,7 +565,4 @@ static void replaceTab(YTIGuideResponse *response) { if (bigYTMiniPlayer() && (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPad)) { %init(Main); } - if (castConfirm()) { - %init(gYTCastconfirm); - } }