forked from MiRO92/uYou-for-YouTube
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
uYouPlusPatches.xm
211 lines (188 loc) · 6.96 KB
/
uYouPlusPatches.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#import "uYouPlusPatches.h"
# pragma mark - YouTube patches
// Fix Google Sign in by @PoomSmart and @level3tjg (qnblackcat/uYouPlus#684)
%hook NSBundle
- (NSDictionary *)infoDictionary {
NSMutableDictionary *info = %orig.mutableCopy;
if ([self isEqual:NSBundle.mainBundle])
info[@"CFBundleIdentifier"] = @"com.google.ios.youtube";
return info;
}
%end
%hook YTHotConfig
- (BOOL)disableAfmaIdfaCollection { return NO; }
%end
// https://github.com/PoomSmart/YouTube-X/blob/1e62b68e9027fcb849a75f54a402a530385f2a51/Tweak.x#L27
// %hook YTAdsInnerTubeContextDecorator
// - (void)decorateContext:(id)context {}
// %end
# pragma mark - uYou patches
// Workaround for qnblackcat/uYouPlus#10
%hook UIViewController
- (UITraitCollection *)traitCollection {
@try {
return %orig;
} @catch(NSException *e) {
return [UITraitCollection currentTraitCollection];
}
}
%end
// Prevent uYou player bar from showing when not playing downloaded media
%hook PlayerManager
- (void)pause {
if (isnan([self progress]))
return;
%orig;
}
%end
// Workaround for issue #54
%hook YTMainAppVideoPlayerOverlayViewController
- (void)updateRelatedVideos {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"relatedVideosAtTheEndOfYTVideos"] == NO) {}
else { return %orig; }
}
%end
// iOS 16 uYou crash fix - @level3tjg: https://github.com/qnblackcat/uYouPlus/pull/224
// %group iOS16
// %hook OBPrivacyLinkButton
// %new
// - (instancetype)initWithCaption:(NSString *)caption
// buttonText:(NSString *)buttonText
// image:(UIImage *)image
// imageSize:(CGSize)imageSize
// useLargeIcon:(BOOL)useLargeIcon {
// return [self initWithCaption:caption
// buttonText:buttonText
// image:image
// imageSize:imageSize
// useLargeIcon:useLargeIcon
// displayLanguage:[NSLocale currentLocale].languageCode];
// }
// %end
// %end
// Fix uYou playback speed crashes YT v18.49.3+, see https://github.com/iCrazeiOS/uYouCrashFix
// %hook YTPlayerViewController
// %new
// -(float)currentPlaybackRateForVarispeedSwitchController:(id)arg1 {
// return [[self activeVideo] playbackRate];
// }
// %new
// -(void)varispeedSwitchController:(id)arg1 didSelectRate:(float)arg2 {
// [[self activeVideo] setPlaybackRate:arg2];
// }
// %end
// Fix streched artwork in uYou's player view - https://github.com/MiRO92/uYou-for-YouTube/issues/287
%hook ArtworkImageView
- (id)imageView {
UIImageView * imageView = %orig;
imageView.contentMode = UIViewContentModeScaleAspectFit;
// Make artwork a bit bigger
UIView *artworkImageView = imageView.superview;
if (artworkImageView != nil && !artworkImageView.translatesAutoresizingMaskIntoConstraints) {
[artworkImageView.leftAnchor constraintEqualToAnchor:artworkImageView.superview.leftAnchor constant:16].active = YES;
[artworkImageView.rightAnchor constraintEqualToAnchor:artworkImageView.superview.rightAnchor constant:-16].active = YES;
}
return imageView;
}
%end
// Fix navigation bar showing a lighter grey with default dark mode - https://github.com/therealFoxster/uYouPlus/commit/8db8197
%hook YTCommonColorPalette
- (UIColor *)brandBackgroundSolid {
return self.pageStyle == 1 ? [UIColor colorWithRed:0.05882352941176471 green:0.05882352941176471 blue:0.05882352941176471 alpha:1.0] : %orig;
}
%end
// Fix uYou's appearance not updating if the app is backgrounded
static DownloadsPagerVC *downloadsPagerVC;
static NSUInteger selectedTabIndex;
%hook DownloadsPagerVC
- (id)init {
downloadsPagerVC = %orig;
return downloadsPagerVC;
}
- (void)viewPager:(id)viewPager didChangeTabToIndex:(NSUInteger)arg1 fromTabIndex:(NSUInteger)arg2 {
%orig; selectedTabIndex = arg1;
}
%end
static void refreshUYouAppearance() {
if (!downloadsPagerVC) return;
// View pager
[downloadsPagerVC updatePageStyles];
// Views
for (UIViewController *vc in [downloadsPagerVC viewControllers]) {
if ([vc isKindOfClass:%c(DownloadingVC)]) {
// `Downloading` view
[(DownloadingVC *)vc updatePageStyles];
for (UITableViewCell *cell in [(DownloadingVC *)vc tableView].visibleCells)
if ([cell isKindOfClass:%c(DownloadingCell)])
[(DownloadingCell *)cell updatePageStyles];
}
else if ([vc isKindOfClass:%c(DownloadedVC)]) {
// `All`, `Audios`, `Videos`, `Shorts` views
[(DownloadedVC *)vc updatePageStyles];
for (UITableViewCell *cell in [(DownloadedVC *)vc tableView].visibleCells)
if ([cell isKindOfClass:%c(DownloadedCell)])
[(DownloadedCell *)cell updatePageStyles];
}
}
// View pager tabs
for (UIView *subview in [downloadsPagerVC view].subviews) {
if ([subview isKindOfClass:[UIScrollView class]]) {
UIScrollView *tabs = (UIScrollView *)subview;
NSUInteger i = 0;
for (UIView *item in tabs.subviews) {
if ([item isKindOfClass:[UILabel class]]) {
// Tab label
UILabel *tabLabel = (UILabel *)item;
if (i == selectedTabIndex) {} // Selected tab should be excluded
else [tabLabel setTextColor:[UILabel _defaultColor]];
i++;
}
}
}
}
}
%hook UIViewController
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
%orig;
dispatch_async(dispatch_get_main_queue(), ^{
refreshUYouAppearance();
});
}
%end
// Prevent uYou's playback from colliding with YouTube's
%hook PlayerVC
- (void)close {
%orig;
[[%c(PlayerManager) sharedInstance] setSource:nil];
}
%end
%hook HAMPlayerInternal
- (void)play {
dispatch_async(dispatch_get_main_queue(), ^{
[[%c(PlayerManager) sharedInstance] pause];
});
%orig;
}
%end
// Temporarily disable uYou's bouncy animation cause it's buggy
%hook SSBouncyButton
- (void)beginShrinkAnimation {}
- (void)beginEnlargeAnimation {}
%end
%ctor {
%init;
// if (@available(iOS 16, *)) {
// %init(iOS16);
// }
// Disable broken options
// Disable uYou's auto updates
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"automaticallyCheckForUpdates"];
// Disable uYou's welcome screen (fix #1147)
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showedWelcomeVC"];
// Disable uYou's disable age restriction
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"disableAgeRestriction"];
// Disable uYou's playback speed controls (prevent crash on video playback https://github.com/therealFoxster/uYouPlus/issues/2#issuecomment-1894912963)
// [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showPlaybackRate"];
// Disable uYou's adblock
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"removeYouTubeAds"];
}