This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLibDisplay.m
418 lines (338 loc) · 13.9 KB
/
LibDisplay.m
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
//
// LibDisplay.m
//
//
// Created by Kyle Howells on 22/12/2011.
// Copyright 2011 Howells Apps. All rights reserved.
//
//#import <SpringBoard4.0/SBAppSwitcherController.h>
#import <SpringBoard/SBIcon.h>
#import <SpringBoard/SBApplication.h>
#import <SpringBoard/SBUIController.h>
#import <SpringBoard/SBDisplayStack.h>
#import <SpringBoard/SBApplication.h>
#import <SpringBoard/SBDisplay.h>
#import <QuartzCore/QuartzCore.h>
#import "LibDisplay.h"
#define SPRINGBOARD UIApp
#define UIApp ((SpringBoard*)[UIApplication sharedApplication])
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#pragma mark - Headers
@interface SpringBoard : UIApplication {}
-(void)setBackgroundingEnabled:(BOOL)backgroundingEnabled forDisplayIdentifier:(NSString *)displayIdentifier;
-(void)showSpringBoardStatusBar;
-(SBApplication*)_accessibilityFrontMostApplication;
-(void)quitTopApplication:(void*)event;
@end
@interface SBApplicationController : NSObject {}
+(SBApplicationController*)sharedInstance;
-(SBApplication*)applicationWithDisplayIdentifier:(NSString*)displayIdentifier;
@end
@interface SBAppSwitcherModel : NSObject {}
+(SBAppSwitcherModel*)sharedInstance;
-(void)addToFront:(id)front;
-(void)remove:(id)remove;
@end
@interface SBUIController ()
-(void)dismissSwitcherAnimated:(BOOL)animated;
@end
@interface SBApplication ()
-(int)suspensionType;
-(int)activationState; //iOS 6
@end
@interface SBProcess : NSObject {}
-(void)resume;
-(void)addAssertion:(id)arg1;
-(void)removeAssertion:(id)arg1;
-(void)removeAllAssertions;
-(id)assertions;
@end
@interface SBProcessAssertion : NSObject
-(id)initWithProcess:(SBProcess*)process reason:(unsigned int)reason identifier:(NSString*)identifier;
@end
@interface SBIconView : UIView
@property(readonly) SBIcon *icon;
- (void)setIcon:(SBIcon*)arg1;
- (id)initWithDefaultSize;
@end
@interface SBIconModel : NSObject
- (id)applicationIconForDisplayIdentifier:(id)arg1;
@end
@interface SBIconController : NSObject
+(SBIconController*)sharedInstance;
-(SBIconModel*)model;
-(void)iconCloseBoxTapped:(SBIconView*)arg1;
@end
@interface SBAppSwitcherController : NSObject
+(SBAppSwitcherController*)sharedInstance;
-(void)iconCloseBoxTapped:(SBIconView*)arg1;
@end
#pragma mark - Private methods
@interface LibDisplay()
-(id)_init;
@property (nonatomic, readonly) NSMutableArray *launchedApps;
@property (nonatomic, readonly) NSMutableArray *delegates;
-(SBDisplayStack*)stackAtIndex:(int)index;
-(void)appLaunched:(SBApplication*)app;
-(void)appFinishedLaunching:(SBApplication*)app;
-(void)appQuit:(SBApplication*)app;
-(void)addToFront:(SBApplication*)app;
-(void)closeSwitcher;
@end
static BOOL sbAppNotNSString = NO;
static LibDisplay *_instance;
@implementation LibDisplay
@synthesize displayStacks = _displayStacks;
@synthesize runningApplications = _runningApplications;
@synthesize launchedApps = _launchedApps;
@synthesize delegates = _delegates;
#pragma mark - Singleton Methods
+(LibDisplay*)sharedInstance{
@synchronized(self) {
if (_instance == nil) {
_instance = [[self alloc] _init];
}
}
return _instance;
}
-(id)_init{
if ((self = [super init])) {
_displayStacks = [[NSMutableArray alloc] init];
_runningApplications = [[NSMutableArray alloc] init];
_launchedApps = [[NSMutableArray alloc] init];
_delegates = [[NSMutableArray alloc] init];
}
return self;
}
// If I'm opensourcing it I don't want it to be crashed be something not realising it's a sharedInstance.
-(id)init{
return [LibDisplay sharedInstance];
}
#pragma mark - Display stacks
-(SBDisplayStack*)SBWPreActivateDisplayStack{
return [self stackAtIndex:0];
}
-(SBDisplayStack*)SBWActiveDisplayStack{
return [self stackAtIndex:1];
}
-(SBDisplayStack*)SBWSuspendingDisplayStack{
return [self stackAtIndex:2];
}
-(SBDisplayStack*)SBWSuspendedEventOnlyDisplayStack{
return [self stackAtIndex:3];
}
-(SBDisplayStack*)stackAtIndex:(int)index{
if (index < [self.displayStacks count]) {
return [self.displayStacks objectAtIndex:index];
}
return nil;
}
#pragma mark - Application stuff
-(SBApplication*)topApplication{
return ([[self SBWActiveDisplayStack] topApplication] ?: [UIApp _accessibilityFrontMostApplication]);
}
-(BOOL)applicationIsLaunching:(SBApplication*)application{
if ([application respondsToSelector:@selector(activationState)]) {
return ([application activationState] == 1);
}
return (![self.launchedApps containsObject:application] && [self.runningApplications containsObject:application]);
}
#pragma mark Application Lifetime
-(void)appLaunched:(SBApplication*)app{
if (![self.runningApplications containsObject:app]) {
[self.runningApplications addObject:app];
for (NSObject <LibDisplayDelegate> *delegate in self.delegates) {
[delegate performSelector:@selector(applicationDidLaunch:) withObject:app];
}
}
}
-(void)appFinishedLaunching:(SBApplication*)app{
if (![self.launchedApps containsObject:app] && [self.runningApplications containsObject:app]) {
[self.launchedApps addObject:app];
}
}
-(void)appQuit:(SBApplication*)app{
if ([self.runningApplications containsObject:app]) {
[self.runningApplications removeObject:app];
for (NSObject <LibDisplayDelegate> *delegate in self.delegates) {
if (delegate && [delegate respondsToSelector:@selector(applicationDidQuit:)]) {
[delegate performSelector:@selector(applicationDidQuit:) withObject:app];
}
}
}
if ([self.launchedApps containsObject:app]) {
[self.launchedApps removeObject:app];
}
}
// Hacky stuff here :( it changed from SBApplication to NSString but without
// changing the method names at all so you can't work out what it wants. + it
// has always just stored the displayID so looking at the array iVar won't help either.
-(void)addToFront:(id)app{
//NSLog(@"what is -addToFront: %@", app);
NSMutableArray *array = self.runningApplications;
if ([app isKindOfClass:[NSString class]]) {
app = [(SBApplicationController*)[objc_getClass("SBApplicationController") sharedInstance] applicationWithDisplayIdentifier:app];
}
else {
sbAppNotNSString = YES;
}
if (app) {
if ([array containsObject:app]) {
[array removeObject:app];
[array addObject:app];
}
else {
[self appLaunched:app];
}
}
}
#pragma mark - Send delegates info.
-(void)notifyOfAppLaunches:(id <LibDisplayDelegate>)new_delegate{
if (![self.delegates containsObject:new_delegate]) {
[self.delegates addObject:new_delegate];
}
}
-(void)removeNotifier:(id <LibDisplayDelegate>)existing_delegate{
if ([self.delegates containsObject:existing_delegate]) {
[self.delegates removeObject:existing_delegate];
}
}
#pragma mark - Active and deactivate applications
-(void)activateApplication:(SBApplication *)toApp animated:(BOOL)animated{
// Get the currently open application.
SBApplication *fromApp = [self topApplication];
// Check if it's the same as the currently open application, if it is there's nothing todo.
if ([[toApp displayIdentifier] isEqualToString:[fromApp displayIdentifier]]) {
return;
}
// If animated they want the system default (app to app transition, or zoom on homescreen).
if (animated && toApp) {
[(SBUIController*)[objc_getClass("SBUIController") sharedInstance] activateApplicationFromSwitcher:toApp];
return; // Done, wasn't that easy.
}
// Now, if we were asked to, open the other app.
if (toApp) {
// Prevent seeing and interacting with the homescreen
SBUIController *uiController = (SBUIController*)[objc_getClass("SBUIController") sharedInstance];
if ([uiController respondsToSelector:@selector(fadeIconsForScatter:duration:startTime:)]) {
[uiController fadeIconsForScatter:YES duration:0 startTime:CACurrentMediaTime()];
}
[toApp clearDisplaySettings];
[toApp clearActivationSettings];
[toApp clearDeactivationSettings];
if (fromApp) {
// 20 = appToApp
[toApp setActivationSetting:20 flag:YES];
}
// Note if it's a large application the user might see a brief flash of the homescreen.
[[self SBWPreActivateDisplayStack] pushDisplay:toApp];
}
else if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
[UIApp quitTopApplication:nil];
}
// If another app is open then close it
if (fromApp) {
// Clear any animation settings the app may have
[fromApp clearDisplaySettings];
[fromApp clearActivationSettings];
[fromApp clearDeactivationSettings];
if (!toApp) {
SpringBoard *springBoard = UIApp;
if ([springBoard respondsToSelector:@selector(showSpringBoardStatusBar)]) {
[springBoard showSpringBoardStatusBar];
}
if ([SPRINGBOARD respondsToSelector:@selector(setBackgroundingEnabled:forDisplayIdentifier:)]) {
// Animate (to fix a backgrounder related bug)
[fromApp setDeactivationSetting:2 flag:YES];
}
}
// Now pop is from the Active displayStack
[[self SBWActiveDisplayStack] popDisplay:fromApp];
// And push it onto the Suspending displayStack
[[self SBWSuspendingDisplayStack] pushDisplay:fromApp];
}
[self closeSwitcher];
}
-(void)quitApplication:(SBApplication*)application{
[self quitApplication:application removeFromSwitcher:NO];
}
-(void)quitApplication:(SBApplication*)application removeFromSwitcher:(BOOL)removeFromSwitcher{
if ([SPRINGBOARD respondsToSelector:@selector(setBackgroundingEnabled:forDisplayIdentifier:)]) {
[SPRINGBOARD setBackgroundingEnabled:NO forDisplayIdentifier:[application displayIdentifier]];
}
// On iOS 4.0 it crashes springboard, but after a delay so I don't know why.
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"4.1") && SYSTEM_VERSION_LESS_THAN(@"6.0")) {
//******************* Proper app quiting code thanks to 'jmeosbn' - start **************//
int suspendType = [application respondsToSelector:@selector(_suspensionType)] ? (int)[application _suspensionType] : (int)[application suspensionType];
// Set app to terminate on suspend then call deactivate
// Allows exiting root apps, even if already backgrounded,
// but does not exit an app with active background tasks
[application setSuspendType:0];
[application deactivate];
[[application process] resume];
// Restore previous suspend type
[application setSuspendType:suspendType];
//******************* Proper app quiting code thanks to 'jmeosbn' - end **************//
}
if ([application respondsToSelector:@selector(kill)]) {
// Now if it hasn't closed after 1/2 second kill it (doesn't work on root apps like iFile)
[application performSelector:@selector(kill) withObject:nil afterDelay:0.4]; // Probably un-needed
//[[objc_getClass("SBAppSwitcherController") sharedInstance] _quitButtonHit:APP];
}
SBAppSwitcherController *controller = [objc_getClass("SBAppSwitcherController") sharedInstance];
if ([controller respondsToSelector:@selector(iconCloseBoxTapped:)]) {
SBIcon *icon = [[[objc_getClass("SBIconController") sharedInstance] model] applicationIconForDisplayIdentifier:[application displayIdentifier]];
SBIconView *iconView = [[objc_getClass("SBIconView") alloc] initWithDefaultSize];
iconView.icon = icon;
[controller iconCloseBoxTapped:iconView];
iconView.icon = nil;
[iconView release];
}
if (removeFromSwitcher) {
[self removeApplicationFromSwitcher:application];
}
}
-(void)removeApplicationFromSwitcher:(SBApplication*)app{
// SBAppSwitcherController *appSwitcherController = (SBAppSwitcherController*)[objc_getClass("SBAppSwitcherController") sharedInstance];
// if ([appSwitcherController respondsToSelector:@selector(_removeApplicationFromRecents:)]) {
// // The app isn't in the recents list if it's currently open.
// [appSwitcherController _removeApplicationFromRecents:application];
// }
SBAppSwitcherModel *switcherModel = (SBAppSwitcherModel*)[objc_getClass("SBAppSwitcherModel") sharedInstance];
if ([switcherModel respondsToSelector:@selector(remove:)]) {
// remove: takes an SBApplication on iOS 4 but an NSString on iOS 5 :(
if (SYSTEM_VERSION_LESS_THAN(@"4.2") || sbAppNotNSString) {
[switcherModel remove:app];
}
else {
[switcherModel remove:app.displayIdentifier];
}
}
}
-(void)closeSwitcher{
SBUIController *uiController = (SBUIController*)[objc_getClass("SBUIController") sharedInstance];
if ([uiController isSwitcherShowing]) {
if ([uiController respondsToSelector:@selector(_dismissSwitcher:)]) {
[uiController _dismissSwitcher:0.0];
}
else if ([uiController respondsToSelector:@selector(dismissSwitcherAnimated:)]) {
[uiController dismissSwitcherAnimated:NO];
}
}
}
#pragma mark - Init Methods
-(id)retain{
return self;
}
-(unsigned)retainCount{
return UINT_MAX;
}
-(void)release{}
-(id)autorelease{
return self;
}
@end