-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTweak.xm
611 lines (530 loc) · 19.3 KB
/
Tweak.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
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIControl.h>
#import <Cephei/HBPreferences.h>
#import <libimagepicker.h>
#import "./headers/UIImage+ScaledImage.h"
#import "./headers/UIImage+animatedGIF.h"
#import "./xeonprefs/XENCommon.h"
#import "./xeonprefs/XENGIFCommon.h"
//Tweak Enabled
static bool isEnabled = true;
static bool debug = false; //Don't enable this.
//Custom Image
static bool isCustomImageEnabled = true;
static bool imageInFrontOfCarrierText = true;
static bool imageInFrontOfTimeText = true;
static int whereToPutImage = 0;
static int imageColor = 1;
static int themesOrImage = 0;
static bool hideCarrierText = false;
static bool hideTimeText = false;
static bool usingiPadStyle = false;
static NSData *userCustomImageData = nil;
static UIImageView *gifImage;
static int staticImageSize = 20;
static int gifImagePadding = 0;
//Custom Text
static bool isCustomTextEnabled = false;
static bool textInFrontOfCarrierText = false;
static bool textInFrontOfTimeText = false;
static int whereToPutText = 0;
static NSString *customText = @"";
//Custom Carrier
static bool isCustomCarrierEnabled = false;
static NSString *customCarrier = nil;
//Custom Cellular Text
static bool isCustomCellularTextEnabled = false;
static NSString *customCellularText = @"";
//Other Settings
static bool adjustFontSize = true;
//Custom Theme
static XENTheme *currentTheme;
static XENGIFTheme *currentGIFTheme;
@interface _UIStatusBarItem : NSObject
@end
@interface _UIStatusBarCellularItem : _UIStatusBarItem
@end
@interface _UIStatusBarStringView : UILabel
@property (nonatomic,copy) NSString * originalText;
@property (nonatomic, assign) BOOL isServiceView;
@property (nonatomic, assign) BOOL isTime;
-(void)setText:(id)arg1;
@end
@interface _UIStatusBarTimeItem : _UIStatusBarItem
@property (nonatomic, retain) _UIStatusBarStringView * shortTimeView;
@property (nonatomic, retain) _UIStatusBarStringView * pillTimeView;
@end
@interface SBStatusBarStateAggregator : NSObject
+(id)sharedInstance;
-(void)_updateServiceItem;
@end
@interface SBTelephonySubscriptionInfo : NSObject
-(NSString *)operatorName;
@end
@interface SBFLockScreenDateView : UIView
-(void)layoutSubviews;
@end
%group Xeon
%hook _UIStatusBarCellularItem
-(_UIStatusBarStringView *)serviceNameView {
_UIStatusBarStringView *orig = %orig;
orig.isServiceView = TRUE;
return orig;
}
%end
%hook _UIStatusBarTimeItem
-(_UIStatusBarStringView *)shortTimeView{
_UIStatusBarStringView *orig = %orig;
orig.isTime = TRUE;
return orig;
}
%end
%end
%group XENCustomImage
%hook _UIStatusBarStringView
%property (nonatomic, assign) BOOL isServiceView;
%property (nonatomic, assign) BOOL isTime;
-(void)setText:(id)arg1 {
%orig;
for (UIView *subview in [self subviews]) {
[subview removeFromSuperview];
}
if (whereToPutImage == 0) {
imageInFrontOfCarrierText = true;
imageInFrontOfTimeText = false;
} else if (whereToPutImage == 1) {
imageInFrontOfCarrierText = false;
imageInFrontOfTimeText = true;
} else if (whereToPutImage == 2) {
imageInFrontOfCarrierText = true;
imageInFrontOfTimeText = true;
}
if (themesOrImage == 0 || themesOrImage == 1) {
if (self.isServiceView) {
if (imageInFrontOfCarrierText) {
NSString *space = @" ";
NSString *carrierText = arg1;
if (arg1 != nil) {
carrierText = [space stringByAppendingString:arg1];
} else {
%orig(space);
}
if (hideCarrierText) {
carrierText = @"";
}
UIImage *userCustomImage = [UIImage imageWithData:userCustomImageData];
UIImage *img = [currentTheme getIcon:@"[email protected]"];
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
UIImage *newImage = nil;
if (themesOrImage == 0) {
if (hideCarrierText) {
newImage = [img scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [img scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
} else {
if (hideCarrierText) {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
}
if (imageColor == 0) {
newImage = [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
NSTextAttachment *imageAttachment = [[NSTextAttachment alloc] init];
imageAttachment.image = newImage;
CGFloat imageOffsetY = -5.0;
imageAttachment.bounds = CGRectMake(0, imageOffsetY, imageAttachment.image.size.width, imageAttachment.image.size.height);
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:imageAttachment];
NSMutableAttributedString *imageFixText = [[NSMutableAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
[imageFixText appendAttributedString:attachmentString];
[imageFixText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:0] range:NSMakeRange(0, imageFixText.length)];
[imageFixText appendAttributedString:[[NSAttributedString alloc] initWithString:@""]];
NSMutableAttributedString *completeText = [[NSMutableAttributedString alloc] initWithString:@""];
[completeText appendAttributedString:imageFixText];
NSMutableAttributedString *textAfterIcon = [[NSMutableAttributedString alloc] initWithString:carrierText];
[completeText appendAttributedString:textAfterIcon];
self.textAlignment = NSTextAlignmentRight;
self.attributedText = completeText;
} else {
%orig;
}
}
if (self.isTime) {
if (imageInFrontOfTimeText) {
NSString *space = @" ";
NSString *carrierText = arg1;
if (arg1 != nil) {
carrierText = [space stringByAppendingString:arg1];
} else {
%orig(space);
}
if (hideTimeText) {
carrierText = @"";
}
UIImage *userCustomImage = [UIImage imageWithData:userCustomImageData];
UIImage *img = [currentTheme getIcon:@"[email protected]"];
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
UIImage *newImage = nil;
if (themesOrImage == 0) {
if (hideCarrierText) {
newImage = [img scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [img scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
} else {
if (hideCarrierText) {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
}
if (imageColor == 0) {
newImage = [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
NSTextAttachment *imageAttachment = [[NSTextAttachment alloc] init];
imageAttachment.image = newImage;
CGFloat imageOffsetY = -5.0;
imageAttachment.bounds = CGRectMake(0, imageOffsetY, imageAttachment.image.size.width, imageAttachment.image.size.height);
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:imageAttachment];
NSMutableAttributedString *imageFixText = [[NSMutableAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
[imageFixText appendAttributedString:attachmentString];
[imageFixText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:0] range:NSMakeRange(0, imageFixText.length)];
[imageFixText appendAttributedString:[[NSAttributedString alloc] initWithString:@""]];
NSMutableAttributedString *completeText = [[NSMutableAttributedString alloc] initWithString:@""];
[completeText appendAttributedString:imageFixText];
NSMutableAttributedString *textAfterIcon = [[NSMutableAttributedString alloc] initWithString:carrierText];
[completeText appendAttributedString:textAfterIcon];
self.textAlignment = NSTextAlignmentRight;
self.attributedText = completeText;
if (adjustFontSize) {
[self setAdjustsFontSizeToFitWidth:YES];
}
} else {
%orig;
}
}
if (usingiPadStyle && [arg1 containsString:@":"]) {
if (imageInFrontOfTimeText) {
NSString *space = @" ";
NSString *carrierText = arg1;
if (arg1 != nil) {
carrierText = [space stringByAppendingString:arg1];
} else {
%orig(space);
}
if (hideTimeText) {
carrierText = @"";
}
UIImage *userCustomImage = [UIImage imageWithData:userCustomImageData];
UIImage *img = [currentTheme getIcon:@"[email protected]"];
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
if (!img) {
img = [currentTheme getIcon:@"[email protected]"];
}
UIImage *newImage = nil;
if (themesOrImage == 0) {
if (hideCarrierText) {
newImage = [img scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [img scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
} else {
if (hideCarrierText) {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(40, staticImageSize)];
} else {
newImage = [userCustomImage scaleImageToSize:CGSizeMake(staticImageSize, staticImageSize)];
}
}
if (imageColor == 0) {
newImage = [newImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
NSTextAttachment *imageAttachment = [[NSTextAttachment alloc] init];
imageAttachment.image = newImage;
CGFloat imageOffsetY = -5.0;
imageAttachment.bounds = CGRectMake(0, imageOffsetY, imageAttachment.image.size.width, imageAttachment.image.size.height);
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:imageAttachment];
NSMutableAttributedString *imageFixText = [[NSMutableAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
[imageFixText appendAttributedString:attachmentString];
[imageFixText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:0] range:NSMakeRange(0, imageFixText.length)];
[imageFixText appendAttributedString:[[NSAttributedString alloc] initWithString:@""]];
NSMutableAttributedString *completeText = [[NSMutableAttributedString alloc] initWithString:@""];
[completeText appendAttributedString:imageFixText];
NSMutableAttributedString *textAfterIcon = [[NSMutableAttributedString alloc] initWithString:carrierText];
[completeText appendAttributedString:textAfterIcon];
self.textAlignment = NSTextAlignmentRight;
self.attributedText = completeText;
if (adjustFontSize) {
[self setAdjustsFontSizeToFitWidth:YES];
}
} else {
%orig;
}
}
}
if (themesOrImage == 2 || themesOrImage == 3) {
NSString *space = @" ";
NSString *carrierText = arg1;
if (arg1 != nil) {
carrierText = [space stringByAppendingString:arg1];
}
if (self.isServiceView && imageInFrontOfCarrierText) {
if (arg1 == nil) {
%orig(space);
}
if (hideCarrierText) {
%orig(space);
} else {
%orig(carrierText);
}
NSData *gifImageData = [currentGIFTheme getGIFData:@"animated.gif"];
UIImage *animatedimg = [UIImage animatedImageWithAnimatedGIFData:gifImageData];
UIImage *userCustomImage = [UIImage animatedImageWithAnimatedGIFData:userCustomImageData];
gifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, gifImagePadding, staticImageSize, staticImageSize)];
if (themesOrImage == 2) {
gifImage.image = animatedimg;
} else {
gifImage.image = userCustomImage;
}
[self addSubview:gifImage];
}
if (self.isTime && imageInFrontOfTimeText) {
if (arg1 == nil) {
%orig(space);
}
if (hideTimeText) {
%orig(space);
} else {
%orig(carrierText);
}
if (adjustFontSize) {
[self setAdjustsFontSizeToFitWidth:YES];
}
NSData *gifImageData = [currentGIFTheme getGIFData:@"animated.gif"];
UIImage *animatedimg = [UIImage animatedImageWithAnimatedGIFData:gifImageData];
UIImage *userCustomImage = [UIImage animatedImageWithAnimatedGIFData:userCustomImageData];
gifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, gifImagePadding, staticImageSize, staticImageSize)];
if (themesOrImage == 2) {
gifImage.image = animatedimg;
} else {
gifImage.image = userCustomImage;
}
[self addSubview:gifImage];
}
if (!self.isTime && usingiPadStyle && [arg1 containsString:@":"]) {
NSString *sp1 = @" ";
NSString *ct1 = arg1;
if (arg1 != nil) {
ct1 = [sp1 stringByAppendingString:arg1];
} else {
%orig(sp1);
}
if (hideTimeText) {
%orig(sp1);
} else {
%orig(ct1);
}
NSData *gifImageData = [currentGIFTheme getGIFData:@"animated.gif"];
UIImage *animatedimg = [UIImage animatedImageWithAnimatedGIFData:gifImageData];
UIImage *userCustomImage = [UIImage animatedImageWithAnimatedGIFData:userCustomImageData];
gifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, gifImagePadding, staticImageSize - 5, staticImageSize - 5)];
if (themesOrImage == 2) {
gifImage.image = animatedimg;
} else {
gifImage.image = userCustomImage;
}
[self addSubview:gifImage];
}
}
}
%end
%end
%group XENCustomText
%hook _UIStatusBarStringView
%property (nonatomic, assign) BOOL isServiceView;
%property (nonatomic, assign) BOOL isTime;
-(void)setText:(id)arg1 {
%orig;
if (whereToPutText == 0) {
textInFrontOfCarrierText = true;
textInFrontOfTimeText = false;
} else if (whereToPutText == 1) {
textInFrontOfCarrierText = false;
textInFrontOfTimeText = true;
} else if (whereToPutText == 2) {
textInFrontOfCarrierText = true;
textInFrontOfTimeText = true;
}
if (self.isServiceView) {
if (textInFrontOfCarrierText) {
NSString *carrierString = arg1;
NSString *spyString = customText;
NSString *statusString = [spyString stringByAppendingString:carrierString];
%orig(statusString);
}
}
if (self.isTime) {
if (textInFrontOfTimeText) {
NSString *timeString = arg1;
NSString *spyString = customText;
NSString *statusString = [spyString stringByAppendingString:timeString];
%orig(statusString);
}
}
if (!self.isTime && usingiPadStyle && [arg1 containsString:@":"]) {
if (textInFrontOfTimeText) {
NSString *timeString = arg1;
NSString *spyString = customText;
NSString *statusString = [spyString stringByAppendingString:timeString];
%orig(statusString);
}
}
}
%end
%end
%group XENCustomCarrier
%hook SBTelephonySubscriptionInfo
-(NSString *)operatorName {
if (%orig == nil) {
return nil;
} else {
return customCarrier;
}
}
%end
%end
%group XENCustomCellularText
%hook _UIStatusBarStringView
%property (nonatomic, assign) BOOL isServiceView;
%property (nonatomic, assign) BOOL isTime;
-(void)setText:(id)arg1 {
%orig;
if (!self.isServiceView && !self.isTime && ![arg1 containsString:@":"]) {
NSArray *cellularArray = [NSArray arrayWithObjects:@"2G", @"3G", @"4G", @"LTE", @"5Gᴱ", nil];
if ([cellularArray containsObject:arg1]) {
%orig(customCellularText);
} else {
%orig;
}
}
}
%end
%end
%group debug
%end
void loadPrefs() {
HBPreferences *file = [[HBPreferences alloc] initWithIdentifier:@"com.peterdev.xeon"];
//Tweak Enabled
isEnabled = [([file objectForKey:@"kEnabled"] ?: @(YES)) boolValue];
//Custom Image
isCustomImageEnabled = [([file objectForKey:@"kEnableCustomImage"] ?: @(YES)) boolValue];
whereToPutImage = [([file objectForKey:@"kWhereToPutImage"] ?: @(0)) intValue];
imageColor = [([file objectForKey:@"kCustomImageColor"] ?: @(1)) intValue];
themesOrImage = [([file objectForKey:@"kThemesOrImages"] ?: @(0)) intValue];
hideCarrierText = [([file objectForKey:@"kHideCarrierText"] ?: @(NO)) boolValue];
hideTimeText = [([file objectForKey:@"kHideTimeText"] ?: @(NO)) boolValue];
userCustomImageData = [file objectForKey:@"kUserCustomImage"];
usingiPadStyle = [([file objectForKey:@"kiPadStyle"] ?: @(NO)) boolValue];
staticImageSize = [([file objectForKey:@"kStaticImageSize"] ?: @(20)) intValue];
gifImagePadding = [([file objectForKey:@"kGIFPadding"] ?: @(0)) intValue];
//Custim Text
isCustomTextEnabled = [([file objectForKey:@"kEnableCustomText"] ?: @(NO)) boolValue];
whereToPutText = [([file objectForKey:@"kWhereToPutText"] ?: @(0)) intValue];
customText = [file objectForKey:@"kCustomText"];
if (!customText) customText = @"";
//Custom Carrier
isCustomCarrierEnabled = [([file objectForKey:@"kEnableCustomCarrier"] ?: @(NO)) boolValue];
customCarrier = [file objectForKey:@"kCustomCarrier"];
if (!customCarrier) customCarrier = nil;
//Custom Cellular Text
isCustomCellularTextEnabled = [([file objectForKey:@"kEnableCustomCellularText"] ?: @(NO)) boolValue];
customCellularText = [file objectForKey:@"kCustomCellularText"];
if (!customCellularText) customCellularText = @"";
//Other Settings
adjustFontSize = [([file objectForKey:@"kAdjustFontSize"] ?: @(YES)) boolValue];
//Custom Theme
NSString *iconTheme = [file objectForKey:@"IconTheme"];
if(!iconTheme){
iconTheme = @"Classic Apple";
}
currentTheme = [XENTheme themeWithPath:[XENThemesDirectory stringByAppendingPathComponent:iconTheme]];
//Custom GIF Theme
NSString *gifTheme = [file objectForKey:@"GIFTheme"];
if(!gifTheme){
gifTheme = @"Pac-Man";
}
currentGIFTheme = [XENGIFTheme gifThemeWithPath:[XENGIFThemesDirectory stringByAppendingPathComponent:gifTheme]];
}
%ctor {
loadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.peterdev.xeon/settingschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
if (isEnabled) {
if (debug) %init(debug);
if (!debug && (isCustomImageEnabled || isCustomTextEnabled)) %init(Xeon);
if (!debug && isCustomImageEnabled) %init(XENCustomImage);
if (!(themesOrImage == 2) && !(themesOrImage == 3)) {
if (!debug && isCustomTextEnabled) %init(XENCustomText);
}
if (!debug && isCustomCarrierEnabled) %init(XENCustomCarrier);
if (!debug && isCustomCellularTextEnabled) %init(XENCustomCellularText);
}
}