-
Notifications
You must be signed in to change notification settings - Fork 11
/
Tweak.x
112 lines (85 loc) · 3.39 KB
/
Tweak.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#import "../YTVideoOverlay/Header.h"
#import "../YTVideoOverlay/Init.x"
#import <YouTubeHeader/YTColor.h>
#import <YouTubeHeader/YTMainAppVideoPlayerOverlayViewController.h>
#import <YouTubeHeader/YTSingleVideoController.h>
#define TweakKey @"YouMute"
@interface YTMainAppControlsOverlayView (YouMute)
@property (retain, nonatomic) YTQTMButton *muteButton;
- (void)didPressMute:(id)arg;
@end
@interface YTInlinePlayerBarContainerView (YouMute)
@property (retain, nonatomic) YTQTMButton *muteButton;
- (void)didPressMute:(id)arg;
@end
static BOOL isMutedTop(YTMainAppControlsOverlayView *self) {
YTMainAppVideoPlayerOverlayViewController *c = [self valueForKey:@"_eventsDelegate"];
YTSingleVideoController *video = [c valueForKey:@"_currentSingleVideoObservable"];
return [video isMuted];
}
static BOOL isMutedBottom(YTInlinePlayerBarContainerView *self) {
YTSingleVideoController *video = [self.delegate valueForKey:@"_currentSingleVideo"];
return [video isMuted];
}
static NSBundle *YTEditResourcesBundle() {
NSBundle *editBundle = [NSBundle bundleForClass:%c(YTEditBundleIdentifier)];
return [NSBundle bundleWithPath:[[editBundle bundlePath] stringByAppendingPathComponent:@"Edit_Resources.bundle"]];
}
static UIImage *muteImage(BOOL muted) {
return [%c(QTMIcon) tintImage:[UIImage imageNamed:muted ? @"ic_volume_off" : @"ic_volume_up" inBundle:YTEditResourcesBundle() compatibleWithTraitCollection:nil] color:[%c(YTColor) white1]];
}
%group Top
%hook YTMainAppControlsOverlayView
%property (retain, nonatomic) YTQTMButton *muteButton;
- (id)initWithDelegate:(id)delegate {
self = %orig;
self.muteButton = [self createButton:TweakKey accessibilityLabel:@"Mute" selector:@selector(didPressMute:)];
return self;
}
- (id)initWithDelegate:(id)delegate autoplaySwitchEnabled:(BOOL)autoplaySwitchEnabled {
self = %orig;
self.muteButton = [self createButton:TweakKey accessibilityLabel:@"Mute" selector:@selector(didPressMute:)];
return self;
}
- (YTQTMButton *)button:(NSString *)tweakId {
return [tweakId isEqualToString:TweakKey] ? self.muteButton : %orig;
}
- (UIImage *)buttonImage:(NSString *)tweakId {
return [tweakId isEqualToString:TweakKey] ? muteImage(isMutedTop(self)) : %orig;
}
%new(v@:@)
- (void)didPressMute:(id)arg {
YTMainAppVideoPlayerOverlayViewController *c = [self valueForKey:@"_eventsDelegate"];
YTSingleVideoController *video = [c valueForKey:@"_currentSingleVideoObservable"];
[video setMuted:![video isMuted]];
[self.muteButton setImage:muteImage([video isMuted]) forState:0];
}
%end
%end
%group Bottom
%hook YTInlinePlayerBarContainerView
%property (retain, nonatomic) YTQTMButton *muteButton;
- (id)init {
self = %orig;
self.muteButton = [self createButton:TweakKey accessibilityLabel:@"Mute" selector:@selector(didPressMute:)];
return self;
}
- (YTQTMButton *)button:(NSString *)tweakId {
return [tweakId isEqualToString:TweakKey] ? self.muteButton : %orig;
}
- (UIImage *)buttonImage:(NSString *)tweakId {
return [tweakId isEqualToString:TweakKey] ? muteImage(isMutedBottom(self)) : %orig;
}
%new(v@:@)
- (void)didPressMute:(id)arg {
YTSingleVideoController *video = [self.delegate valueForKey:@"_currentSingleVideo"];
[video setMuted:![video isMuted]];
[self.muteButton setImage:muteImage([video isMuted]) forState:0];
}
%end
%end
%ctor {
initYTVideoOverlay(TweakKey);
%init(Top);
%init(Bottom);
}