-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFANotificationHandler.mm
148 lines (114 loc) · 5.45 KB
/
FANotificationHandler.mm
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
/**
FANotificationHandler.mm
FoldMusic
version 1.2.0, July 15th, 2012
Copyright (C) 2012 theiostream
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
theiostream
**/
#import "FolderAlbums.h"
#import "FAPreferencesHandler.h"
#import "FANotificationHandler.h"
#include <substrate.h>
static void StopPlayback() {
CPDistributedMessagingCenter *center = [CPDistributedMessagingCenter centerNamed:@"am.theiostre.foldalbum.player"];
[center sendMessageName:@"Stop" userInfo:nil];
}
static FANotificationHandler *sharedInstance_ = nil;
@implementation FANotificationHandler
+ (id)sharedInstance {
if (!sharedInstance_)
sharedInstance_ = [[FANotificationHandler alloc] init];
return sharedInstance_;
}
- (void)addNewAlbumIconWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
MPMediaItemCollection *collection = [NSKeyedUnarchiver unarchiveObjectWithData:[userInfo objectForKey:@"MediaCollection"]];
NSString *title = [userInfo objectForKey:@"Title"];
SBIconListModel *availableModel = [[objc_getClass("SBIconController") sharedInstance] firstAvailableModel];
[availableModel addAlbumFolderForTitle:title plusKeyName:title andMediaCollection:collection atIndex:0 insert:NO];
}
- (void)updateKeyWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
StopPlayback();
NSString *key = [userInfo objectForKey:@"Key"];
NSDictionary *dict = [userInfo objectForKey:@"Dictionary"];
[[FAPreferencesHandler sharedInstance] updateKey:key withDictionary:dict];
}
- (void)optimizedUpdateKeyWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
StopPlayback();
NSString *key = [userInfo objectForKey:@"Key"];
NSDictionary *dict = [userInfo objectForKey:@"Dictionary"];
[[FAPreferencesHandler sharedInstance] optimizedUpdateKey:key withDictionary:dict];
}
- (void)removeKeyWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
StopPlayback();
NSString *key = [userInfo objectForKey:@"Key"];
[[FAPreferencesHandler sharedInstance] deleteKey:key];
}
- (NSDictionary *)keyExistsWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
NSString *key = [userInfo objectForKey:@"Key"];
NSNumber *ret = [NSNumber numberWithBool:[[FAPreferencesHandler sharedInstance] keyExists:key]];
return [NSDictionary dictionaryWithObject:ret forKey:@"Result"];
}
- (NSDictionary *)objectForKeyWithMessageName:(NSString *)message userInfo:(NSDictionary *)userInfo {
NSString *key = [userInfo objectForKey:@"Key"];
id ret = [[FAPreferencesHandler sharedInstance] objectForKey:key];
return [NSDictionary dictionaryWithObject:ret forKey:@"Result"];
}
- (NSDictionary *)allKeys {
NSArray *allKeys = [[FAPreferencesHandler sharedInstance] allKeys];
return [NSDictionary dictionaryWithObject:allKeys forKey:@"Result"];
}
// FIXME: When relayouting, there seems to be an odd bug.
// Maybe check out how Apple *fully* does its relayouting.
// Thanks BigBoss! (stolen from libhide)
- (void)relayout {
SBIconModel *iconModel = kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_6_0 ? MSHookIvar<SBIconModel *>([objc_getClass("SBIconController") sharedInstance], "_iconModel") : [objc_getClass("SBIconModel") sharedInstance];
NSSet *_visibleIconTags = MSHookIvar<NSSet *>(iconModel, "_visibleIconTags");
NSSet *_hiddenIconTags = MSHookIvar<NSSet *>(iconModel, "_hiddenIconTags");
if (_visibleIconTags && _hiddenIconTags) {
[iconModel setVisibilityOfIconsWithVisibleTags:_visibleIconTags hiddenTags:_hiddenIconTags];
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_6_0)
[iconModel layout];
else
[iconModel relayout];
}
}
- (void)updateTitles {
FAPreferencesHandler *handler = [FAPreferencesHandler sharedInstance];
NSArray *rootIconLists = [[objc_getClass("SBIconController") sharedInstance] rootIconLists];
NSUInteger count = [rootIconLists count];
for (NSUInteger i=0; i<count; i++) {
SBIconListView *iconListView = [rootIconLists objectAtIndex:i];
SBIconListModel *model = [iconListView model];
NSArray *icons = [model icons];
NSUInteger iconsCount = [icons count];
//NSLog(@"[!] Icons Count: %i", iconsCount);
for (NSUInteger j=0; j<iconsCount; j++) {
//NSLog(@"[!] Icon Index %i", j);
SBIcon *icon = [icons objectAtIndex:j];
if ([icon isKindOfClass:objc_getClass("FAFolderIcon")]) {
FAFolder *folder = (FAFolder *)[(FAFolderIcon *)icon folder];
NSString *iconDisplayName = [folder keyName];
if (![handler keyExists:iconDisplayName])
continue;
NSDictionary *dict = [handler objectForKey:iconDisplayName];
[folder setDisplayName:[dict objectForKey:@"fakeTitle"]];
[(SBFolderIcon *)icon updateLabel];
}
}
}
}
@end