This repository has been archived by the owner on Mar 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SwitcherBlur.xm
119 lines (88 loc) · 4.83 KB
/
SwitcherBlur.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
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <objc/runtime.h>
#import "CKBlurView.h"
/**************************** Forward-Declarations ****************************/
@interface CAFilter : NSObject
+(instancetype)filterWithName:(NSString *)name;
@end
@interface SpringBoard : UIApplication
-(void)_relaunchSpringBoardNow;
@end
@interface SBApplication
-(id)bundleIdentifier;
-(BOOL)isRunning;
@end
@interface SBAppSliderWindow : UIWindow
@end
@interface SBAppSliderSnapshotView {
UIImageView *_snapshotImage;
}
@property(retain, nonatomic) SBApplication *application;
+(id)appSliderSnapshotViewForApplication:(id)application orientation:(int)orientation loadAsync:(BOOL)async withQueue:(id)queue statusBarCache:(id)cache;
@end
/**************************** Settings Assignments ***************************/
static NSMutableArray *switcherblur_DisabledApps; // @"All" means all are disabled, nil means everything's enabled
static NSInteger switcherblur_blurIfInactive, switcherblur_blurWallpaper;
static void switcherBlur_reloadSettings(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.insanj.switcherblur.plist"]];
NSLog(@"[SwitcherBlur] Reloading settings: %@", settings);
if([settings objectForKey:@"enabled"] && ![[settings objectForKey:@"enabled"] boolValue]){
switcherblur_DisabledApps = @[@"All"].mutableCopy;
switcherblur_blurIfInactive = 1;
switcherblur_blurWallpaper = 1;
}
else{
switcherblur_DisabledApps = [[NSMutableArray alloc] init];
for(NSString *key in [settings allKeys])
if(![key isEqualToString:@"enabled"] && [[settings objectForKey:key] boolValue])
[switcherblur_DisabledApps addObject:[key stringByReplacingOccurrencesOfString:@"Blacklist-" withString:@""]];
if(switcherblur_DisabledApps.count == 0)
switcherblur_DisabledApps = nil;
switcherblur_blurIfInactive = ([settings objectForKey:@"running"] && [[settings objectForKey:@"running"] boolValue]) + 1;
int previousWallpaper = switcherblur_blurWallpaper;
switcherblur_blurWallpaper = ([settings objectForKey:@"wallpaper"] && [[settings objectForKey:@"wallpaper"] boolValue]) + 1;
if(previousWallpaper != switcherblur_blurWallpaper)
[(SpringBoard *)[%c(SpringBoard) sharedApplication] _relaunchSpringBoardNow];
}
}
/**************************** Background Blur ****************************/
%hook SBAppSliderWindow
-(id)initWithFrame:(CGRect)frame{
if(switcherblur_blurWallpaper == 0){
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.insanj.switcherblur.plist"]];
switcherblur_blurWallpaper = ([settings objectForKey:@"wallpaper"] && [[settings objectForKey:@"wallpaper"] boolValue]) + 1;
}
SBAppSliderWindow *window = %orig();
if(switcherblur_blurWallpaper == 2){
NSLog(@"[SwitcherBlur] Blurrig app switcher background : %@", self);
CKBlurView *blurView = [[CKBlurView alloc] initWithFrame:frame];
[window addSubview:blurView];
}
return window;
}
%end
/**************************** Snapshot Blur ****************************/
%hook SBAppSliderSnapshotView
+(id)appSliderSnapshotViewForApplication:(SBApplication*)application orientation:(int)orientation loadAsync:(BOOL)async withQueue:(id)queue statusBarCache:(id)cache{
if(switcherblur_blurIfInactive == 0){
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.insanj.switcherblur.plist"]];
switcherblur_blurIfInactive = ([settings objectForKey:@"running"] && [[settings objectForKey:@"running"] boolValue]) + 1;
}
if(!switcherblur_DisabledApps || ![switcherblur_DisabledApps[0] isEqualToString:@"All"]){
if(![switcherblur_DisabledApps containsObject:[application bundleIdentifier]] && !((switcherblur_blurIfInactive == 2) && [application isRunning])){
NSLog(@"[SwitcherBlur]: Blurring application-specific snapshotImage %@", %orig());
UIImageView *snapshot = (UIImageView *) %orig();
CAFilter *filter = [CAFilter filterWithName:@"gaussianBlur"];
[filter setValue:@5 forKey:@"inputRadius"];
snapshot.layer.filters = [NSArray arrayWithObject:filter];
return snapshot;
}
}
return %orig;
}
%end
%ctor{
CFNotificationCenterRef r = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(r, NULL, &switcherBlur_reloadSettings, CFSTR("com.insanj.switcherblur/reloadSettings"), NULL, 0);
}