forked from PoomSmart/YouPiP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.x
177 lines (153 loc) · 7.17 KB
/
Settings.x
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
// clang-format off
#import "../PSHeader/iOSVersions.h"
#import "Header.h"
#import "../YouTubeHeader/YTAlertView.h"
#import "../YouTubeHeader/YTHotConfig.h"
#import "../YouTubeHeader/YTSettingsViewController.h"
#import "../YouTubeHeader/YTSettingsSectionItem.h"
#import "../YouTubeHeader/YTSettingsSectionItemManager.h"
#import "../YouTubeHeader/YTAppSettingsSectionItemActionController.h"
#define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil]
#define FEATURE_CUTOFF_VERSION @"16.46.5"
@interface YTSettingsSectionItemManager (YouPiP)
- (void)updateYouPiPSectionWithEntry:(id)entry;
@end
static const NSInteger YouPiPSection = 200;
extern BOOL UsePiPButton();
extern BOOL UseTabBarPiPButton();
extern BOOL NoMiniPlayerPiP();
extern BOOL LegacyPiP();
extern BOOL NonBackgroundable();
extern BOOL FakeVersion();
extern NSBundle *YouPiPBundle();
NSString *currentVersion;
static NSString *YouPiPWarnVersionKey = @"YouPiPWarnVersionKey";
%hook YTAppSettingsPresentationData
+ (NSArray *)settingsCategoryOrder {
NSArray *order = %orig;
NSMutableArray *mutableOrder = [order mutableCopy];
NSUInteger insertIndex = [order indexOfObject:@(1)];
if (insertIndex != NSNotFound)
[mutableOrder insertObject:@(YouPiPSection) atIndex:insertIndex + 1]; // Add YouPiP under General (ID: 1) section
return mutableOrder;
}
%end
%hook YTSettingsSectionItemManager
%new(v@:@)
- (void)updateYouPiPSectionWithEntry:(id)entry {
YTSettingsViewController *delegate = [self valueForKey:@"_dataDelegate"];
NSMutableArray *sectionItems = [NSMutableArray array];
NSBundle *tweakBundle = YouPiPBundle();
YTSettingsSectionItem *activationMethod = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"USE_PIP_BUTTON")
titleDescription:LOC(@"USE_PIP_BUTTON_DESC")
accessibilityIdentifier:nil
switchOn:UsePiPButton()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:PiPActivationMethodKey];
return YES;
}
settingItemId:0];
[sectionItems addObject:activationMethod];
YTSettingsSectionItem *activationMethod2 = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"USE_TAB_BAR_PIP_BUTTON")
titleDescription:LOC(@"USE_TAB_BAR_PIP_BUTTON_DESC")
accessibilityIdentifier:nil
switchOn:UseTabBarPiPButton()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:PiPActivationMethod2Key];
return YES;
}
settingItemId:0];
[sectionItems addObject:activationMethod2];
YTSettingsSectionItem *miniPlayer = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"DISABLE_PIP_MINI_PLAYER")
titleDescription:LOC(@"DISABLE_PIP_MINI_PLAYER_DESC")
accessibilityIdentifier:nil
switchOn:NoMiniPlayerPiP()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:NoMiniPlayerPiPKey];
return YES;
}
settingItemId:0];
[sectionItems addObject:miniPlayer];
if (IS_IOS_OR_NEWER(iOS_13_0) && [currentVersion compare:@"15.33.4" options:NSNumericSearch] == NSOrderedDescending) {
YTSettingsSectionItem *legacyPiP = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"LEGACY_PIP")
titleDescription:LOC(@"LEGACY_PIP_DESC")
accessibilityIdentifier:nil
switchOn:LegacyPiP()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:CompatibilityModeKey];
return YES;
}
settingItemId:0];
[sectionItems addObject:legacyPiP];
}
YTAppSettingsSectionItemActionController *sectionItemActionController = [delegate valueForKey:@"_sectionItemActionController"];
YTSettingsSectionItemManager *sectionItemManager = [sectionItemActionController valueForKey:@"_sectionItemManager"];
YTHotConfig *hotConfig;
@try {
hotConfig = [sectionItemManager valueForKey:@"_hotConfig"];
} @catch (id ex) {
hotConfig = [sectionItemManager.gimme instanceForType:%c(YTHotConfig)];
}
YTIIosMediaHotConfig *iosMediaHotConfig = hotConfig.hotConfigGroup.mediaHotConfig.iosMediaHotConfig;
if ([iosMediaHotConfig respondsToSelector:@selector(setEnablePipForNonBackgroundableContent:)]) {
YTSettingsSectionItem *nonBackgroundable = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"NON_BACKGROUNDABLE_PIP")
titleDescription:LOC(@"NON_BACKGROUNDABLE_PIP_DESC")
accessibilityIdentifier:nil
switchOn:NonBackgroundable()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:NonBackgroundableKey];
return YES;
}
settingItemId:0];
[sectionItems addObject:nonBackgroundable];
}
if ([currentVersion compare:FEATURE_CUTOFF_VERSION options:NSNumericSearch] == NSOrderedDescending) {
YTSettingsSectionItem *fakeVersion = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"FAKE_YT_VERSION")
titleDescription:[NSString stringWithFormat:LOC(@"FAKE_YT_VERSION_DESC"), FEATURE_CUTOFF_VERSION]
accessibilityIdentifier:nil
switchOn:FakeVersion()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:FakeVersionKey];
return YES;
}
settingItemId:0];
[sectionItems addObject:fakeVersion];
}
[delegate setSectionItems:sectionItems forCategory:YouPiPSection title:TweakName titleDescription:nil headerHidden:NO];
}
- (void)updateSectionForCategory:(NSUInteger)category withEntry:(id)entry {
if (category == YouPiPSection) {
[self updateYouPiPSectionWithEntry:entry];
return;
}
%orig;
}
%end
BOOL loadWatchNextRequest = NO;
%hook YTVersionUtils
+ (NSString *)appVersion {
return FakeVersion() && loadWatchNextRequest ? FEATURE_CUTOFF_VERSION : %orig;
}
%end
%hook YTWatchNextViewController
- (void)loadWatchNextRequest {
loadWatchNextRequest = YES;
%orig;
loadWatchNextRequest = NO;
}
%end
%ctor {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
currentVersion = [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey];
if (![defaults boolForKey:YouPiPWarnVersionKey] && [currentVersion compare:@(OS_STRINGIFY(MIN_YOUTUBE_VERSION)) options:NSNumericSearch] != NSOrderedDescending) {
[defaults setBool:YES forKey:YouPiPWarnVersionKey];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSBundle *tweakBundle = YouPiPBundle();
YTAlertView *alertView = [%c(YTAlertView) infoDialog];
alertView.title = TweakName;
alertView.subtitle = [NSString stringWithFormat:LOC(@"UNSUPPORTED_YT_VERSION"), currentVersion, @(OS_STRINGIFY(MIN_YOUTUBE_VERSION))];
[alertView show];
});
}
%init;
}