diff --git a/Source/SelectableLyrics.xm b/Source/SelectableLyrics.xm index cb8a9a19..34b993c9 100644 --- a/Source/SelectableLyrics.xm +++ b/Source/SelectableLyrics.xm @@ -5,7 +5,9 @@ static BOOL YTMU(NSString *key) { return [YTMUltimateDict[key] boolValue]; } -static BOOL selectableLyrics = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"selectableLyrics"); +static BOOL shouldShowSelectableLyrics() { + return YTMU(@"YTMUltimateIsEnabled") && YTMU(@"selectableLyrics"); +} @interface YTFormattedStringLabel : UILabel @end @@ -16,11 +18,9 @@ static BOOL selectableLyrics = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"selectabl %hook YTMLightweightMusicDescriptionShelfCell -%property (retain, nonatomic) UITextView *lyrics; - - (id)initWithFrame:(CGRect)frame { self = %orig; - if (self && selectableLyrics) { + if (self && shouldShowSelectableLyrics()) { UIView *container = [self valueForKey:@"_descriptionContainer"]; self.lyrics = [[UITextView alloc] init]; self.lyrics.backgroundColor = [UIColor clearColor]; @@ -35,7 +35,7 @@ static BOOL selectableLyrics = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"selectabl - (void)setRenderer:(id)renderer { %orig; - if (selectableLyrics) { + if (shouldShowSelectableLyrics()) { YTFormattedStringLabel *lyrics = [self valueForKey:@"_descriptionLabel"]; lyrics.userInteractionEnabled = YES; lyrics.hidden = YES; @@ -48,7 +48,7 @@ static BOOL selectableLyrics = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"selectabl - (void)layoutSubviews { %orig; - if (selectableLyrics) { + if (shouldShowSelectableLyrics()) { YTFormattedStringLabel *lyrics = [self valueForKey:@"_descriptionLabel"]; self.lyrics.frame = lyrics.frame; } diff --git a/Source/SponsorBlock.xm b/Source/SponsorBlock.xm index 995095c3..25c3efbc 100644 --- a/Source/SponsorBlock.xm +++ b/Source/SponsorBlock.xm @@ -8,7 +8,6 @@ #define ytmuInt(key) [[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"YTMUltimate"][key] integerValue] %hook YTPlayerViewController -%property (nonatomic, strong) NSMutableDictionary *sponsorBlockValues; - (void)playbackController:(id)arg1 didActivateVideo:(id)arg2 withPlaybackData:(id)arg3 { %orig; @@ -17,7 +16,7 @@ self.sponsorBlockValues = [NSMutableDictionary dictionary]; - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://sponsor.ajay.app/api/skipSegments?videoID=%@&categories=%@", self.currentVideoID, @"%5B%22music_offtopic%22%5D"]]]; + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://sponsor.ajay.app/api/skipSegments?videoID=%@&categories=%@", [self currentVideoID], @"%5B%22music_offtopic%22%5D"]]]; [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (!error) { @@ -29,7 +28,7 @@ [segments setObject:@(1) forKey:uuid]; } - [self.sponsorBlockValues setObject:jsonResponse forKey:self.currentVideoID]; + [self.sponsorBlockValues setObject:jsonResponse forKey:[self currentVideoID]]; [self.sponsorBlockValues setObject:segments forKey:@"segments"]; } } @@ -50,8 +49,8 @@ %new - (void)skipSegment { - if (ytmuBool(@"sponsorBlock") && [NSJSONSerialization isValidJSONObject:self.sponsorBlockValues]) { - NSDictionary *sponsorBlockValues = [self.sponsorBlockValues objectForKey:self.currentVideoID]; + if (ytmuBool(@"sponsorBlock") && self.sponsorBlockValues && [self.sponsorBlockValues count] > 0) { + NSDictionary *sponsorBlockValues = [self.sponsorBlockValues objectForKey:[self currentVideoID]]; NSMutableDictionary *segmentSkipValues = [self.sponsorBlockValues objectForKey:@"segments"]; for (NSDictionary *jsonDictionary in sponsorBlockValues) { @@ -60,8 +59,8 @@ if (segmentSkipValue && [segmentSkipValue isEqual:@(1)] && [[jsonDictionary objectForKey:@"category"] isEqual:@"music_offtopic"] - && self.currentVideoMediaTime >= [[jsonDictionary objectForKey:@"segment"][0] floatValue] - && self.currentVideoMediaTime <= ([[jsonDictionary objectForKey:@"segment"][1] floatValue] - 1)) { + && [self currentVideoMediaTime] >= [[jsonDictionary objectForKey:@"segment"][0] floatValue] + && [self currentVideoMediaTime] <= ([[jsonDictionary objectForKey:@"segment"][1] floatValue] - 1)) { [segmentSkipValues setObject:@(0) forKey:uuid]; [self.sponsorBlockValues setObject:segmentSkipValues forKey:@"segments"]; @@ -107,4 +106,4 @@ } [[NSUserDefaults standardUserDefaults] setObject:mutableDict forKey:@"YTMUltimate"]; -} \ No newline at end of file +} diff --git a/Source/VolumeBar/VolumeBar.xm b/Source/VolumeBar/VolumeBar.xm index 006344be..2a13daaa 100644 --- a/Source/VolumeBar/VolumeBar.xm +++ b/Source/VolumeBar/VolumeBar.xm @@ -5,7 +5,9 @@ static BOOL YTMU(NSString *key) { return [YTMUltimateDict[key] boolValue]; } -static BOOL volumeBar = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); +static BOOL shouldShowVolumeBar() { + return YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); +} @interface YTMWatchView: UIView @property (readonly, nonatomic) BOOL isExpanded; @@ -17,12 +19,11 @@ static BOOL volumeBar = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); @end %hook YTMWatchView -%property (nonatomic, strong) GSVolBar *volumeBar; - (instancetype)initWithColorScheme:(id)scheme { self = %orig; - if (self && volumeBar) { + if (self && shouldShowVolumeBar()) { self.volumeBar = [[GSVolBar alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - (self.frame.size.width / 2) / 2, 0, self.frame.size.width / 2, 25)]; [self addSubview:self.volumeBar]; @@ -34,7 +35,7 @@ static BOOL volumeBar = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); - (void)layoutSubviews { %orig; - if (volumeBar) { + if (shouldShowVolumeBar()) { self.volumeBar.frame = CGRectMake(self.frame.size.width / 2 - (self.frame.size.width / 2) / 2, CGRectGetMinY(self.tabView.frame) - 25, self.frame.size.width / 2, 25); } } @@ -42,7 +43,7 @@ static BOOL volumeBar = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); - (void)updateColorsAfterLayoutChangeTo:(long long)arg1 { %orig; - if (volumeBar) { + if (shouldShowVolumeBar()) { [self updateVolBarVisibility]; } } @@ -50,18 +51,18 @@ static BOOL volumeBar = YTMU(@"YTMUltimateIsEnabled") && YTMU(@"volBar"); - (void)updateColorsBeforeLayoutChangeTo:(long long)arg1 { %orig; - if (volumeBar) { + if (shouldShowVolumeBar()) { self.volumeBar.hidden = YES; } } %new - (void)updateVolBarVisibility { - if (volumeBar) { + if (shouldShowVolumeBar()) { dispatch_async(dispatch_get_main_queue(), ^(void){ self.volumeBar.hidden = !(self.isExpanded && self.currentLayout == 2); }); } } -%end \ No newline at end of file +%end