forked from PoomSmart/YTUHD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.x
66 lines (57 loc) · 2.65 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
#import "Header.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();
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:@"/Library/Application Support/YTUHD.bundle"];
if (!bundle)
bundle = [NSBundle bundleWithPath:@"/var/jb/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
%hook YTSettingsViewController
- (void)setSectionItems:(NSMutableArray <YTSettingsSectionItem *> *)sectionItems forCategory:(NSInteger)category title:(NSString *)title titleDescription:(NSString *)titleDescription headerHidden:(BOOL)headerHidden {
if (category == 14) {
NSBundle *tweakBundle = YTUHDBundle();
BOOL hasVP9 = VTIsHardwareDecodeSupported(kCMVideoCodecType_VP9);
YTSettingsSectionItem *vp9 = [%c(YTSettingsSectionItem) switchItemWithTitle:LOC(@"USE_VP9")
titleDescription:[NSString stringWithFormat:@"%@\n\n%@: %d", LOC(@"USE_VP9_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];
}
%orig(sectionItems, category, title, titleDescription, headerHidden);
}
%end