-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLace.xm
executable file
·304 lines (221 loc) · 8.19 KB
/
Lace.xm
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#import <SpringBoard/SBMediaController.h>
#import <SpringBoard/SBControlCenterController.h>
#import <SpringBoard/SBControlCenterViewController.h>
@interface SBPagedScrollView : UIScrollView
@property (assign, nonatomic) unsigned long long currentPageIndex;
- (BOOL)scrollToPageAtIndex:(unsigned long long)arg1 animated:(BOOL)arg2;
@end
@interface SBUIChevronView : UIView
- (void)setState:(long long)state;
@end
@interface SBNotificationCenterViewController : UIViewController
@property (nonatomic, readonly) SBUIChevronView *grabberView;
@end
@interface SPUINavigationBar : UIView
@end
@interface SBSearchEtceteraNavigationController : UIViewController
@end
@interface SBSearchEtceteraTodayLayoutContentView : UIView
@property (nonatomic, assign, readwrite) CGFloat navigationBarTopInset;
@end
@protocol NCNotificationSectionList <NSObject>
@required
- (unsigned long long)sectionCount;
@end
@interface NCNotificationChronologicalList : NSObject <NCNotificationSectionList>
@property (nonatomic, retain) NSMutableArray *sections;
@end
#define prefPath [NSString stringWithFormat:@"%@/Library/Preferences/%@", NSHomeDirectory(), @"se.nosskirneh.lace.plist"]
static NSDictionary *prefs;
static SBPagedScrollView *pagedScrollView;
static id<NCNotificationSectionList> notificationList;
static SPUINavigationBar *searchNavBar;
static UIView *layoutContainerView;
void updateSettings(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
prefs = [[NSDictionary alloc] initWithContentsOfFile:prefPath];
}
/* Notification Centre */
%hook SBUIChevronView
- (void)setState:(long long)state {
if ((prefs[@"enabled"] && ![prefs[@"enabled"] boolValue]) ||
![prefs[@"CustomChevronIconEnabled"] boolValue])
return %orig;
%orig([prefs[@"CustomChevronIcon"] integerValue]);
}
%end
%hook SBNotificationCenterViewController
// Prevents stuttering animation between page control and chevron
- (void)_updateGrabberAndPageControlForMode:(NSUInteger)arg {
return;
}
- (BOOL)shouldPlayFeedbackForNewTouchLocation:(CGPoint)point velocity:(CGPoint)speed {
if (prefs[@"enabled"] && ![prefs[@"enabled"] boolValue])
return %orig;
// Set custom chevron state
if ([prefs[@"CustomChevronIconEnabled"] boolValue] &&
prefs[@"CustomChevronIcon"])
[self.grabberView setState:-2]; // Dummy value, will be overwritten in method
// Scroll to page
int page = pagedScrollView.currentPageIndex;
BOOL animated = NO;
if ([prefs[@"DefaultSectionEnabled"] boolValue]) {
page = [prefs[@"DefaultSection"] integerValue];
} else if ([prefs[@"Automode"] boolValue]) {
page = notificationList.sectionCount > 0 ? 1 : 0;
} else if (!prefs[@"ChangeWhileDragging"] ||
[prefs[@"ChangeWhileDragging"] boolValue]) {
animated = YES;
CGFloat width = [UIScreen mainScreen].bounds.size.width;
if (point.x < width / 2.0f) // Left
page = 0;
else // Right
page = 1;
}
if (pagedScrollView.currentPageIndex != page) {
[pagedScrollView scrollToPageAtIndex:page animated:animated];
pagedScrollView.currentPageIndex = page;
}
return %orig;
}
- (void)viewWillAppear:(BOOL)arg {
%orig;
if (prefs[@"enabled"] && ![prefs[@"enabled"] boolValue] &&
searchNavBar.hidden) {
// Restore hidden if tweak is no longer enabled
[searchNavBar setHidden:NO];
return;
}
if ([prefs[@"HideSearch"] boolValue]) {
[searchNavBar setHidden:YES];
[layoutContainerView setFrame:(CGRectMake(layoutContainerView.frame.origin.x,
layoutContainerView.frame.origin.y + 20,
layoutContainerView.frame.size.width,
layoutContainerView.frame.size.height - 20))];
} else {
[searchNavBar setHidden:NO];
}
}
- (void)viewWillDisappear:(BOOL)arg {
%orig;
// Unhide in order to be visible with Spotlight
[searchNavBar setHidden:NO];
}
%end
%hook SBSearchEtceteraTodayLayoutContentView
- (void)setNavigationBarTopInset:(CGFloat)inset {
if (self.navigationBarTopInset != 0 &&
inset != self.navigationBarTopInset &&
prefs[@"enabled"] && [prefs[@"enabled"] boolValue] &&
[prefs[@"HideSearch"] boolValue]) {
return;
}
%orig;
}
%end
%hook NCNotificationSectionListViewController
- (void)setSectionList:(id)arg1 {
%orig;
notificationList = arg1;
}
%end
%hook NCNotificationChronologicalList
- (id)init {
return notificationList = %orig;
}
%end
%hook SBPagedScrollView
- (id)initWithFrame:(CGRect)frame {
if (!pagedScrollView && CGRectIsEmpty(frame))
return pagedScrollView = %orig;
return %orig;
}
%end
%hook SBSearchEtceteraNavigationController
- (void)viewDidLoad {
%orig;
layoutContainerView = self.view;
}
%end
%hook SPUINavigationBar
- (id)initWithFrame:(CGRect)frame {
return searchNavBar = %orig;
}
%end
/* Control Centre */
@interface SBControlCenterController (Addition)
@property (nonatomic, assign) NSInteger currentPage;
@end
%hook SBControlCenterController
%property (nonatomic, assign) NSInteger currentPage;
- (void)setPresented:(BOOL)presented {
%orig;
self.currentPage = -2;
}
- (void)_updateTransitionWithTouchLocation:(CGPoint)point velocity:(CGPoint)velocity {
if (prefs[@"enabledCC"] && ![prefs[@"enabledCC"] boolValue])
return %orig;
// Scroll to page
int page = -1;
BOOL animated = NO;
if ([prefs[@"DefaultSectionEnabledCC"] boolValue]) {
page = [prefs[@"DefaultSectionCC"] integerValue];
} else if ([prefs[@"AutomodeCC"] boolValue]) {
page = [[%c(SBMediaController) sharedInstance] nowPlayingApplication] ? 1 : 0;
} else if (!prefs[@"ChangeWhileDraggingCC"] ||
[prefs[@"ChangeWhileDraggingCC"] boolValue]) {
animated = YES;
CGFloat width = [UIScreen mainScreen].bounds.size.width;
page = point.x / width * [self numberOfActivePages];
}
if (page != -1 && self.currentPage != page) {
[self scrollToPage:page animated:animated withCompletion:nil];
self.currentPage = page;
}
%orig;
}
%end
/* Lockscreen */
@interface SBDashBoardNotificationListViewController : UIViewController
@property(readonly, nonatomic) BOOL hasContent;
@end
@interface SBDashBoardMainPageContentViewController : UIViewController
@property(readonly, nonatomic) SBDashBoardNotificationListViewController *notificationListViewController;
@end
@interface SBDashBoardMainPageViewController : UIViewController
@property (nonatomic, assign) SBDashBoardMainPageContentViewController *contentViewController;
@end
@interface SBDashBoardPageViewBase : UIView
@property (nonatomic, assign) SBDashBoardMainPageViewController *pageViewController;
@end
@interface SBDashBoardView : UIView
@property (nonatomic, readwrite, assign) SBDashBoardPageViewBase *mainPageView;
- (BOOL)scrollToPageAtIndex:(unsigned long long)arg1 animated:(BOOL)arg2 withCompletion:(id)arg3;
@end
%hook SBDashBoardView
- (BOOL)resetScrollViewToMainPageAnimated:(BOOL)arg1 withCompletion:(id)arg2 {
if (prefs[@"enabledLS"] && ![prefs[@"enabledLS"] boolValue])
return %orig;
int page = 1;
if ([prefs[@"DefaultSectionEnabledLS"] boolValue]) {
page = [prefs[@"DefaultSectionLS"] integerValue];
} else if ([prefs[@"AutomodeLS"] boolValue]) {
// Are notifications present?
BOOL hasContent = self.mainPageView.pageViewController.contentViewController.notificationListViewController.hasContent;
if (!hasContent)
page = 0;
}
[self scrollToPageAtIndex:page animated:NO withCompletion:nil];
return YES;
}
%end
%ctor {
// Init settings file
prefs = [[NSDictionary alloc] initWithContentsOfFile:prefPath];
if (!prefs) prefs = [[NSMutableDictionary alloc] init];
// Add observer to update settings
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFStringRef(@"se.nosskirneh.lace/preferencesChanged"), NULL, 0);
}