Skip to content

Commit

Permalink
Tap each A/B setting to copy to clipboard or remove from modified list
Browse files Browse the repository at this point in the history
  • Loading branch information
PoomSmart committed Jan 15, 2023
1 parent 4ca8b2d commit 2b44222
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET := iphone:clang:latest:11.0
INSTALL_TARGET_PROCESSES = YouTube
ARCHS = arm64
PACKAGE_VERSION = 1.4.7
PACKAGE_VERSION = 1.5.0

include $(THEOS)/makefiles/common.mk

Expand Down
39 changes: 31 additions & 8 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ static void setValue(NSString *method, NSString *classKey, BOOL value) {
[defaults setBool:value forKey:getKey(method, classKey)];
}

static void updateAllKeys() {
allKeys = [defaults dictionaryRepresentation].allKeys;
}

static BOOL returnFunction(id const self, SEL _cmd) {
NSString *method = NSStringFromSelector(_cmd);
NSString *methodKey = getKey(method, NSStringFromClass([self class]));
Expand Down Expand Up @@ -157,6 +161,7 @@ static NSString *getCategory(char c, NSString *method) {
BOOL isPhone = ![%c(YTCommonUtils) isIPad];
NSString *yesText = _LOC([NSBundle mainBundle], @"settings.yes");
NSString *cancelText = _LOC([NSBundle mainBundle], @"confirm.cancel");
NSString *deleteText = _LOC([NSBundle mainBundle], @"search.action.delete");
Class YTSettingsSectionItemClass = %c(YTSettingsSectionItem);
Class YTAlertViewClass = %c(YTAlertView);
if (tweakEnabled()) {
Expand All @@ -166,6 +171,7 @@ static NSString *getCategory(char c, NSString *method) {
char c = tolower([method characterAtIndex:0]);
NSString *category = getCategory(c, method);
if (![properties objectForKey:category]) properties[category] = [NSMutableArray array];
updateAllKeys();
BOOL modified = [allKeys containsObject:getKey(method, classKey)];
NSString *modifiedTitle = modified ? [NSString stringWithFormat:@"%@ *", method] : method;
YTSettingsSectionItem *methodSwitch = [YTSettingsSectionItemClass switchItemWithTitle:modifiedTitle
Expand All @@ -176,13 +182,28 @@ static NSString *getCategory(char c, NSString *method) {
setValue(method, classKey, enabled);
return YES;
}
// selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
// YTAlertView *alertView = [YTAlertViewClass infoDialog];
// alertView.title = method;
// alertView.subtitle = [NSString stringWithFormat:@"-[%@ %@]", classKey, method];
// [alertView show];
// return YES;
// }
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSString *content = [NSString stringWithFormat:@"%@.%@", classKey, method];
YTAlertView *alertView = [YTAlertViewClass confirmationDialog];
alertView.title = method;
alertView.subtitle = content;
[alertView addTitle:LOC(@"COPY_TO_CLIPBOARD") withAction:^{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = content;
[[%c(YTToastResponderEvent) eventWithMessage:LOC(@"COPIED_TO_CLIPBOARD") firstResponder:[self parentResponder]] send];
}];
updateAllKeys();
NSString *key = getKey(method, classKey);
if ([allKeys containsObject:key]) {
[alertView addTitle:deleteText withAction:^{
[defaults removeObjectForKey:key];
updateAllKeys();
}];
}
[alertView addCancelButton:NULL];
[alertView show];
return NO;
}
settingItemId:0];
[properties[category] addObject:methodSwitch];
}
Expand Down Expand Up @@ -238,6 +259,7 @@ static NSString *getCategory(char c, NSString *method) {
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSMutableArray *features = [NSMutableArray array];
updateAllKeys();
for (NSString *key in allKeys) {
if ([key hasPrefix:Prefix]) {
NSString *displayKey = [key substringFromIndex:Prefix.length + 1];
Expand All @@ -264,6 +286,7 @@ static NSString *getCategory(char c, NSString *method) {
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
YTAlertView *alertView = [YTAlertViewClass confirmationDialogWithAction:^{
updateAllKeys();
for (NSString *key in allKeys) {
if ([key hasPrefix:Prefix])
[defaults removeObjectForKey:key];
Expand Down Expand Up @@ -380,7 +403,7 @@ static void hookClass(NSObject *instance) {
- (BOOL)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
defaults = [NSUserDefaults standardUserDefaults];
if (tweakEnabled()) {
allKeys = [defaults dictionaryRepresentation].allKeys;
updateAllKeys();
YTGlobalConfig *globalConfig;
YTColdConfig *coldConfig;
YTHotConfig *hotConfig;
Expand Down

0 comments on commit 2b44222

Please sign in to comment.