-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
84 lines (59 loc) · 2.81 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
#import "BringBackSleep.h"
/*
This tweak was created out of boredom don't be stupid just use the actual Control Center for tvOS 13.
Copyright 2019 J.K. Hayslip (@iKilledAppl3) & ToxicAppl3 INSDC./iKilledAppl3 LLC.
Friday, December, 20, 2019 was a fun day for us all!
Anyways enjoy and remember not to spoil yourself!
*/
%hook TVSMMainViewController
-(void)viewDidLoad {
if (kEnabled) {
// Make sure we call this original view if not we can't add the alert view!
%orig;
//Hide the original view!
for (UIView *view in self.view.subviews) {
[view removeFromSuperview];
}
// call the main view controller of the application so we can push the alert to the main view.
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
//then call the alert controller
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Sleep Now?"
message:@"This will also turn off any connected devices."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Sleep" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//This is kinda hacky but hey it works :P
// Allocating the sleep module so we can call the sleep function.
TVSMSleepModule *sleepModule = [[%c(TVSMSleepModule) alloc] init];
[sleepModule handleAction];
// Here we need to release the view so we have to call this method....
// I haven't found a way around this yet... :/
TVSMSystemMenuManager *menuMan = [%c(TVSMSystemMenuManager) sharedInstance];
[menuMan dismissSystemMenu];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// Here we need to release the view so we have to call this method....
// I haven't found a way around this yet... :/
TVSMSystemMenuManager *menuMan = [%c(TVSMSystemMenuManager) sharedInstance];
[menuMan dismissSystemMenu];
}];
[alert addAction:defaultAction];
[alert addAction:cancel];
[vc presentViewController:alert animated:YES completion:nil];
}
else {
%orig;
}
}
%end
// Load preferences to make sure changes are written to the plist
static void loadPrefs() {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:PLIST_PATH];
//our preference values that write to a plist file when a user selects somethings
kEnabled = [([prefs objectForKey:@"kEnabled"] ?: @(YES)) boolValue];
}
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) loadPrefs, CFSTR("com.ikilledappl3.nosleeptilbrooklyn.prefschanged"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
loadPrefs();
}