-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathClock.xm
executable file
·254 lines (221 loc) · 7.76 KB
/
Clock.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
#import "core/ANEMSettingsManager.h"
@interface UIImage (Bundle)
+ (UIImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
@end
@interface SBClockApplicationIconImageView : UIImageView
- (UIImage *)contentsImage;
- (void)_setAnimating:(BOOL)animating;
@end
static UIImage *hourHandImage;
static UIImage *minuteHandImage;
static UIImage *secondHandImage;
static UIImage *redDotImage;
static UIImage *blackDotImage;
static UIColor *hourHandColor;
static UIColor *minuteHandColor;
static UIColor *secondHandColor;
static UIColor *redDotColor;
static UIColor *blackDotColor;
static BOOL clockImagesLoaded = NO;
static BOOL clockIconNeedsUpdate = NO;
static void loadClockImages(){
if (clockImagesLoaded)
return;
hourHandImage = [[UIImage imageNamed:@"ClockIconHourHand"] retain];
minuteHandImage = [[UIImage imageNamed:@"ClockIconHourHand"] retain];
secondHandImage = [[UIImage imageNamed:@"ClockIconHourHand"] retain];
redDotImage = [[UIImage imageNamed:@"ClockIconHourHand"] retain];
blackDotImage = [[UIImage imageNamed:@"ClockIconHourHand"] retain];
clockImagesLoaded = YES;
}
%group all
%hook SBClockApplicationIconImageView
- (id)initWithFrame:(CGRect)frame {
self = %orig;
loadClockImages();
CALayer *hours = [self valueForKey:@"_hours"];
CALayer *minutes = [self valueForKey:@"_minutes"];
CALayer *seconds = [self valueForKey:@"_seconds"];
CALayer *redDot = [self valueForKey:@"_redDot"];
CALayer *blackDot = [self valueForKey:@"_blackDot"];
hourHandColor = [[UIColor alloc] initWithCGColor:hours.backgroundColor];
minuteHandColor = [[UIColor alloc] initWithCGColor:minutes.backgroundColor];
secondHandColor = [[UIColor alloc] initWithCGColor:seconds.backgroundColor];
redDotColor = [[UIColor alloc] initWithCGColor:redDot.backgroundColor];
blackDotColor = [[UIColor alloc] initWithCGColor:blackDot.backgroundColor];
if (hourHandImage){
hours.contents = (id)hourHandImage.CGImage;
hours.backgroundColor = [[UIColor clearColor] CGColor];
}
if (minuteHandImage){
minutes.contents = (id)minuteHandImage.CGImage;
minutes.backgroundColor = [[UIColor clearColor] CGColor];
}
if (secondHandImage){
seconds.contents = (id)secondHandImage.CGImage;
seconds.backgroundColor = [[UIColor clearColor] CGColor];
}
if (redDotImage){
redDot.contents = (id)redDotImage.CGImage;
redDot.backgroundColor = [[UIColor clearColor] CGColor];
}
if (blackDotImage){
blackDot.contents = (id)blackDotImage.CGImage;
blackDot.backgroundColor = [[UIColor clearColor] CGColor];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wambiguous-macro"
#if TARGET_IPHONE_SIMULATOR
[self _setAnimating:YES];
#endif
#pragma clang diagnostic pop
clockIconNeedsUpdate = NO;
return self;
}
- (void)updateAnimatingState {
%orig;
if (!clockIconNeedsUpdate)
return;
CALayer *hours = [self valueForKey:@"_hours"];
CALayer *minutes = [self valueForKey:@"_minutes"];
CALayer *seconds = [self valueForKey:@"_seconds"];
CALayer *redDot = [self valueForKey:@"_redDot"];
CALayer *blackDot = [self valueForKey:@"_blackDot"];
if (hourHandImage){
hours.contents = (id)hourHandImage.CGImage;
hours.backgroundColor = [[UIColor clearColor] CGColor];
} else {
hours.contents = nil;
hours.backgroundColor = [hourHandColor CGColor];
}
if (minuteHandImage){
minutes.contents = (id)minuteHandImage.CGImage;
minutes.backgroundColor = [[UIColor clearColor] CGColor];
} else {
minutes.contents = nil;
minutes.backgroundColor = [minuteHandColor CGColor];
}
if (secondHandImage){
seconds.contents = (id)secondHandImage.CGImage;
seconds.backgroundColor = [[UIColor clearColor] CGColor];
} else {
seconds.contents = nil;
seconds.backgroundColor = [secondHandColor CGColor];
}
if (redDotImage){
redDot.contents = (id)redDotImage.CGImage;
redDot.backgroundColor = [[UIColor clearColor] CGColor];
} else {
redDot.contents = nil;
redDot.backgroundColor = [redDotColor CGColor];
}
if (blackDotImage){
blackDot.contents = (id)blackDotImage.CGImage;
blackDot.backgroundColor = [[UIColor clearColor] CGColor];
} else {
blackDot.contents = nil;
blackDot.backgroundColor = [blackDotColor CGColor];
}
clockIconNeedsUpdate = NO;
}
- (BOOL)isAnimationAllowed {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wambiguous-macro"
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
return %orig;
#endif
#pragma clang diagnostic pop
}
- (UIImage *)contentsImage {
UIImage *origImage = %orig;
CGSize origImageSize = origImage.size;
if (origImage.scale == 1){
CGFloat scale = [[UIScreen mainScreen] scale];
origImageSize.width /= scale;
origImageSize.height /= scale;
}
UIImage *ret = [UIImage imageNamed:@"ClockIconBackgroundSquare"];
UIGraphicsBeginImageContextWithOptions(origImageSize, NO, 0.0);
CGSize imageSize = CGSizeMake(60, 60);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
if (MAX([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height) == 1366){ //iPad Pro
imageSize = CGSizeMake(83.5, 83.5);
} else
imageSize = CGSizeMake(76, 76);
}
[ret drawInRect:CGRectMake((origImageSize.width-imageSize.width)/2.0,(origImageSize.height-imageSize.height)/2.0,imageSize.width,imageSize.height)];
ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (ret != nil){
UIImage *maskImage = nil;
NSBundle *mobileIconsBundle = [NSBundle bundleWithIdentifier:@"com.apple.mobileicons.framework"];
if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad)
maskImage = [UIImage imageNamed:@"AppIconMask~iphone" inBundle:mobileIconsBundle];
else {
maskImage = [UIImage imageNamed:@"AppIconMask~ipad" inBundle:mobileIconsBundle];
if (MAX([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height) == 1366)
maskImage = [UIImage imageNamed:@"AppIconMask-RFB~ipad" inBundle:mobileIconsBundle];
}
if (maskImage){
UIGraphicsBeginImageContextWithOptions(origImageSize, YES, 0.0);
[[UIColor whiteColor] setFill];
UIRectFill(CGRectMake(0,0,origImageSize.width,origImageSize.height));
[maskImage drawAtPoint:CGPointMake((origImageSize.width-maskImage.size.width)/2.0,(origImageSize.height-maskImage.size.height)/2.0)];
maskImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef),
NULL, false);
CGImageRef masked = CGImageCreateWithMask([ret CGImage], mask);
CGImageRelease(mask);
ret = [UIImage imageWithCGImage:masked scale:ret.scale orientation:ret.imageOrientation];
CGImageRelease(masked);
}
} else {
ret = %orig;
}
return ret;
}
%end
%end
@interface AnemoneClockEventHandler: NSObject <AnemoneEventHandler>
- (void)reloadTheme;
@end
@implementation AnemoneClockEventHandler
- (void)reloadTheme {
if (hourHandImage)
[hourHandImage release];
hourHandImage = nil;
if (minuteHandImage)
[minuteHandImage release];
minuteHandImage = nil;
if (secondHandImage)
[secondHandImage release];
secondHandImage = nil;
if (redDotImage)
[redDotImage release];
redDotImage = nil;
if (blackDotImage)
[blackDotImage release];
blackDotImage = nil;
clockImagesLoaded = NO;
loadClockImages();
clockIconNeedsUpdate = YES;
}
@end
%ctor {
if (kCFCoreFoundationVersionNumber > MaxSupportedCFVersion)
return;
%init(all);
if (objc_getClass("ANEMSettingsManager") == nil){
dlopen("/Library/MobileSubstrate/DynamicLibraries/AnemoneCore.dylib",RTLD_LAZY);
}
[[%c(ANEMSettingsManager) sharedManager] addEventHandler:[AnemoneClockEventHandler new]];
}