-
Notifications
You must be signed in to change notification settings - Fork 1
/
Debug.x
78 lines (65 loc) · 2.23 KB
/
Debug.x
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
#import "Debug.h"
//int __isOSVersionAtLeast(int major, int minor, int patch) { NSOperatingSystemVersion version; version.majorVersion = major; version.minorVersion = minor; version.patchVersion = patch; return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:version]; }
extern NSString *bundleID;
@implementation Debug
static bool springboardReady = false;
+(UIWindow*) GetKeyWindow {
if (@available(iOS 13, *)) {
NSSet *connectedScenes = [UIApplication sharedApplication].connectedScenes;
for (UIScene *scene in connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *windowScene = (UIWindowScene *)scene;
for (UIWindow *window in windowScene.windows) {
if (window.isKeyWindow) {
return window;
}
}
}
}
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSArray *windows = [[UIApplication sharedApplication] windows];
#pragma clang diagnostic pop
for (UIWindow *window in windows) {
if (window.isKeyWindow) {
return window;
}
}
}
return nil;
}
// Shows an alert box. Used for debugging
+(void)ShowAlert:(NSString *)msg {
if (!springboardReady) return;
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"Alert"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
//Add Buttons
UIAlertAction* dismissButton = [UIAlertAction
actionWithTitle:@"Cool!"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Handle dismiss button action here
}];
//Add your buttons to alert controller
[alert addAction:dismissButton];
[[self GetKeyWindow].rootViewController presentViewController:alert animated:YES completion:nil];
}
// Show log with tweak name as prefix for easy grep
+(void)Log:(NSString *)msg {
if (!loggingEnabled)
return;
NSLog(@"%@ (%@): %@", TWEAK_NAME, bundleID, msg);
}
// Log exception info
+(void)LogException:(NSException *)e {
NSLog(@"%@: NSException caught", TWEAK_NAME);
NSLog(@"%@: Name:%@", TWEAK_NAME, e.name);
NSLog(@"%@: Reason:%@", TWEAK_NAME, e.reason);
}
+(void)SpringBoardReady {
springboardReady = true;
}
@end