From ddb0a37cc814a5182c070312ec45c4e0d64220c6 Mon Sep 17 00:00:00 2001 From: "aricloverGitHub (INACTIVE)" <78001398+arichornlover@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:04:02 -0600 Subject: [PATCH] Added Clear Cache (uYouPlusSettings.xm) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based off of YTLite’s Version of ClearCache. Credit: Dayanch96 --- Sources/uYouPlusSettings.xm | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Sources/uYouPlusSettings.xm b/Sources/uYouPlusSettings.xm index 09b913c..84c4d4a 100644 --- a/Sources/uYouPlusSettings.xm +++ b/Sources/uYouPlusSettings.xm @@ -64,6 +64,22 @@ SWITCH3( ); */ +static NSString *GetCacheSize() { // YTLite - @dayanch96 + NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject; + NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:cachePath error:nil]; + + unsigned long long int folderSize = 0; + for (NSString *fileName in filesArray) { + NSString *filePath = [cachePath stringByAppendingPathComponent:fileName]; + NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; + folderSize += [fileAttributes fileSize]; + } + + NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init]; + formatter.countStyle = NSByteCountFormatterCountStyleFile; + + return [formatter stringFromByteCount:folderSize]; +} static int contrastMode() { NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSComparisonResult result1 = [appVersion compare:@"17.33.2" options:NSNumericSearch]; @@ -314,6 +330,27 @@ extern NSBundle *uYouPlusBundle(); ]; [sectionItems addObject:appIcon]; +YTSettingsSectionItem *clearCache = [%c(YTSettingsSectionItem) + itemWithTitle:LOC(@"Clear Cache") + titleDescription:nil + accessibilityIdentifier:nil + detailTextBlock:^NSString *() { + return GetCacheSize(); + } + selectBlock:^BOOL (YTSettingsCell *cell, NSUInteger arg1) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject; + [[NSFileManager defaultManager] removeItemAtPath:cachePath error:nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + [cell setDetailText:GetCacheSize()]; + [[%c(YTToastResponderEvent) eventWithMessage:LOC(@"Done") firstResponder:[self parentResponder]] send]; + }); + }); + return YES; + } +]; +[sectionItems addObject:clearCache]; + YTSettingsSectionItem *clearNotifications = [%c(YTSettingsSectionItem) itemWithTitle:LOC(@"CLEAR_NOTIFICATIONS") titleDescription:LOC(@"CLEAR_NOTIFICATIONS_DESC")