Skip to content

Commit

Permalink
chore: export toast string
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian committed Dec 7, 2024
1 parent 64b52fe commit 59199ca
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 52 deletions.
111 changes: 60 additions & 51 deletions Settings.x
Original file line number Diff line number Diff line change
Expand Up @@ -371,64 +371,73 @@

%new
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
YTSettingsViewController *settingsVC = [self valueForKey:@"_settingsViewControllerDelegate"];
if (urls.count == 0) {
return;
}

NSURL *url = urls.firstObject;
[url startAccessingSecurityScopedResource];
if (objc_getAssociatedObject(controller, "gonerino_delegate") != self) return;

NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];
if (urls.count == 0) return;

[url stopAccessingSecurityScopedResource];
YTSettingsViewController *settingsVC = [self valueForKey:@"_settingsViewControllerDelegate"];
NSURL *url = urls.firstObject;

if (!data || error) {
[[%c(YTToastResponderEvent) eventWithMessage:@"Failed to read settings file"
if (isImportOperation) {
[url startAccessingSecurityScopedResource];

NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];

[url stopAccessingSecurityScopedResource];

if (!data || error) {
[[%c(YTToastResponderEvent) eventWithMessage:@"Failed to read settings file"
firstResponder:settingsVC] send];
return;
}

NSDictionary *settings = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:NULL
error:&error];

if (!settings || error) {
[[%c(YTToastResponderEvent) eventWithMessage:@"Invalid settings file format"
firstResponder:settingsVC] send];
return;
}

NSArray *channels = settings[@"blockedChannels"];
if (channels) {
[[ChannelManager sharedInstance] setBlockedChannels:[NSMutableArray arrayWithArray:channels]];
}

NSArray *videos = settings[@"blockedVideos"];
if (videos) {
[[VideoManager sharedInstance] setBlockedVideos:videos];
}

NSNumber *peopleWatched = settings[@"blockPeopleWatched"];
if (peopleWatched) {
[[NSUserDefaults standardUserDefaults] setBool:[peopleWatched boolValue] forKey:@"GonerinoPeopleWatched"];
}

NSNumber *mightLike = settings[@"blockMightLike"];
if (mightLike) {
[[NSUserDefaults standardUserDefaults] setBool:[mightLike boolValue] forKey:@"GonerinoMightLike"];
}

[[NSUserDefaults standardUserDefaults] synchronize];
[self reloadGonerinoSection];
[[%c(YTToastResponderEvent) eventWithMessage:@"Settings imported successfully"
firstResponder:settingsVC] send];
return;
}

NSDictionary *settings = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:NULL
error:&error];
} else {
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
settings[@"blockedChannels"] = [[ChannelManager sharedInstance] blockedChannels];
settings[@"blockedVideos"] = [[VideoManager sharedInstance] blockedVideos];
settings[@"blockPeopleWatched"] = @([[NSUserDefaults standardUserDefaults] boolForKey:@"GonerinoPeopleWatched"]);
settings[@"blockMightLike"] = @([[NSUserDefaults standardUserDefaults] boolForKey:@"GonerinoMightLike"]);

if (!settings || error) {
[[%c(YTToastResponderEvent) eventWithMessage:@"Invalid settings file format"
[settings writeToURL:url atomically:YES];
[[%c(YTToastResponderEvent) eventWithMessage:@"Settings exported successfully"
firstResponder:settingsVC] send];
return;
}

NSArray *channels = settings[@"blockedChannels"];
if (channels) {
[[ChannelManager sharedInstance] setBlockedChannels:[NSMutableArray arrayWithArray:channels]];
}

NSArray *videos = settings[@"blockedVideos"];
if (videos) {
[[VideoManager sharedInstance] setBlockedVideos:videos];
}

NSNumber *peopleWatched = settings[@"blockPeopleWatched"];
if (peopleWatched) {
[[NSUserDefaults standardUserDefaults] setBool:peopleWatched.boolValue forKey:@"GonerinoPeopleWatched"];
}

NSNumber *mightLike = settings[@"blockMightLike"];
if (mightLike) {
[[NSUserDefaults standardUserDefaults] setBool:mightLike.boolValue forKey:@"GonerinoMightLike"];
}

[self reloadGonerinoSection];

UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
[generator prepare];
[generator impactOccurred];

[[%c(YTToastResponderEvent) eventWithMessage:@"Settings imported successfully"
firstResponder:settingsVC] send];
}

%new
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dev.adrian.gonerino
Name: Gonerino
Version: 0.5.0
Version: 0.5.1
Architecture: iphoneos-arm
Description: Remove videos uploaded by specific channels
Maintainer: Adrian Castro
Expand Down

0 comments on commit 59199ca

Please sign in to comment.