From 0d72c03167ae605aaa30905c120f0855e65ac8de Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:23:02 -0700 Subject: [PATCH 1/7] Add keys to Copy Settings --- Source/Settings.xm | 18 +++----- Source/SettingsKeys.h | 42 +++++++++++++++++++ Source/get_keys.py | 96 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 Source/SettingsKeys.h create mode 100644 Source/get_keys.py diff --git a/Source/Settings.xm b/Source/Settings.xm index c25f262..00e49e7 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -5,6 +5,7 @@ #import "../Tweaks/YouTubeHeader/YTSettingsSectionItemManager.h" #import "../Tweaks/YouTubeHeader/YTUIUtils.h" #import "../Tweaks/YouTubeHeader/YTSettingsPickerViewController.h" +#import "SettingsKeys.h" // #import "AppIconOptionsController.h" // Basic switch item @@ -47,17 +48,6 @@ static int appVersionSpoofer() { extern NSBundle *YTLitePlusBundle(); -// Keys for "Copy Settings" button (for: YTLitePlus) -NSArray *copyKeys = @[ -/* MAIN Controls Keys 1/2 */ @"enableShareButton_enabled", @"enableSaveToButton_enabled", @"hideVideoPlayerShadowOverlayButtons_enabled", @"hideRightPanel_enabled", @"hideHeatwaves_enabled", @"disableAmbientModePortrait_enabled", -/* MAIN Controls Keys 2/2 */ @"disableAmbientModeFullscreen_enabled", @"fullscreenToTheRight_enabled", @"seekAnywhere_enabled", @"YTTapToSeek_enabled", @"disablePullToFull_enabled", @"alwaysShowRemainingTime_enabled", @"disableRemainingTime_enabled", @"disableEngagementOverlay_enabled", -/* MAIN App Overlay Keys 1/2 */ @"disableAccountSection_enabled", @"disableAutoplaySection_enabled", @"disableTryNewFeaturesSection_enabled", @"disableVideoQualityPreferencesSection_enabled", @"disableNotificationsSection_enabled", -/* MAIN App Overlay Keys 2/2 */ @"disableManageAllHistorySection_enabled", @"disableYourDataInYouTubeSection_enabled", @"disablePrivacySection_enabled", @"disableLiveChatSection_enabled", -/* MAIN Playback Keys */ @"inline_muted_playback_enabled", -/* MAIN Misc Keys */ @"newSettingsUI_enabled", @"ytStartupAnimation_enabled", @"ytNoModernUI_enabled", @"iPadLayout_enabled", @"iPhoneLayout_enabled", @"castConfirm_enabled", @"bigYTMiniPlayer_enabled", @"hideCastButton_enabled", @"hideSponsorBlockButton_enabled", @"hideHomeTab_enabled", @"fixCasting_enabled", @"flex_enabled", @"enableVersionSpoofer_enabled", -/* TWEAK YTUHD Keys */ @"EnableVP9", @"AllVP9" -]; - // Add both YTLite and YTLitePlus to YouGroupSettings static const NSInteger YTLitePlusSection = 788; static const NSInteger YTLiteSection = 789; @@ -115,6 +105,7 @@ static const NSInteger YTLiteSection = 789; }]; [sectionItems addObject:main]; +# pragma mark - Copy and Paste Settings YTSettingsSectionItem *copySettings = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"COPY_SETTINGS") titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"COPY_SETTINGS_DESC_2") : LOC(@"COPY_SETTINGS_DESC") @@ -125,7 +116,7 @@ static const NSInteger YTLiteSection = 789; // Export Settings functionality NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"exported_settings.txt"]]; NSMutableString *settingsString = [NSMutableString string]; - for (NSString *key in copyKeys) { + for (NSString *key in NSUserDefaultsCopyKeys) { id value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; if (value) { [settingsString appendFormat:@"%@: %@\n", key, value]; @@ -140,7 +131,7 @@ static const NSInteger YTLiteSection = 789; // Copy Settings functionality (DEFAULT - Copies to Clipboard) NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSMutableString *settingsString = [NSMutableString string]; - for (NSString *key in copyKeys) { + for (NSString *key in NSUserDefaultsCopyKeys) { if ([userDefaults objectForKey:key]) { NSString *value = [userDefaults objectForKey:key]; [settingsString appendFormat:@"%@: %@\n", key, value]; @@ -194,6 +185,7 @@ static const NSInteger YTLiteSection = 789; ]; [sectionItems addObject:pasteSettings]; +# pragma mark - Video Player YTSettingsSectionItem *videoPlayer = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"VIDEO_PLAYER") titleDescription:LOC(@"VIDEO_PLAYER_DESC") diff --git a/Source/SettingsKeys.h b/Source/SettingsKeys.h new file mode 100644 index 0000000..96a5bfb --- /dev/null +++ b/Source/SettingsKeys.h @@ -0,0 +1,42 @@ +#import "../YTLitePlus.h" + +// Keys for "Copy Settings" button (for: YTLitePlus) +// In alphabetical order for tweaks after YTLitePlus +NSArray *NSUserDefaultsCopyKeys = @[ + // YTLitePlus - gathered using get_keys.py + @"YTTapToSeek_enabled", @"alwaysShowRemainingTime_enabled", @"bigYTMiniPlayer_enabled", @"castConfirm_enabled", + @"disableAccountSection_enabled", @"disableAmbientModeFullscreen_enabled", + @"disableAmbientModePortrait_enabled", @"disableAutoplaySection_enabled", @"disableCollapseButton_enabled", + @"disableEngagementOverlay_enabled", @"disableLiveChatSection_enabled", + @"disableManageAllHistorySection_enabled", @"disableNotificationsSection_enabled", + @"disablePrivacySection_enabled", @"disablePullToFull_enabled", @"disableRemainingTime_enabled", + @"disableTryNewFeaturesSection_enabled", @"disableVideoQualityPreferencesSection_enabled", + @"disableYourDataInYouTubeSection_enabled", @"enableSaveToButton_enabled", @"enableShareButton_enabled", + @"enableVersionSpoofer_enabled", @"fixCasting_enabled", @"flex_enabled", @"fullscreenToTheRight_enabled", + @"hideAutoplayMiniPreview_enabled", @"hideCastButton_enabled", @"hideHUD_enabled", @"hideHeatwaves_enabled", + @"hideHomeTab_enabled", @"hidePreviewCommentSection_enabled", @"hideRightPanel_enabled", + @"hideSpeedToast_enabled", @"hideSponsorBlockButton_enabled", @"hideVideoPlayerShadowOverlayButtons_enabled", + @"iPadLayout_enabled", @"iPhoneLayout_enabled", @"inline_muted_playback_enabled", @"lowContrastMode_enabled", + @"newSettingsUI_enabled", @"oledKeyBoard_enabled", @"playerGestures_enabled", @"seekAnywhere_enabled", + @"switchCopyandPasteFunctionality_enabled", @"ytNoModernUI_enabled", @"ytStartupAnimation_enabled", + // DEMC - https://github.com/therealFoxster/DontEatMyContent/blob/master/Tweak.h + @"DEMC_enabled", @"DEMC_colorViewsEnabled", @"DEMC_safeAreaConstant", @"DEMC_disableAmbientMode", + @"DEMC_limitZoomToFill", @"DEMC_enableForAllVideos", + // iSponsorBlock cannot be exported using this method - it is also being removed in v5 + // Return-YouTube-Dislike - https://github.com/PoomSmart/Return-YouTube-Dislikes/blob/main/TweakSettings.h + @"RYD-ENABLED", @"RYD-VOTE-SUBMISSION", @"RYD-EXACT-LIKE-NUMBER", @"RYD-EXACT-NUMBER", + // All YTVideoOverlay Tweaks - https://github.com/PoomSmart/YTVideoOverlay/blob/0fc6d29d1aa9e75f8c13d675daec9365f753d45e/Tweak.x#L28C1-L41C84 + @"YTVideoOverlay-YouLoop-Enabled", @"YTVideoOverlay-YouTimeStamp-Enabled", @"YTVideoOverlay-YouMute-Enabled", + @"YTVideoOverlay-YouQuality-Enabled", @"YTVideoOverlay-YouLoop-Position", @"YTVideoOverlay-YouTimeStamp-Position", + @"YTVideoOverlay-YouMute-Position", @"YTVideoOverlay-YouQuality-Position", + // YouPiP - https://github.com/PoomSmart/YouPiP/blob/main/Header.h + @"YouPiPPosition", @"CompatibilityModeKey", @"PiPActivationMethodKey", @"PiPActivationMethod2Key", + @"NoMiniPlayerPiPKey", @"NonBackgroundableKey", + // YTABConfig cannot be reasonably exported using this method + // YTHoldForSpeed will be removed in v5 + // YouTube Plus / YTLite cannot be exported using this method + // YTUHD - https://github.com/PoomSmart/YTUHD/blob/master/Header.h + @"EnableVP9", @"AllVP9", + // Useful YouTube Keys + @"inline_muted_playback_enabled", +]; diff --git a/Source/get_keys.py b/Source/get_keys.py new file mode 100644 index 0000000..e763e3a --- /dev/null +++ b/Source/get_keys.py @@ -0,0 +1,96 @@ +import re +import os + +def extract_values_from_file(file_path): + """ + Extracts keys that match the pattern @\"_enabled\" from the given file. + + Args: + file_path (str): The path to the file to be searched. + + Returns: + list: A list of matching keys found in the file. + """ + # Define the regex pattern to match the strings that resemble the given examples + pattern = r'@\"[a-zA-Z0-9_]+_enabled\"' + matches = [] + + try: + # Read the content of the file + with open(file_path, 'r') as file: + file_content = file.read() + + # Find all matches + matches = re.findall(pattern, file_content) + except Exception as e: + print(f"Error reading {file_path}: {e}") + + return matches + +def format_output(keys): + """ + Formats the keys with indentation and line breaks if the segment exceeds 120 characters (116 excluding indentation). + + Args: + keys (list): The list of keys to be formatted. + + Returns: + str: A formatted string with the keys. + """ + indent = " " * 4 + line_length_limit = 116 # Limit excluding indentation + current_line = indent + formatted_output = "" + + for key in keys: + # Check if adding the next key would exceed the line length limit + if len(current_line) + len(key) + 2 > line_length_limit: # +2 accounts for the comma and space + # Add the current line to the formatted output and start a new line + formatted_output += current_line.rstrip(", ") + ",\n" + current_line = indent # Start a new indented line + + # Add the key to the current line + current_line += key + ", " + + # Add the last line to the output + formatted_output += current_line.rstrip(", ") # Remove trailing comma and space from the final line + return formatted_output + +def find_and_extract_keys(): + """ + Recursively searches for .xm and .h files in the parent directory and extracts keys + that match the pattern @\"_enabled\". The matching keys are then printed + with indentation and line breaks if the line exceeds 120 characters. + + Usage: + 1. Place this script in the desired directory. + 2. Run the script with the command: python extract_keys.py + 3. The script will search for all .xm and .h files in the parent directory and + print any matching keys it finds. + + Note: + - The script searches the directory where it is located (the parent directory). + - It only looks for files with extensions .xm and .h. + """ + # Get the parent directory + parent_directory = os.path.dirname(os.path.abspath(__file__)) + + # Store the found keys + found_keys = set() # Use a set to automatically remove duplicates + + # Walk through the parent directory and find all .xm and .h files + for root, dirs, files in os.walk(parent_directory): + for file in files: + if file.endswith(('.xm', '.h')): + file_path = os.path.join(root, file) + found_keys.update(extract_values_from_file(file_path)) + + # Print the found keys with formatting + if found_keys: + sorted_keys = sorted(found_keys) + print(format_output(sorted_keys)) + else: + print("No keys found.") + +if __name__ == "__main__": + find_and_extract_keys() From beeb9eb19fb6b185b6d369484eecda3c4cc77d5c Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:46:32 -0700 Subject: [PATCH 2/7] Add default value ignore --- Source/Settings.xm | 10 ++++++++-- Source/SettingsKeys.h | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index 00e49e7..eff47c3 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -132,13 +132,18 @@ static const NSInteger YTLiteSection = 789; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSMutableString *settingsString = [NSMutableString string]; for (NSString *key in NSUserDefaultsCopyKeys) { - if ([userDefaults objectForKey:key]) { - NSString *value = [userDefaults objectForKey:key]; + id value = [userDefaults objectForKey:key]; + id defaultValue = NSUserDefaultsCopyKeysDefaults[key]; + + // Only include the setting if it is different from the default value + // If no default value is found, include it by default + if (value && (!defaultValue || ![value isEqual:defaultValue])) { [settingsString appendFormat:@"%@: %@\n", key, value]; } } [[UIPasteboard generalPasteboard] setString:settingsString]; // Show a confirmation message or perform some other action here + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings copied"]]; } return YES; } @@ -176,6 +181,7 @@ static const NSInteger YTLiteSection = 789; } [settingsViewController reloadData]; // Show a confirmation message or perform some other action here + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings applied"]]; } }]]; [settingsViewController presentViewController:confirmPasteAlert animated:YES completion:nil]; diff --git a/Source/SettingsKeys.h b/Source/SettingsKeys.h index 96a5bfb..384f08b 100644 --- a/Source/SettingsKeys.h +++ b/Source/SettingsKeys.h @@ -40,3 +40,15 @@ NSArray *NSUserDefaultsCopyKeys = @[ // Useful YouTube Keys @"inline_muted_playback_enabled", ]; + + +// Some default values to ignore when exporting settings +NSDictionary *NSUserDefaultsCopyKeysDefaults = @{ + @"fixCasting_enabled": @1, + @"inline_muted_playback_enabled": @5, + @"newSettingsUI_enabled": @1, + @"DEMC_safeAreaConstant": @21.5, + @"RYD-ENABLED": @1, + @"RYD-VOTE-SUBMISSION": @1, + // Duplicate keys are not allowed in NSDictionary. If present, only the last one will be kept. +}; \ No newline at end of file From 6e9ec38c4a235ef0ee03d065b0e5247271baacf7 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:30:30 -0700 Subject: [PATCH 3/7] Add reminder for YouTube Plus --- Source/Settings.xm | 15 +++++++++++++++ YTLitePlus.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Source/Settings.xm b/Source/Settings.xm index eff47c3..94bccaf 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -145,6 +145,14 @@ static const NSInteger YTLiteSection = 789; // Show a confirmation message or perform some other action here [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings copied"]]; } + // Prompt to export YouTube Plus settings + UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" message:@"Note: This cannot save iSponsorBlock and most YouTube settings.\nWould you like to also export your YouTube Plus Settings?" preferredStyle:UIAlertControllerStyleAlert]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + // Export YouTube Plus Settings functionality + [%c(YTLUserDefaults) exportYtlSettings]; + }]]; + [settingsViewController presentViewController:exportAlert animated:YES completion:nil]; return YES; } ]; @@ -186,6 +194,13 @@ static const NSInteger YTLiteSection = 789; }]]; [settingsViewController presentViewController:confirmPasteAlert animated:YES completion:nil]; } + // Reminder to import YouTube Plus settings + UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" + message:@"Remember to import your YouTube Plus settings as well." + preferredStyle:UIAlertControllerStyleAlert]; + [reminderAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; + [settingsViewController presentViewController:reminderAlert animated:YES completion:nil]; + return YES; } ]; diff --git a/YTLitePlus.h b/YTLitePlus.h index 8a41583..062a504 100644 --- a/YTLitePlus.h +++ b/YTLitePlus.h @@ -133,6 +133,7 @@ typedef NS_ENUM(NSUInteger, GestureSection) { // OLED Live Chat - @bhackel @interface YTLUserDefaults : NSUserDefaults ++ (void)exportYtlSettings; @end // Hide Home Tab - @bhackel From 2097308a8321e27d68c4bfe774fa3abd77000a15 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:57:38 -0700 Subject: [PATCH 4/7] Improve localizations, fix bugs --- Source/Settings.xm | 57 +++++++++++++------ .../ar.lproj/Localizable.strings | 1 + .../bg.lproj/Localizable.strings | 1 + .../de.lproj/Localizable.strings | 1 + .../en.lproj/Localizable.strings | 1 + .../es.lproj/Localizable.strings | 1 + .../fr.lproj/Localizable.strings | 1 + .../ja.lproj/Localizable.strings | 1 + .../pt.lproj/Localizable.strings | 1 + .../ro.lproj/Localizable.strings | 1 + .../ru.lproj/Localizable.strings | 1 + .../template.lproj/Localizable.strings | 2 + .../tr.lproj/Localizable.strings | 1 + .../vi.lproj/Localizable.strings | 1 + .../zh_TW.lproj/Localizable.strings | 1 + 15 files changed, 55 insertions(+), 17 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index 94bccaf..7861547 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -108,13 +108,13 @@ static const NSInteger YTLiteSection = 789; # pragma mark - Copy and Paste Settings YTSettingsSectionItem *copySettings = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"COPY_SETTINGS") - titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"COPY_SETTINGS_DESC_2") : LOC(@"COPY_SETTINGS_DESC") + titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"EXPORT_SETTINGS_DESC") : LOC(@"COPY_SETTINGS_DESC") accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { if (IS_ENABLED(@"switchCopyandPasteFunctionality_enabled")) { // Export Settings functionality - NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"exported_settings.txt"]]; + NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"YTLitePlusSettings.txt"]]; NSMutableString *settingsString = [NSMutableString string]; for (NSString *key in NSUserDefaultsCopyKeys) { id value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; @@ -146,7 +146,7 @@ static const NSInteger YTLiteSection = 789; [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings copied"]]; } // Prompt to export YouTube Plus settings - UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" message:@"Note: This cannot save iSponsorBlock and most YouTube settings.\nWould you like to also export your YouTube Plus Settings?" preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" message:@"Note: This feature cannot save iSponsorBlock and most YouTube settings.\n\nWould you like to also export your YouTube Plus Settings?" preferredStyle:UIAlertControllerStyleAlert]; [exportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; [exportAlert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // Export YouTube Plus Settings functionality @@ -160,7 +160,7 @@ static const NSInteger YTLiteSection = 789; YTSettingsSectionItem *pasteSettings = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"PASTE_SETTINGS") - titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"PASTE_SETTINGS_DESC_2") : LOC(@"PASTE_SETTINGS_DESC") + titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"IMPORT_SETTINGS_DESC") : LOC(@"PASTE_SETTINGS_DESC") accessibilityIdentifier:nil detailTextBlock:nil selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { @@ -170,7 +170,6 @@ static const NSInteger YTLiteSection = 789; documentPicker.delegate = (id)self; documentPicker.allowsMultipleSelection = NO; [settingsViewController presentViewController:documentPicker animated:YES completion:nil]; - return YES; } else { // Paste Settings functionality (DEFAULT - Pastes from Clipboard) UIAlertController *confirmPasteAlert = [UIAlertController alertControllerWithTitle:LOC(@"PASTE_SETTINGS_ALERT") message:nil preferredStyle:UIAlertControllerStyleAlert]; @@ -194,6 +193,8 @@ static const NSInteger YTLiteSection = 789; }]]; [settingsViewController presentViewController:confirmPasteAlert animated:YES completion:nil]; } + // Show a toast message to confirm the action + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings pasted"]]; // Reminder to import YouTube Plus settings UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" message:@"Remember to import your YouTube Plus settings as well." @@ -689,23 +690,45 @@ static const NSInteger YTLiteSection = 789; // Implement the delegate method for document picker %new - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls { - NSURL *pickedURL = [urls firstObject]; - - if (pickedURL) { - // Use AVPlayerViewController to play the video - AVPlayer *player = [AVPlayer playerWithURL:pickedURL]; - AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; - playerViewController.player = player; - + if (urls.count > 0) { + NSURL *pickedURL = [urls firstObject]; + NSError *error; + NSString *fileType = [pickedURL resourceValuesForKeys:@[NSURLTypeIdentifierKey] error:&error][NSURLTypeIdentifierKey]; + UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; - if (settingsViewController) { - [settingsViewController presentViewController:playerViewController animated:YES completion:^{ - [player play]; - }]; + + if (UTTypeConformsTo((__bridge CFStringRef)fileType, kUTTypePlainText)) { + // This block handles the import of settings from a text file. + NSString *fileContents = [NSString stringWithContentsOfURL:pickedURL encoding:NSUTF8StringEncoding error:nil]; + NSArray *lines = [fileContents componentsSeparatedByString:@"\n"]; + for (NSString *line in lines) { + NSArray *components = [line componentsSeparatedByString:@": "]; + if (components.count == 2) { + NSString *key = components[0]; + NSString *value = components[1]; + [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + } + } + if ([settingsViewController respondsToSelector:@selector(reloadData)]) { + // Call a custom reloadData method if it exists + [settingsViewController performSelector:@selector(reloadData)]; + } + } else if (UTTypeConformsTo((__bridge CFStringRef)fileType, kUTTypeMovie)) { + // This block handles video playback using AVPlayer and AVPlayerViewController. + AVPlayer *player = [AVPlayer playerWithURL:pickedURL]; + AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; + playerViewController.player = player; + + if (settingsViewController) { + [settingsViewController presentViewController:playerViewController animated:YES completion:^{ + [player play]; + }]; + } } } } + %new - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller { // Handle cancellation if needed diff --git a/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings index a577d98..bbca947 100644 --- a/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ar.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings b/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings index 4689437..1bf547f 100644 --- a/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/bg.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Копиране на всички текущи настройки в клипборда"; "PASTE_SETTINGS" = "Поставяне на настройки"; "PASTE_SETTINGS_DESC" = "Поставяне на настройки от клипборда и прилагане"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Експортиране на настройки"; "EXPORT_SETTINGS_DESC" = "Експортиране на всички текущи настройки в .txt файл"; "IMPORT_SETTINGS" = "Импортиране на настройки"; diff --git a/lang/YTLitePlus.bundle/de.lproj/Localizable.strings b/lang/YTLitePlus.bundle/de.lproj/Localizable.strings index 76a63fe..18e8820 100644 --- a/lang/YTLitePlus.bundle/de.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/de.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/en.lproj/Localizable.strings b/lang/YTLitePlus.bundle/en.lproj/Localizable.strings index 9801761..a892a2f 100644 --- a/lang/YTLitePlus.bundle/en.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/en.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/es.lproj/Localizable.strings b/lang/YTLitePlus.bundle/es.lproj/Localizable.strings index 1cf7433..739f5dd 100644 --- a/lang/YTLitePlus.bundle/es.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/es.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings b/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings index e788b97..b493803 100644 --- a/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/fr.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings index 2749ff2..ea2c349 100644 --- a/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ja.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "現在のすべての設定をクリップボードにコピーします"; "PASTE_SETTINGS" = "設定を貼り付け"; "PASTE_SETTINGS_DESC" = "クリップボードから設定を貼り付けて適用します"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings b/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings index df987ed..db9ffcb 100644 --- a/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/pt.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copia todas as configurações atuais para a área de transferência"; "PASTE_SETTINGS" = "Colar Configurações"; "PASTE_SETTINGS_DESC" = "Cola as configurações da área de transferência e aplica"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Exportar Configurações"; "EXPORT_SETTINGS_DESC" = "Exporta todas as configurações atuais para um arquivo .txt"; "IMPORT_SETTINGS" = "Importar Configurações"; diff --git a/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings index 343c226..86905e3 100644 --- a/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ro.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings b/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings index 5e6bb59..b09cc70 100644 --- a/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/ru.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/template.lproj/Localizable.strings b/lang/YTLitePlus.bundle/template.lproj/Localizable.strings index 413a20a..308b84c 100644 --- a/lang/YTLitePlus.bundle/template.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/template.lproj/Localizable.strings @@ -21,6 +21,8 @@ https://github.com/PoomSmart/Return-YouTube-Dislikes/tree/main/layout/Library/Ap "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; + "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings b/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings index a9b0ea3..a845fe7 100644 --- a/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/tr.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Tüm mevcut ayarları panoya kopyala"; "PASTE_SETTINGS" = "Ayarları Yapıştır"; "PASTE_SETTINGS_DESC" = "Panodaki ayarları yapıştır ve uygula"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Ayarları Dışa Aktar"; "EXPORT_SETTINGS_DESC" = "Tüm mevcut ayarları bir .txt dosyasına dışa aktarır"; "IMPORT_SETTINGS" = "Ayarları İçe Aktar"; diff --git a/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings b/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings index dd3fdb0..d2c81b3 100644 --- a/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/vi.lproj/Localizable.strings @@ -6,6 +6,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; diff --git a/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings b/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings index aef5cf3..e48afb9 100644 --- a/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings +++ b/lang/YTLitePlus.bundle/zh_TW.lproj/Localizable.strings @@ -7,6 +7,7 @@ "COPY_SETTINGS_DESC" = "Copy all current settings to the clipboard"; "PASTE_SETTINGS" = "Paste Settings"; "PASTE_SETTINGS_DESC" = "Paste settings from clipboard and apply"; +"PASTE_SETTINGS_ALERT" = "Apply settings from clipboard?"; "EXPORT_SETTINGS" = "Export Settings"; "EXPORT_SETTINGS_DESC" = "Exports all current settings into a .txt file"; "IMPORT_SETTINGS" = "Import Settings"; From 6996c0ed66543c17df8bb012e0c8c8321cb3360b Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Mon, 26 Aug 2024 01:46:52 -0700 Subject: [PATCH 5/7] Add keys, fix toasts --- Source/Settings.xm | 13 +++++-------- Source/SettingsKeys.h | 5 +++-- Source/get_keys.py | 4 ++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index 456959f..00e78c0 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -191,11 +191,9 @@ static const NSInteger YTLiteSection = 789; }]]; [settingsViewController presentViewController:confirmPasteAlert animated:YES completion:nil]; } - // Show a toast message to confirm the action - [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings pasted"]]; // Reminder to import YouTube Plus settings UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" - message:@"Remember to import your YouTube Plus settings as well." + message:@"Remember to import your YouTube Plus settings as well" preferredStyle:UIAlertControllerStyleAlert]; [reminderAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; [settingsViewController presentViewController:reminderAlert animated:YES completion:nil]; @@ -678,7 +676,7 @@ static const NSInteger YTLiteSection = 789; NSError *error; NSString *fileType = [pickedURL resourceValuesForKeys:@[NSURLTypeIdentifierKey] error:&error][NSURLTypeIdentifierKey]; - UIViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; + YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; if (UTTypeConformsTo((__bridge CFStringRef)fileType, kUTTypePlainText)) { // This block handles the import of settings from a text file. @@ -692,10 +690,9 @@ static const NSInteger YTLiteSection = 789; [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; } } - if ([settingsViewController respondsToSelector:@selector(reloadData)]) { - // Call a custom reloadData method if it exists - [settingsViewController performSelector:@selector(reloadData)]; - } + [settingsViewController reloadData]; + // Show a toast message to confirm the action + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings applied"]]; } } } diff --git a/Source/SettingsKeys.h b/Source/SettingsKeys.h index 384f08b..d18b4e8 100644 --- a/Source/SettingsKeys.h +++ b/Source/SettingsKeys.h @@ -17,8 +17,9 @@ NSArray *NSUserDefaultsCopyKeys = @[ @"hideHomeTab_enabled", @"hidePreviewCommentSection_enabled", @"hideRightPanel_enabled", @"hideSpeedToast_enabled", @"hideSponsorBlockButton_enabled", @"hideVideoPlayerShadowOverlayButtons_enabled", @"iPadLayout_enabled", @"iPhoneLayout_enabled", @"inline_muted_playback_enabled", @"lowContrastMode_enabled", - @"newSettingsUI_enabled", @"oledKeyBoard_enabled", @"playerGestures_enabled", @"seekAnywhere_enabled", - @"switchCopyandPasteFunctionality_enabled", @"ytNoModernUI_enabled", @"ytStartupAnimation_enabled", + @"newSettingsUI_enabled", @"oledKeyBoard_enabled", @"playerGesturesHapticFeedback_enabled", + @"playerGestures_enabled", @"seekAnywhere_enabled", @"switchCopyandPasteFunctionality_enabled", + @"videoPlayerButton_enabled", @"ytNoModernUI_enabled", @"ytStartupAnimation_enabled", // DEMC - https://github.com/therealFoxster/DontEatMyContent/blob/master/Tweak.h @"DEMC_enabled", @"DEMC_colorViewsEnabled", @"DEMC_safeAreaConstant", @"DEMC_disableAmbientMode", @"DEMC_limitZoomToFill", @"DEMC_enableForAllVideos", diff --git a/Source/get_keys.py b/Source/get_keys.py index e763e3a..dd6f221 100644 --- a/Source/get_keys.py +++ b/Source/get_keys.py @@ -61,6 +61,7 @@ def find_and_extract_keys(): Recursively searches for .xm and .h files in the parent directory and extracts keys that match the pattern @\"_enabled\". The matching keys are then printed with indentation and line breaks if the line exceeds 120 characters. + Ignores SettingsKeys.h Usage: 1. Place this script in the desired directory. @@ -82,6 +83,9 @@ def find_and_extract_keys(): for root, dirs, files in os.walk(parent_directory): for file in files: if file.endswith(('.xm', '.h')): + # Skip SettingsKeys.h + if file == "SettingsKeys.h": + continue file_path = os.path.join(root, file) found_keys.update(extract_values_from_file(file_path)) From 09721d4b3a37792f4d25cc3c44ca3a610f83f07a Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:31:00 -0700 Subject: [PATCH 6/7] Fix reminder popups --- Source/Settings.xm | 107 ++++++++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index 00e78c0..d6212fb 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -105,7 +105,7 @@ static const NSInteger YTLiteSection = 789; # pragma mark - Copy and Paste Settings YTSettingsSectionItem *copySettings = [%c(YTSettingsSectionItem) - itemWithTitle:LOC(@"COPY_SETTINGS") + itemWithTitle:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"EXPORT_SETTINGS") : LOC(@"COPY_SETTINGS") titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"EXPORT_SETTINGS_DESC") : LOC(@"COPY_SETTINGS_DESC") accessibilityIdentifier:nil detailTextBlock:nil @@ -116,7 +116,11 @@ static const NSInteger YTLiteSection = 789; NSMutableString *settingsString = [NSMutableString string]; for (NSString *key in NSUserDefaultsCopyKeys) { id value = [[NSUserDefaults standardUserDefaults] objectForKey:key]; - if (value) { + id defaultValue = NSUserDefaultsCopyKeysDefaults[key]; + + // Only include the setting if it is different from the default value + // If no default value is found, include it by default + if (value && (!defaultValue || ![value isEqual:defaultValue])) { [settingsString appendFormat:@"%@: %@\n", key, value]; } } @@ -142,22 +146,31 @@ static const NSInteger YTLiteSection = 789; [[UIPasteboard generalPasteboard] setString:settingsString]; // Show a confirmation message or perform some other action here [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings copied"]]; + + // Show an option to export YouTube Plus settings + UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" + message:@"Note: This feature cannot save iSponsorBlock and most YouTube settings.\n\nWould you like to also export your YouTube Plus Settings?" + preferredStyle:UIAlertControllerStyleAlert]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + // Export YouTube Plus Settings functionality + [%c(YTLUserDefaults) exportYtlSettings]; + }]]; + + // Get the root view controller + UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; + + // Present the alert from the root view controller + [rootViewController presentViewController:exportAlert animated:YES completion:nil]; } - // Prompt to export YouTube Plus settings - UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" message:@"Note: This feature cannot save iSponsorBlock and most YouTube settings.\n\nWould you like to also export your YouTube Plus Settings?" preferredStyle:UIAlertControllerStyleAlert]; - [exportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; - [exportAlert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - // Export YouTube Plus Settings functionality - [%c(YTLUserDefaults) exportYtlSettings]; - }]]; - [settingsViewController presentViewController:exportAlert animated:YES completion:nil]; + return YES; } ]; [sectionItems addObject:copySettings]; YTSettingsSectionItem *pasteSettings = [%c(YTSettingsSectionItem) - itemWithTitle:LOC(@"PASTE_SETTINGS") + itemWithTitle:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"IMPORT_SETTINGS") : LOC(@"PASTE_SETTINGS") titleDescription:IS_ENABLED(@"switchCopyandPasteFunctionality_enabled") ? LOC(@"IMPORT_SETTINGS_DESC") : LOC(@"PASTE_SETTINGS_DESC") accessibilityIdentifier:nil detailTextBlock:nil @@ -183,20 +196,20 @@ static const NSInteger YTLiteSection = 789; NSString *value = components[1]; [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; } - } + } [settingsViewController reloadData]; - // Show a confirmation message or perform some other action here + // Show a confirmation toast [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings applied"]]; + // Show a reminder to import YouTube Plus settings as well + UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" + message:@"Remember to import your YouTube Plus settings as well" + preferredStyle:UIAlertControllerStyleAlert]; + [reminderAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; + [settingsViewController presentViewController:reminderAlert animated:YES completion:nil]; } }]]; [settingsViewController presentViewController:confirmPasteAlert animated:YES completion:nil]; } - // Reminder to import YouTube Plus settings - UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" - message:@"Remember to import your YouTube Plus settings as well" - preferredStyle:UIAlertControllerStyleAlert]; - [reminderAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; - [settingsViewController presentViewController:reminderAlert animated:YES completion:nil]; return YES; } @@ -674,25 +687,49 @@ static const NSInteger YTLiteSection = 789; if (urls.count > 0) { NSURL *pickedURL = [urls firstObject]; NSError *error; - NSString *fileType = [pickedURL resourceValuesForKeys:@[NSURLTypeIdentifierKey] error:&error][NSURLTypeIdentifierKey]; + // Check which mode the document picker is in + if (controller.documentPickerMode == UIDocumentPickerModeImport) { + // Import mode: Handle the import of settings from a text file + NSString *fileType = [pickedURL resourceValuesForKeys:@[NSURLTypeIdentifierKey] error:&error][NSURLTypeIdentifierKey]; - YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; - - if (UTTypeConformsTo((__bridge CFStringRef)fileType, kUTTypePlainText)) { - // This block handles the import of settings from a text file. - NSString *fileContents = [NSString stringWithContentsOfURL:pickedURL encoding:NSUTF8StringEncoding error:nil]; - NSArray *lines = [fileContents componentsSeparatedByString:@"\n"]; - for (NSString *line in lines) { - NSArray *components = [line componentsSeparatedByString:@": "]; - if (components.count == 2) { - NSString *key = components[0]; - NSString *value = components[1]; - [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + if (UTTypeConformsTo((__bridge CFStringRef)fileType, kUTTypePlainText)) { + NSString *fileContents = [NSString stringWithContentsOfURL:pickedURL encoding:NSUTF8StringEncoding error:nil]; + NSArray *lines = [fileContents componentsSeparatedByString:@"\n"]; + for (NSString *line in lines) { + NSArray *components = [line componentsSeparatedByString:@": "]; + if (components.count == 2) { + NSString *key = components[0]; + NSString *value = components[1]; + [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; + } } + // Reload settings view after importing + YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; + [settingsViewController reloadData]; + // Show a confirmation message or perform some other action here + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings applied"]]; + // Show a reminder to import YouTube Plus settings as well + UIAlertController *reminderAlert = [UIAlertController alertControllerWithTitle:@"Reminder" + message:@"Remember to import your YouTube Plus settings as well" + preferredStyle:UIAlertControllerStyleAlert]; + [reminderAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; + [settingsViewController presentViewController:reminderAlert animated:YES completion:nil]; } - [settingsViewController reloadData]; - // Show a toast message to confirm the action - [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings applied"]]; + + } else if (controller.documentPickerMode == UIDocumentPickerModeExportToService || controller.documentPickerMode == UIDocumentPickerModeMoveToService) { + [[%c(GOOHUDManagerInternal) sharedInstance] showMessageMainThread:[%c(YTHUDMessage) messageWithText:@"Settings saved"]]; + // Export mode: Display a reminder to save YouTube Plus settings + UIAlertController *exportAlert = [UIAlertController alertControllerWithTitle:@"Export Settings" + message:@"Note: This feature cannot save iSponsorBlock and most YouTube settings.\n\nWould you like to also export your YouTube Plus Settings?" + preferredStyle:UIAlertControllerStyleAlert]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; + [exportAlert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + // Export YouTube Plus Settings functionality + [%c(YTLUserDefaults) exportYtlSettings]; + }]]; + YTSettingsViewController *settingsViewController = [self valueForKey:@"_settingsViewControllerDelegate"]; + // Present the alert from the root view controller + [settingsViewController presentViewController:exportAlert animated:YES completion:nil]; } } } From 5fb849297adcb1e60f9f078e00b5b7cbf5f8531d Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Mon, 26 Aug 2024 23:12:24 -0700 Subject: [PATCH 7/7] Fix bug with reminder again --- Source/Settings.xm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Settings.xm b/Source/Settings.xm index d6212fb..418d6f4 100644 --- a/Source/Settings.xm +++ b/Source/Settings.xm @@ -156,12 +156,8 @@ static const NSInteger YTLiteSection = 789; // Export YouTube Plus Settings functionality [%c(YTLUserDefaults) exportYtlSettings]; }]]; - - // Get the root view controller - UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; - // Present the alert from the root view controller - [rootViewController presentViewController:exportAlert animated:YES completion:nil]; + [settingsViewController presentViewController:exportAlert animated:YES completion:nil]; } return YES;