Skip to content

Commit

Permalink
NSBundle category
Browse files Browse the repository at this point in the history
  • Loading branch information
dayanch96 committed Apr 1, 2024
1 parent 141ee73 commit cf133a7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
18 changes: 2 additions & 16 deletions Source/Headers/Localization.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
#import <Foundation/Foundation.h>
#import <rootless.h>
#import "../Utils/NSBundle+YTMU.h"
#import "ABCSwitch.h"

static inline NSBundle *YTMusicUltimateBundle() {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *tweakBundlePath = [[NSBundle mainBundle] pathForResource:@"YTMusicUltimate" ofType:@"bundle"];
NSString *rootlessBundlePath = ROOT_PATH_NS(@"/Library/Application Support/YTMusicUltimate.bundle");

bundle = [NSBundle bundleWithPath:tweakBundlePath ?: rootlessBundlePath];
});

return bundle;
}

static inline NSString *LOC(NSString *key) {
return [YTMusicUltimateBundle() localizedStringForKey:key value:nil table:nil];
}
#define LOC(key) [NSBundle.ytmu_defaultBundle localizedStringForKey:key value:nil table:nil]
2 changes: 1 addition & 1 deletion Source/Prefs/TabBarSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ - (UIImage *)tbImageNamed:(NSString *)imageName {

UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(24, 24)];
UIImage *downloadsImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
UIImage *buttonImage = [UIImage imageWithContentsOfFile:[YTMusicUltimateBundle() pathForResource:@"downloads" ofType:@"png" inDirectory:@"icons"]];
UIImage *buttonImage = [UIImage imageWithContentsOfFile:[NSBundle.ytmu_defaultBundle pathForResource:@"downloads" ofType:@"png" inDirectory:@"icons"]];
UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
UIImageView *buttonImageView = [[UIImageView alloc] initWithImage:buttonImage];
buttonImageView.contentMode = UIViewContentModeScaleAspectFit;
Expand Down
2 changes: 1 addition & 1 deletion Source/Prefs/YTMUltimateSettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.detailTextLabel.text = settingData[@"detail"];
cell.detailTextLabel.numberOfLines = 0;

UIImage *image = [UIImage imageWithContentsOfFile:[YTMusicUltimateBundle() pathForResource:settingData[@"image"] ofType:@"png" inDirectory:@"icons"]];
UIImage *image = [UIImage imageWithContentsOfFile:[NSBundle.ytmu_defaultBundle pathForResource:settingData[@"image"] ofType:@"png" inDirectory:@"icons"]];
cell.imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
cell.detailTextLabel.textColor = [UIColor secondaryLabelColor];

Expand Down
12 changes: 12 additions & 0 deletions Source/Utils/NSBundle+YTMU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <Foundation/Foundation.h>
#import <rootless.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSBundle (YTMusicUltimate)

@property (class, nonatomic, readonly) NSBundle *ytmu_defaultBundle;

@end

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions Source/Utils/NSBundle+YTMU.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import "NSBundle+YTMU.h"

@implementation NSBundle (YTMusicUltimate)

+ (NSBundle *)ytmu_defaultBundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
NSString *tweakBundlePath = [[NSBundle mainBundle] pathForResource:@"YTMusicUltimate" ofType:@"bundle"];
NSString *rootlessBundlePath = ROOT_PATH_NS(@"/Library/Application Support/YTMusicUltimate.bundle");

bundle = [NSBundle bundleWithPath:tweakBundlePath ?: rootlessBundlePath];
});

return bundle;
}

@end
2 changes: 1 addition & 1 deletion Source/YTMTab.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static BOOL YTMU(NSString *key) {
NSString *imageName = isSelected ? @"downloads_selected" : @"downloads";
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(24, 24)];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
UIImage *buttonImage = [UIImage imageWithContentsOfFile:[YTMusicUltimateBundle() pathForResource:imageName ofType:@"png" inDirectory:@"icons"]];
UIImage *buttonImage = [UIImage imageWithContentsOfFile:[NSBundle.ytmu_defaultBundle pathForResource:imageName ofType:@"png" inDirectory:@"icons"]];
UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
UIImageView *buttonImageView = [[UIImageView alloc] initWithImage:buttonImage];
buttonImageView.contentMode = UIViewContentModeScaleAspectFit;
Expand Down

0 comments on commit cf133a7

Please sign in to comment.