-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.x
More file actions
165 lines (131 loc) · 4.71 KB
/
Tweak.x
File metadata and controls
165 lines (131 loc) · 4.71 KB
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
#import "Tweak.h"
bool shortlookInstalled = false;
static PlayingNotificationManager *notificationManager;
static PlayingManager *manager;
static PlayingPreferences *preferences;
static MediaControlsViewController *currentView;
%group MediaControllerHook
%hook SBMediaController
-(void)_setNowPlayingApplication:(SBApplication*)arg1 {
%orig;
manager.currentApp = arg1.bundleIdentifier;
}
-(void)setNowPlayingInfo:(id)arg1 {
%orig;
if(preferences.enabled) {
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, shortlookInstalled ? (NSEC_PER_SEC * 0.75) : 0);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
MRMediaRemoteGetNowPlayingInfo(dispatch_get_main_queue(), ^(CFDictionaryRef information) {
NSString *currentID = @"";
SBApplication *currentApplication = [[%c(SpringBoard) sharedApplication] _accessibilityFrontMostApplication];
if(currentApplication) {
currentID = currentApplication.bundleIdentifier;
}
bool showBanner = true;
if(manager.currentApp && ![manager.currentApp isEqualToString:@""] && currentID && ![currentID isEqualToString:@""]) {
if ([[preferences.preferences objectForKey:[@"blacklist-" stringByAppendingString:manager.currentApp]] boolValue]) {
return;
}
showBanner = ![[preferences.preferences objectForKey:[@"dontshow-" stringByAppendingString:currentID]] boolValue];
}
NSMutableDictionary *mutableInformation = [(__bridge NSDictionary *)information mutableCopy];
[mutableInformation setValue:[NSNumber numberWithBool:showBanner] forKey:@"showBanner"];
[manager setMetadata:mutableInformation];
[currentView applyPlaying];
});
});
}
}
%end
%end
%group BBServerManager
%hook BBServer
-(id)initWithQueue:(id)arg1 {
notificationManager.bbServer = %orig;
return notificationManager.bbServer;
}
-(id)initWithQueue:(id)arg1 dataProviderManager:(id)arg2 syncService:(id)arg3 dismissalSyncCache:(id)arg4 observerListener:(id)arg5 utilitiesListener:(id)arg6 conduitListener:(id)arg7 systemStateListener:(id)arg8 settingsListener:(id)arg9 {
notificationManager.bbServer = %orig;
return notificationManager.bbServer;
}
- (void)dealloc {
if (notificationManager.bbServer == self) {
notificationManager.bbServer = NULL;
}
%orig;
}
%end
%end
%group ShortLookFixer
%hook DDUserNotification
- (NSString *)senderIdentifier {
NSString *orig = %orig;
if(!preferences.asMediaApp) {
return orig;
}
if([orig isEqualToString:manager.currentApp]) {
return @"me.conorthedev.playing";
} else {
return orig;
}
}
%end
%end
%group ColouredControls
%hook MediaControlsViewController
-(void)loadView {
%orig;
[self applyPlaying];
}
-(void)viewWillAppear:(BOOL)animated {
%orig;
[self applyPlaying];
}
-(void)viewDidDisappear:(BOOL)animated {
%orig;
currentView = nil;
}
%new
-(void)applyPlaying {
MediaControlsViewController *typedSelf = ((MediaControlsViewController *) self);
if ([preferences colouredControls]) {
typedSelf.view.superview.layer.cornerRadius = 13;
typedSelf.view.superview.layer.masksToBounds = TRUE;
UIImage *artwork = [manager getArtwork];
UIColor *backgroundColor = (artwork != nil) ? [artwork getAverageColor] : [UIColor clearColor];
[UIView animateWithDuration:0.2f animations:^{
typedSelf.view.superview.backgroundColor = [backgroundColor colorWithAlphaComponent:[preferences mediaControlsColorOpacity]];
}];
} else {
[UIView animateWithDuration:0.2f animations:^{
typedSelf.view.superview.backgroundColor = [UIColor clearColor];
}];
}
currentView = self;
}
%end
%end
void PlayingPreferencesUpdated(CFNotificationCenterRef center, void *observer, CFNotificationName name, const void *object, CFDictionaryRef userInfo) {
if (currentView) {
[currentView applyPlaying];
}
}
%ctor {
notificationManager = [PlayingNotificationManager sharedInstance];
manager = [PlayingManager sharedInstance];
preferences = [PlayingPreferences sharedInstance];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &PlayingPreferencesUpdated, (__bridge CFNotificationName)@"me.conorthedev.playing/ReloadPrefs", NULL, 0);
NSString *shortlookPath = @"/Library/MobileSubstrate/DynamicLibraries/ShortLook.dylib";
if ([[NSFileManager defaultManager] fileExistsAtPath:shortlookPath]){
shortlookInstalled = true;
dlopen([shortlookPath UTF8String], RTLD_LAZY);
%init(ShortLookFixer);
}
%init(BBServerManager);
%init(MediaControllerHook);
NSString *mediaControlsControllerClass = @"SBDashboardMediaControlsViewController";
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0")) {
mediaControlsControllerClass = @"CSMediaControlsViewController";
}
%init(ColouredControls, MediaControlsViewController = NSClassFromString(mediaControlsControllerClass));
}