Update Settings.xm

This commit is contained in:
Foxster
2023-12-25 00:27:46 -08:00
parent a230c4e16b
commit 069db37bf2
+96 -73
View File
@@ -6,11 +6,13 @@
#import "../Tweaks/YouTubeHeader/YTSettingsPickerViewController.h" #import "../Tweaks/YouTubeHeader/YTSettingsPickerViewController.h"
#import "uYouPlus.h" #import "uYouPlus.h"
#define SECTION_HEADER(s) [sectionItems addObject:[%c(YTSettingsSectionItem) itemWithTitle:nil titleDescription:[s uppercaseString] accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger sectionItemIndex) { return NO; }]] #define VERSION_STRING [[NSString stringWithFormat:@"%@", @(OS_STRINGIFY(TWEAK_VERSION))] stringByReplacingOccurrencesOfString:@"\"" withString:@""]
#define SECTION_HEADER(s) [sectionItems addObject:[%c(YTSettingsSectionItem) itemWithTitle:@"\t" titleDescription:[s uppercaseString] accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger sectionItemIndex) { return NO; }]]
#define SWITCH_ITEM(t, d, k) [sectionItems addObject:[YTSettingsSectionItemClass switchItemWithTitle:t titleDescription:d accessibilityIdentifier:nil switchOn:IS_ENABLED(k) switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:k];return YES;} settingItemId:0]] #define SWITCH_ITEM(t, d, k) [sectionItems addObject:[YTSettingsSectionItemClass switchItemWithTitle:t titleDescription:d accessibilityIdentifier:nil switchOn:IS_ENABLED(k) switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:k];return YES;} settingItemId:0]]
#define SHOW_RELAUNCH_YT_SNACKBAR [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Relaunch YouTube to apply changes"]] #define SHOW_RELAUNCH_YT_SNACKBAR [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:LOC(@"RESTART_YOUTUBE")]]
#define SWITCH_ITEM2(t, d, k) [sectionItems addObject:[YTSettingsSectionItemClass switchItemWithTitle:t titleDescription:d accessibilityIdentifier:nil switchOn:IS_ENABLED(k) switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:k];SHOW_RELAUNCH_YT_SNACKBAR;return YES;} settingItemId:0]] #define SWITCH_ITEM2(t, d, k) [sectionItems addObject:[YTSettingsSectionItemClass switchItemWithTitle:t titleDescription:d accessibilityIdentifier:nil switchOn:IS_ENABLED(k) switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:k];SHOW_RELAUNCH_YT_SNACKBAR;return YES;} settingItemId:0]]
@@ -48,8 +50,51 @@ extern NSBundle *uYouPlusBundle();
Class YTSettingsSectionItemClass = %c(YTSettingsSectionItem); Class YTSettingsSectionItemClass = %c(YTSettingsSectionItem);
YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"];
# pragma mark - About
// SECTION_HEADER(LOC(@"ABOUT"));
YTSettingsSectionItem *version = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"VERSION")
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:^NSString *() {
return VERSION_STRING;
}
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
return [%c(YTUIUtils) openURL:[NSURL URLWithString:@"https://github.com/therealFoxster/uYouPlus/releases"]];
}
];
[sectionItems addObject:version];
YTSettingsSectionItem *bug = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"REPORT_AN_ISSUE")
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSString *url = [NSString stringWithFormat:@"https://github.com/therealFoxster/uYouPlus/issues/new/?title=[v%@] %@", VERSION_STRING, LOC(@"ADD_TITLE")];
return [%c(YTUIUtils) openURL:[NSURL URLWithString:[url stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]];
}
];
[sectionItems addObject:bug];
YTSettingsSectionItem *exitYT = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"QUIT_YOUTUBE")
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
// https://stackoverflow.com/a/17802404/19227228
[[UIApplication sharedApplication] performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:0.5];
exit(0);
}
];
[sectionItems addObject:exitYT];
# pragma mark - App theme # pragma mark - App theme
SECTION_HEADER(@"App theme"); SECTION_HEADER(LOC(@"APP_THEME"));
YTSettingsSectionItem *themeGroup = [YTSettingsSectionItemClass YTSettingsSectionItem *themeGroup = [YTSettingsSectionItemClass
itemWithTitle:LOC(@"DARK_THEME") itemWithTitle:LOC(@"DARK_THEME")
@@ -67,36 +112,55 @@ extern NSBundle *uYouPlusBundle();
} }
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
NSArray <YTSettingsSectionItem *> *rows = @[ NSArray <YTSettingsSectionItem *> *rows = @[
[YTSettingsSectionItemClass checkmarkItemWithTitle:LOC(@"DEFAULT_THEME") titleDescription:LOC(@"DEFAULT_THEME_DESC") selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { [YTSettingsSectionItemClass
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"appTheme"]; checkmarkItemWithTitle:LOC(@"DEFAULT_THEME")
[settingsViewController reloadData]; titleDescription:LOC(@"DEFAULT_THEME_DESC")
SHOW_RELAUNCH_YT_SNACKBAR; selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
return YES; [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"appTheme"];
}], [settingsViewController reloadData];
[YTSettingsSectionItemClass checkmarkItemWithTitle:LOC(@"OLD_DARK_THEME") titleDescription:LOC(@"OLD_DARK_THEME_DESC") selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { SHOW_RELAUNCH_YT_SNACKBAR;
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"appTheme"]; return YES;
[settingsViewController reloadData]; }
SHOW_RELAUNCH_YT_SNACKBAR; ],
return YES; [YTSettingsSectionItemClass
}], checkmarkItemWithTitle:LOC(@"OLD_DARK_THEME")
[YTSettingsSectionItemClass checkmarkItemWithTitle:LOC(@"OLED_DARK_THEME") titleDescription:LOC(@"OLED_DARK_THEME_DESC") selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { titleDescription:LOC(@"OLD_DARK_THEME_DESC")
[[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"appTheme"]; selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
[settingsViewController reloadData]; [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"appTheme"];
SHOW_RELAUNCH_YT_SNACKBAR; [settingsViewController reloadData];
return YES; SHOW_RELAUNCH_YT_SNACKBAR;
}], return YES;
[YTSettingsSectionItemClass switchItemWithTitle:LOC(@"OLED_KEYBOARD") }
titleDescription:LOC(@"OLED_KEYBOARD_DESC") ],
accessibilityIdentifier:nil [YTSettingsSectionItemClass
switchOn:IS_ENABLED(@"oledKeyBoard_enabled") checkmarkItemWithTitle:LOC(@"OLED_DARK_THEME")
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) { titleDescription:LOC(@"OLED_DARK_THEME_DESC")
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"oledKeyBoard_enabled"]; selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
SHOW_RELAUNCH_YT_SNACKBAR; [[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"appTheme"];
return YES; [settingsViewController reloadData];
} SHOW_RELAUNCH_YT_SNACKBAR;
settingItemId:0] return YES;
}
],
[YTSettingsSectionItemClass
switchItemWithTitle:LOC(@"OLED_KEYBOARD")
titleDescription:LOC(@"OLED_KEYBOARD_DESC")
accessibilityIdentifier:nil
switchOn:IS_ENABLED(@"oledKeyBoard_enabled")
switchBlock:^BOOL (YTSettingsCell *cell, BOOL enabled) {
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:@"oledKeyBoard_enabled"];
SHOW_RELAUNCH_YT_SNACKBAR;
return YES;
}
settingItemId:0
]
];
YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc]
initWithNavTitle:LOC(@"DARK_THEME")
pickerSectionTitle:[LOC(@"DARK_THEME") uppercaseString]
rows:rows selectedItemIndex:APP_THEME_IDX
parentResponder:[self parentResponder]
]; ];
YTSettingsPickerViewController *picker = [[%c(YTSettingsPickerViewController) alloc] initWithNavTitle:LOC(@"DARK_THEME") pickerSectionTitle:[LOC(@"DARK_THEME") uppercaseString] rows:rows selectedItemIndex:APP_THEME_IDX parentResponder:[self parentResponder]];
[settingsViewController pushViewController:picker]; [settingsViewController pushViewController:picker];
return YES; return YES;
} }
@@ -146,47 +210,6 @@ extern NSBundle *uYouPlusBundle();
SWITCH_ITEM2(LOC(@"YT_RE_EXPLORE"), LOC(@"YT_RE_EXPLORE_DESC"), @"reExplore_enabled"); SWITCH_ITEM2(LOC(@"YT_RE_EXPLORE"), LOC(@"YT_RE_EXPLORE_DESC"), @"reExplore_enabled");
SWITCH_ITEM(LOC(@"ENABLE_FLEX"), LOC(@"ENABLE_FLEX_DESC"), @"flex_enabled"); SWITCH_ITEM(LOC(@"ENABLE_FLEX"), LOC(@"ENABLE_FLEX_DESC"), @"flex_enabled");
# pragma mark - About
SECTION_HEADER(@"About");
YTSettingsSectionItem *bug = [%c(YTSettingsSectionItem)
itemWithTitle:@"Report an issue"
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
return [%c(YTUIUtils) openURL:[NSURL URLWithString:@"https://github.com/therealFoxster/uYouPlus/issues"]];
}
];
[sectionItems addObject:bug];
YTSettingsSectionItem *version = [%c(YTSettingsSectionItem)
itemWithTitle:LOC(@"VERSION")
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:^NSString *() {
return [[NSString stringWithFormat:@"%@", @(OS_STRINGIFY(TWEAK_VERSION))] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
}
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
return [%c(YTUIUtils) openURL:[NSURL URLWithString:@"https://github.com/therealFoxster/uYouPlus/releases"]];
}
];
[sectionItems addObject:version];
YTSettingsSectionItem *exitYT = [%c(YTSettingsSectionItem)
itemWithTitle:@"Exit YouTube"
titleDescription:nil
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
// https://stackoverflow.com/a/17802404/19227228
[[UIApplication sharedApplication] performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:0.5];
exit(0);
}
];
[sectionItems addObject:exitYT];
[settingsViewController setSectionItems:sectionItems forCategory:uYouPlusSection title:@"uYouPlus" titleDescription:LOC(@"TITLE DESCRIPTION") headerHidden:YES]; [settingsViewController setSectionItems:sectionItems forCategory:uYouPlusSection title:@"uYouPlus" titleDescription:LOC(@"TITLE DESCRIPTION") headerHidden:YES];
} }