forked from PoomSmart/YTUHD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.x
84 lines (73 loc) · 3.44 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
#import "Header.h"
#import <rootless.h>
#import <VideoToolbox/VideoToolbox.h>
#import <YouTubeHeader/YTHotConfig.h>
#import <YouTubeHeader/YTSettingsViewController.h>
#import <YouTubeHeader/YTSettingsSectionItem.h>
#import <YouTubeHeader/YTSettingsSectionItemManager.h>
#define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil]
extern BOOL UseVP9();
extern BOOL AllVP9();
NSBundle *YTUHDBundle() {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *tweakBundlePath = [[NSBundle mainBundle] pathForResource:@"YTUHD" ofType:@"bundle"];
if (tweakBundlePath)
bundle = [NSBundle bundleWithPath:tweakBundlePath];
else
bundle = [NSBundle bundleWithPath:ROOT_PATH_NS(@"/Library/Application Support/YTUHD.bundle")];
});
return bundle;
}
%hook YTSettingsSectionItemManager
- (void)updateVideoQualitySectionWithEntry:(id)entry {
YTHotConfig *hotConfig;
@try {
hotConfig = [self valueForKey:@"_hotConfig"];
} @catch (id ex) {
hotConfig = [self.gimme instanceForType:%c(YTHotConfig)];
}
YTIMediaQualitySettingsHotConfig *mediaQualitySettingsHotConfig = [hotConfig hotConfigGroup].mediaHotConfig.mediaQualitySettingsHotConfig;
BOOL defaultValue = mediaQualitySettingsHotConfig.enablePersistentVideoQualitySettings;
mediaQualitySettingsHotConfig.enablePersistentVideoQualitySettings = YES;
%orig;
mediaQualitySettingsHotConfig.enablePersistentVideoQualitySettings = defaultValue;
}
%end
static void addSectionItem(NSMutableArray <YTSettingsSectionItem *> *sectionItems, NSInteger category) {
if (category == 14) {
NSBundle *tweakBundle = YTUHDBundle();
BOOL hasVP9 = VTIsHardwareDecodeSupported(kCMVideoCodecType_VP9);
YTSettingsSectionItem *vp9 = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"USE_VP9")
titleDescription:[NSString stringWithFormat:@"%@\n\n%@\n\n%@: %d", LOC(@"USE_VP9_DESC"), LOC(@"YOUPIP_DESC"), LOC(@"HW_VP9_SUPPORT"), hasVP9]
accessibilityIdentifier:nil
switchOn:UseVP9()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:UseVP9Key];
return YES;
}
settingItemId:0];
[sectionItems addObject:vp9];
YTSettingsSectionItem *allVP9 = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"ALL_VP9")
titleDescription:LOC(@"ALL_VP9_DESC")
accessibilityIdentifier:nil
switchOn:AllVP9()
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AllVP9Key];
return YES;
}
settingItemId:0];
[sectionItems addObject:allVP9];
}
}
%hook YTSettingsViewController
- (void)setSectionItems:(NSMutableArray <YTSettingsSectionItem *> *)sectionItems forCategory:(NSInteger)category title:(NSString *)title titleDescription:(NSString *)titleDescription headerHidden:(BOOL)headerHidden {
addSectionItem(sectionItems, category);
%orig;
}
- (void)setSectionItems:(NSMutableArray <YTSettingsSectionItem *> *)sectionItems forCategory:(NSInteger)category title:(NSString *)title icon:(YTIIcon *)icon titleDescription:(NSString *)titleDescription headerHidden:(BOOL)headerHidden {
addSectionItem(sectionItems, category);
%orig;
}
%end