-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathSettings.x
105 lines (99 loc) · 5.02 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
#import <AppSettingsViewController.h>
#import "FeedFilterSettingsViewController.h"
NSBundle *redditFilterBundle;
extern UIImage *iconWithName(NSString *iconName);
extern NSString *localizedString(NSString *key, NSString *table);
@interface AppSettingsViewController ()
@property(nonatomic, assign) NSInteger feedFilterSectionIndex;
@end
%hook NSURLSession
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data, NSURLResponse *response,
NSError *error))completionHandler {
if (![request.URL.host hasPrefix:@"gql"] || !request.HTTPBody) return %orig;
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:request.HTTPBody
options:0
error:&error];
if (error || ![json[@"operationName"] isEqualToString:@"GetAllExperimentVariants"])
return %orig;
void (^newCompletionHandler)(NSData *, NSURLResponse *, NSError *) =
^(NSData *data, NSURLResponse *response, NSError *error) {
if (error || !data) return completionHandler(data, response, error);
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
if (error || !json) return completionHandler(data, response, error);
for (NSMutableDictionary *experimentVariant in json[@"data"][@"experimentVariants"])
if ([experimentVariant[@"experimentName"] isEqualToString:@"ios_swiftui_app_settings"])
experimentVariant[@"name"] = @"disabled";
data = [NSJSONSerialization dataWithJSONObject:json options:0 error:nil];
completionHandler(data, response, error);
};
return %orig(request, newCompletionHandler);
}
%end
%hook AppSettingsViewController
%property(nonatomic, assign) NSInteger feedFilterSectionIndex;
- (void)viewDidLoad {
%orig;
for (int section = 0; section < [self numberOfSectionsInTableView:self.tableView]; section++) {
BaseTableReusableView *headerView = (BaseTableReusableView *)[self tableView:self.tableView
viewForHeaderInSection:section];
if (!headerView) continue;
BaseLabel *label = headerView.contentView.subviews[0];
for (NSString *key in @[ @"drawer.settings.feedOptions", @"drawer.settings.viewOptions" ]) {
if ([label.text isEqualToString:[localizedString(key, @"user") uppercaseString]]) {
self.feedFilterSectionIndex = section;
return;
}
}
}
self.feedFilterSectionIndex = 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger result = %orig;
if (section == self.feedFilterSectionIndex) result++;
return result;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == self.feedFilterSectionIndex &&
indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
UIImage *iconImage = [iconWithName(@"icon_filter") ?: iconWithName(@"icon-filter-outline")
imageScaledToSize:CGSizeMake(20, 20)];
UIImage *accessoryIconImage =
[iconWithName(@"icon_forward") imageScaledToSize:CGSizeMake(20, 20)];
ImageLabelTableViewCell *cell =
[self dequeueSettingsCellForTableView:tableView
indexPath:indexPath
leadingImage:iconImage
text:[redditFilterBundle
localizedStringForKey:@"filter.settings.title"
value:@"Feed filter"
table:nil]];
[cell setCustomAccessoryImage:accessoryIconImage];
return cell;
}
return %orig;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == self.feedFilterSectionIndex &&
indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
[self.navigationController
pushViewController:[(FeedFilterSettingsViewController *)[objc_getClass(
"FeedFilterSettingsViewController") alloc]
initWithStyle:UITableViewStyleGrouped]
animated:YES];
return;
}
%orig;
}
%end
%ctor {
redditFilterBundle = [NSBundle bundleWithPath:[NSBundle.mainBundle pathForResource:@"RedditFilter"
ofType:@"bundle"]];
if (!redditFilterBundle)
redditFilterBundle = [NSBundle bundleWithPath:@THEOS_PACKAGE_INSTALL_PREFIX
@"/Library/Application Support/RedditFilter.bundle"];
}