-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTweak.xm
54 lines (42 loc) · 1.66 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
#import "NSTask.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface SBIconController : UIViewController
- (void)executePing;
@end
BOOL timerAdded = NO;
NSDictionary *rootDict;
%hook SBIconController
- (void)viewDidLoad {
%orig;
rootDict = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/dev.ametrine.notiping.plist"];
BOOL shouldEnableNotiPing = [[rootDict objectForKey:@"enableTweak"] boolValue];
NSNumber *timerDelay = [rootDict objectForKey:@"timerDelay"];
double putIntoNSTimer = [timerDelay doubleValue];
if (shouldEnableNotiPing) {
if (!timerAdded) {
timerAdded = YES;
[NSTimer scheduledTimerWithTimeInterval:putIntoNSTimer target:self selector:@selector(executePing) userInfo:nil repeats:YES];
}
}
}
%new
- (void)executePing {
NSString *ipAddress = [rootDict objectForKey:@"ipAddress"];
NSString *alertText = [rootDict objectForKey:@"alertText"];
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/ping";
task.arguments = @[ipAddress, @"-c", @"1"];
[task launch];
[task waitUntilExit];
if (task.terminationStatus == 1) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"NotiPing"
message:alertText
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault
handler:nil];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
}
%end