-
Notifications
You must be signed in to change notification settings - Fork 2
/
Spring.x
167 lines (118 loc) · 4.37 KB
/
Spring.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#import "Visualizers/DPWaveEqualizerView.h"
#import "SharedInfo.h"
@interface SBDashBoardMediaArtworkViewController : UIViewController
@end
@interface SBLockScreenNowPlayingController : NSObject
@property (assign, getter=isEnabled, nonatomic) BOOL enabled;
@end
@interface VolumeControl : NSObject
+ (instancetype)sharedVolumeControl;
- (float)getMediaVolume;
@end
@interface SBFLockScreenDateView : UIView
@end
@interface SBLockScreenDateViewController : UIViewController
@end
@interface MPULockScreenVolumeSlider : UISlider
@end
static DPMainEqualizerView *equalizerView = NULL;
static SBLockScreenNowPlayingController *sblsNowPlayingController = NULL;
static BOOL isShowingMusic = NO;
static void relayedMessageCallBack(CFMachPortRef port, LMMessage *request, CFIndex size, void *info) {
if (equalizerView) {
if ((size_t)size < sizeof(LMMessage)) {
// some kind of bad message
return;
}
float *buffer = LMMessageGetData(request);
unsigned bufferSize = LMMessageGetDataLength(request)/sizeof(float);
[equalizerView updateBuffer:buffer withBufferSize:bufferSize];
}
}
static void updateVolumeGain() {
if (equalizerView) {
VolumeControl *volControl = [%c(VolumeControl) sharedVolumeControl];
// I've been told by music lovers that gain is not volume, however it looks cool
equalizerView.equalizerSettings.gain = volControl.getMediaVolume*20;
}
}
static UIImage *cirlceImageWithDiameter(CGFloat size) {
CGRect rect = CGRectMake(0, 0, size, size);
// 3.0, hardcoded for Plus devices
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 3.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, UIColor.whiteColor.CGColor);
CGContextFillEllipseInRect(context, rect);
CGContextSaveGState(context);
UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return ret;
}
// Update visualizer's gain with any volume change
%hook SBMediaController
- (void)_systemVolumeChanged:(id)arg1 {
%orig;
updateVolumeGain();
}
%end
%hook SBDashBoardMediaArtworkViewController
- (void)viewWillAppear:(BOOL)animated {
%orig;
isShowingMusic = YES;
notify_post(kNotifyShouldSendKey);
}
- (void)viewDidDisappear:(BOOL)animated {
%orig;
isShowingMusic = NO;
notify_post(kNotifyShouldStopKey);
}
- (void)viewDidLoad {
%orig;
DPEqualizerSettings *settings = [DPEqualizerSettings create];
CGFloat const equalizerViewHeight = 836;
// the waves start at half way down the view, so half of the total height is the top of the screen, assuming y == 0
// subtract twenty so it doesn't go exactly to the top of the screen
settings.maxBinHeight = equalizerViewHeight/2 - 20;
// Hardcoded Plus sized location
equalizerView = [[DPWaveEqualizerView alloc] initWithFrame:CGRectMake(0, 0, 414, equalizerViewHeight) andSettings:settings];
equalizerView.lowFrequencyColor = [UIColor colorWithWhite:0.9 alpha:1];
equalizerView.hightFrequencyColor = [UIColor colorWithWhite:0.9 alpha:1];
equalizerView.backgroundColor = UIColor.clearColor;
updateVolumeGain();
[self.view addSubview:equalizerView];
}
%end
// Get and store mediaController instance
%hook SBLockScreenNowPlayingController
- (SBLockScreenNowPlayingController *)initWithMediaController:(id)mediaController {
return sblsNowPlayingController = %orig;
}
%end
// Make the Volume Slider thumb not so large
%hook MPULockScreenVolumeSlider
- (id)init {
if ((self = %orig)) {
[self setThumbImage:cirlceImageWithDiameter(12) forState:UIControlStateNormal];
[self setThumbImage:cirlceImageWithDiameter(24) forState:UIControlStateHighlighted];
}
return self;
}
%end
// Properly hide media if a notification is presenting
%hook SBDashBoardNotificationListViewController
- (BOOL)hasContent {
BOOL ret = %orig;
sblsNowPlayingController.enabled = !ret;
return ret;
}
%end
// Disable sleeping on the lockscreen if music is showing
%hook SBDashBoardIdleTimerEventPublisher
- (BOOL)isEnabled {
return isShowingMusic ? NO : %orig;
}
%end
// Listen for messages from mediaserverd
%ctor {
LMStartService(interprocSpringMedia.serverName, CFRunLoopGetMain(), (CFMachPortCallBack)relayedMessageCallBack);
}