mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-04-21 11:52:00 +00:00
Improved Copy Settings & Paste Settings
This also fixes crashing when interacting with the buttons when having “replaceCopyandPasteButtons_enabled” enabled.
This commit is contained in:
parent
3978100972
commit
4214d03d3b
1 changed files with 22 additions and 19 deletions
|
|
@ -201,21 +201,19 @@ extern NSBundle *uYouPlusBundle();
|
||||||
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
|
selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) {
|
||||||
if (IS_ENABLED(@"replaceCopyandPasteButtons_enabled")) {
|
if (IS_ENABLED(@"replaceCopyandPasteButtons_enabled")) {
|
||||||
// Export Settings functionality
|
// Export Settings functionality
|
||||||
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"exported_settings.txt"]];
|
||||||
NSMutableString *settingsString = [NSMutableString string];
|
NSMutableString *settingsString = [NSMutableString string];
|
||||||
for (NSString *key in copyKeys) {
|
for (NSString *key in copyKeys) {
|
||||||
if ([userDefaults objectForKey:key]) {
|
id value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
||||||
NSString *value = [userDefaults objectForKey:key];
|
if (value) {
|
||||||
[settingsString appendFormat:@"%@: %@\n", key, value];
|
[settingsString appendFormat:@"%@: %@\n", key, value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settingsString.length > 0) {
|
[settingsString writeToURL:tempFileURL atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
||||||
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeExportToService];
|
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithURL:tempFileURL inMode:UIDocumentPickerModeExportToService];
|
||||||
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
|
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
|
||||||
documentPicker.allowsMultipleSelection = NO;
|
documentPicker.allowsMultipleSelection = NO;
|
||||||
[UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:documentPicker animated:YES completion:nil];
|
[settingsViewController presentViewController:documentPicker animated:YES completion:nil];
|
||||||
}
|
|
||||||
return YES;
|
|
||||||
} else {
|
} else {
|
||||||
// Copy Settings functionality (default behavior)
|
// Copy Settings functionality (default behavior)
|
||||||
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
@ -245,7 +243,7 @@ extern NSBundle *uYouPlusBundle();
|
||||||
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeImport];
|
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.text"] inMode:UIDocumentPickerModeImport];
|
||||||
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
|
documentPicker.delegate = (id<UIDocumentPickerDelegate>)self;
|
||||||
documentPicker.allowsMultipleSelection = NO;
|
documentPicker.allowsMultipleSelection = NO;
|
||||||
[UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:documentPicker animated:YES completion:nil];
|
[settingsViewController presentViewController:documentPicker animated:YES completion:nil];
|
||||||
return YES;
|
return YES;
|
||||||
} else {
|
} else {
|
||||||
// Paste Settings functionality (default behavior)
|
// Paste Settings functionality (default behavior)
|
||||||
|
|
@ -262,7 +260,7 @@ extern NSBundle *uYouPlusBundle();
|
||||||
NSString *value = components[1];
|
NSString *value = components[1];
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[settingsViewController reloadData];
|
[settingsViewController reloadData];
|
||||||
SHOW_RELAUNCH_YT_SNACKBAR;
|
SHOW_RELAUNCH_YT_SNACKBAR;
|
||||||
}
|
}
|
||||||
|
|
@ -1395,18 +1393,23 @@ extern NSBundle *uYouPlusBundle();
|
||||||
[settingsViewController setSectionItems:sectionItems forCategory:uYouPlusSection title:@"uYouEnhanced" titleDescription:LOC(@"TITLE DESCRIPTION") headerHidden:YES];
|
[settingsViewController setSectionItems:sectionItems forCategory:uYouPlusSection title:@"uYouEnhanced" titleDescription:LOC(@"TITLE DESCRIPTION") headerHidden:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
// File Manager (Paste Settings)
|
// File Manager (Import Settings .txt)
|
||||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
||||||
if (urls.count > 0) {
|
if (urls.count > 0) {
|
||||||
NSString *fileContents = [NSString stringWithContentsOfURL:urls.firstObject encoding:NSUTF8StringEncoding error:nil];
|
NSURL *fileURL = urls.firstObject;
|
||||||
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
|
NSString *fileContents = [NSString stringWithContentsOfURL:fileURL encoding:NSUTF8StringEncoding error:nil];
|
||||||
for (NSString *line in lines) {
|
if (fileContents.length > 0) {
|
||||||
NSArray *components = [line componentsSeparatedByString:@": "];
|
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
|
||||||
if (components.count == 2) {
|
for (NSString *line in lines) {
|
||||||
NSString *key = components[0];
|
NSArray *components = [line componentsSeparatedByString:@": "];
|
||||||
NSString *value = components[1];
|
if (components.count == 2) {
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
NSString *key = components[0];
|
||||||
|
NSString *value = components[1];
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"];
|
||||||
|
[settingsViewController reloadData];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue