This repository was archived by the owner on Jun 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathButtonController.m
executable file
·1173 lines (990 loc) · 51 KB
/
ButtonController.m
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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "ButtonController.h"
static bool stringsAreEqual(CFStringRef a, CFStringRef b)
{
if (!a || !b) return 0;
return (CFStringCompare(a, b, 0) == kCFCompareEqualTo);
}
static void update (void * context)
{
ButtonController * self = (__bridge ButtonController *) context;
CFTypeRef blob = IOPSCopyPowerSourcesInfo ();
CFArrayRef list = IOPSCopyPowerSourcesList (blob);
unsigned int count = CFArrayGetCount (list);
if (count == 0)
[self powerSourceChanged:POWER_AC];
unsigned int i = 0;
for (i = 0; i < count; i++)
{
CFTypeRef source;
CFDictionaryRef description;
source = CFArrayGetValueAtIndex (list, i);
description = IOPSGetPowerSourceDescription (blob, source);
if (stringsAreEqual (CFDictionaryGetValue (description, CFSTR (kIOPSTransportTypeKey)), CFSTR (kIOPSInternalType)))
{
CFStringRef currentState = CFDictionaryGetValue (description, CFSTR (kIOPSPowerSourceStateKey));
if (stringsAreEqual (currentState, CFSTR (kIOPSACPowerValue)))
[self powerSourceChanged:POWER_AC];
else if (stringsAreEqual (currentState, CFSTR (kIOPSBatteryPowerValue)))
[self powerSourceChanged:POWER_BATTERY];
//else
// [self powerSourceChanged:POWER_OTHER];
}
}
CFRelease (list);
CFRelease (blob);
}
@implementation ButtonController
#pragma mark NSApplication Methods
- (void) awakeFromNib
{
defaults = [NSUserDefaults standardUserDefaults];
//[defaults synchronize];
licence = [[NSUserDefaults standardUserDefaults] integerForKey:kReadmeVersion];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
CPUSafetyTemp = 100.0;
disableInsomniaFunction = false;
if (!licence)
[self makeReadme];
/* Setup the defaults */
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"CPUSafetyMaxTemp"] != nil)
CPUSafetyTemp = [[NSUserDefaults standardUserDefaults] floatForKey:@"CPUSafetyMaxTemp"];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"CPUSafety"] == nil)
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"CPUSafety"];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"debugMode"] != nil)
debug = [[NSUserDefaults standardUserDefaults] floatForKey:@"debugMode"];
[[NSUserDefaults standardUserDefaults] synchronize];
deviceModel = [self machineModel];
if ([deviceModel rangeOfString:@"MacBook"].location == NSNotFound && [[NSUserDefaults standardUserDefaults] objectForKey:@"modelCheck"] == nil) {
disableInsomniaFunction = true;
[statusInsomniaItem setEnabled:false];
[statusInsomniaItem setHidden:true];
[CPUSafetyItem setHidden:true];
[lidHotKeyItem setHidden:true];
[disableLidSleepForItem setHidden:true];
[disableLidSleepOnACItem setHidden:true];
NSLog(@"Device is not MacBook(%@), Insomnia features disabled!", deviceModel);
}
/********************************
InsomniaX Functions
********************************/
if (!disableInsomniaFunction) {
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"CPUSensorKey"] != nil) {
smcSensorKey = (char*)[[[NSUserDefaults standardUserDefaults] stringForKey:@"CPUSensorKey"] UTF8String];
smc_init();
if (SMCGetTemperature(smcSensorKey) == -1.0) {
NSLog(@"ERROR: Custom defined sensor %s is not valid, return to default", smcSensorKey);
if (SMCGetTemperature(SMC_KEY_CPU_TEMP) != -1.0) {
smcSensorKey = SMC_KEY_CPU_TEMP;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_DIODE) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_DIODE;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_HEATSINK) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_HEATSINK;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_PROXIMITY) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_PROXIMITY;
} else if (SMCGetTemperature(SMC_KEY_AMBIENT_AIR_0) != -1.0) {
smcSensorKey = SMC_KEY_AMBIENT_AIR_0;
} else if (SMCGetTemperature(SMC_KEY_AMBIENT_AIR_1) != -1.0) {
smcSensorKey = SMC_KEY_AMBIENT_AIR_1;
} else {
NSRunAlertPanel(@"InsomniaX", @"ERROR: Unable to find a temperature sensor to monitor for safety system, safety system is disabled, please contact support!", @"Ok", nil, nil);
NSLog(@"ERROR: Unable to find a temperature sensor to monitor for safety system, safety system is disabled, please contact support!");
cpuSafetyIsAvailable = false;
}
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%s",smcSensorKey] forKey:@"CPUSensorKey"];
}
smc_close();
//NSLog(@"Loading from defaults");
} else {
// Lets try to find the key for the first sensor we find
smc_init();
//NSLog(@"Scanning");
if (SMCGetTemperature(SMC_KEY_CPU_TEMP) != -1.0) {
smcSensorKey = SMC_KEY_CPU_TEMP;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_DIODE) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_DIODE;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_HEATSINK) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_HEATSINK;
} else if (SMCGetTemperature(SMC_KEY_CPU_0_PROXIMITY) != -1.0) {
smcSensorKey = SMC_KEY_CPU_0_PROXIMITY;
} else if (SMCGetTemperature(SMC_KEY_AMBIENT_AIR_0) != -1.0) {
smcSensorKey = SMC_KEY_AMBIENT_AIR_0;
} else if (SMCGetTemperature(SMC_KEY_AMBIENT_AIR_1) != -1.0) {
smcSensorKey = SMC_KEY_AMBIENT_AIR_1;
} else {
NSRunAlertPanel(@"InsomniaX", @"ERROR: Unable to find a temperature sensor to monitor for safety system, safety system is disabled, please contact support!", @"Ok", nil, nil);
NSLog(@"ERROR: Unable to find a temperature sensor to monitor for safety system, safety system is disabled, please contact support!");
cpuSafetyIsAvailable = false;
}
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%s",smcSensorKey] forKey:@"CPUSensorKey"];
smc_close();
}
if (debug && cpuSafetyIsAvailable) NSLog(@"Monitoring sensor %s", smcSensorKey);
if (!cpuSafetyIsAvailable) {
// Disable CPU Safety Menu
[CPUSafetyItem setState:NSOffState];
[CPUSafetyItem setEnabled:false];
[CPUSafetyItem setTitle:@"CPU Safety is unavailable"];
} else {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"CPUSafety"])
[CPUSafetyItem setState:NSOnState];
}
/* Install latest InsomniaX */
NSString *supportPath = [NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"Library/Application Support/%@", [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleName"]]];
//NSBundle *bundle = [NSBundle mainBundle];
insomniaPath = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/%@", supportPath, insomnia_name]];
if (![[NSFileManager defaultManager] fileExistsAtPath:insomniaPath]){
NSLog(@"Installing Latest Kext");
NSString *source = [[[[[NSBundle mainBundle] bundlePath]
stringByAppendingPathComponent:@"Contents"]
stringByAppendingPathComponent:@"Resources"]
stringByAppendingPathComponent:insomnia_name];
if ([[NSFileManager defaultManager] fileExistsAtPath:source]) {
[[NSFileManager defaultManager] createDirectoryAtPath:supportPath withIntermediateDirectories:YES attributes:nil error:nil];
[[NSFileManager defaultManager] copyItemAtPath:source toPath:[supportPath stringByAppendingPathComponent:insomnia_name] error:NULL];
}
NSLog(@"Latest Insomnia kext is installed at %@", insomniaPath);
}
/* Initialise and configure the loader */
myInitAuthCommand();
}
/******************************** Status Item ********************************/
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
LidSleepImage = [NSImage imageNamed:@"LidSleep"];
[LidSleepImage setTemplate:true];
LidIdleSleepImage = [NSImage imageNamed:@"LidIdleSleep"];
[LidIdleSleepImage setTemplate:true];
IdleSleepImage = [NSImage imageNamed:@"IdleSleep"];
[IdleSleepImage setTemplate:true];
NormalImage = [NSImage imageNamed:@"Normal"];
[NormalImage setTemplate:true];
[statusItem setImage:NormalImage];
[statusItem setMenu:statusMenu];
[statusItem setHighlightMode:YES];
/******************************** Load on Login Item ********************************/
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
BOOL launch = [launchController launchAtLogin];
if (launch)
[StartOnLoginItem setState:NSOnState];
else
[StartOnLoginItem setState:NSOffState];
/*************************** Auto load functions **************************/
[disableIdleSleepOnACItem setState:[[NSUserDefaults standardUserDefaults] integerForKey:@"disableIdleSleepOnAC"]];
[disableLidSleepOnACItem setState:[[NSUserDefaults standardUserDefaults] integerForKey:@"disableLidSleepOnAC"]];
/* Power Source Notification */
powerNotifierRunLoopSource = IOPSNotificationCreateRunLoopSource (update, (__bridge void *)(self));
if (powerNotifierRunLoopSource)
CFRunLoopAddSource (CFRunLoopGetCurrent(), powerNotifierRunLoopSource, kCFRunLoopDefaultMode);
/* Sets the hotkey */
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"idleKeyFlags"] != 0){
int keyCombo = [[NSUserDefaults standardUserDefaults] integerForKey:@"idleKeyCombo"];
int keyFlags = [[NSUserDefaults standardUserDefaults] integerForKey:@"idleKeyFlags"];
[idleSR setKeyCombo:SRMakeKeyCombo(keyCombo, keyFlags)];
}
// Why load something thats not available?
if (!disableInsomniaFunction) {
if (!disableInsomniaFunction && [[NSUserDefaults standardUserDefaults] integerForKey:@"lidKeyFlags"] != 0){
int keyCombo = [[NSUserDefaults standardUserDefaults] integerForKey:@"lidKeyCombo"];
int keyFlags = [[NSUserDefaults standardUserDefaults] integerForKey:@"lidKeyFlags"];
[lidSR setKeyCombo:SRMakeKeyCombo(keyCombo, keyFlags)];
}
}
/* Sets the hotkey */
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"displaySleepKeyFlags"] != 0){
int keyCombo = [[NSUserDefaults standardUserDefaults] integerForKey:@"displaySleepKeyCombo"];
int keyFlags = [[NSUserDefaults standardUserDefaults] integerForKey:@"displaySleepKeyFlags"];
[displaySleepSR setKeyCombo:SRMakeKeyCombo(keyCombo, keyFlags)];
}
/******************************** Sounds ********************************/
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"sound"] == TRUE){
loadSound = [NSSound soundNamed:@"beep3"];
unloadSound = [NSSound soundNamed:@"beep4"];
idleEnableSound = [NSSound soundNamed:@"beep1"];
idleDisableSound = [NSSound soundNamed:@"beep2"];
[soundMenuItem setState:NSOnState];
}
[defaults synchronize];
if ([defaults boolForKey:@"saveStateOnExit"] == TRUE) {
if (!disableInsomniaFunction && [defaults boolForKey:@"lidSleepState"]) {
[self setInsomniaState:true];
[defaults setBool:false forKey:@"lidSleepState"];
}
if ([defaults boolForKey:@"idleSleepState"]) {
[self setIdleSleepState:true];
[defaults setBool:false forKey:@"idleSleepState"];
}
}
[self setStatusIcon];
[self setInsomniaStatus];
if (!disableInsomniaFunction && [[NSUserDefaults standardUserDefaults] boolForKey:@"CPUSafety"] && [self insomniaState]) {
[self setCPUSafetyState:TRUE];
}
/************** Background Thread ****************/
systemTimer = [NSTimer scheduledTimerWithTimeInterval: 60
target: self
selector: @selector(backgroundThread:)
userInfo: nil
repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:systemTimer forMode:NSDefaultRunLoopMode];
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(appWillTerminate:)
name:NSApplicationWillTerminateNotification
object:nil];
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
return YES;
}
-(void)sendNotificationWithTitle:(NSString *)title andText:(NSString *)text{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = title;
notification.informativeText = text;
notification.soundName = NSUserNotificationDefaultSoundName;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
-(void)backgroundThread:(NSTimer *)timer{
if (enableLidSleepTimer != nil) {
NSDate *lidSleepTimerFire = [enableLidSleepTimer fireDate];
NSTimeInterval timeInterval = [lidSleepTimerFire timeIntervalSinceNow];
[disableLidSleepForItem setTitle:[NSString stringWithFormat:@"Lid Sleep will be enabled in %@",[self convertTimeIntervalToString:timeInterval]]];
}
if (enableIdleSleepTimer != nil) {
NSDate *idleSleepTimerFire = [enableIdleSleepTimer fireDate];
NSTimeInterval timeInterval = [idleSleepTimerFire timeIntervalSinceNow];
[disableIdleSleepForItem setTitle:[NSString stringWithFormat:@"Idle Sleep will be enabled in %@",[self convertTimeIntervalToString:timeInterval]]];
}
}
-(NSString*)convertTimeIntervalToString:(NSTimeInterval)timeInterval {
NSInteger ti = (NSInteger)timeInterval;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
NSInteger hours = (ti / 3600);
NSString *title;
if (hours > 0 && minutes == 0) {
title = [NSString stringWithFormat:@"%ld hours", hours];
} else if (hours > 0) {
title = [NSString stringWithFormat:@"%ld hours and %ld minutes", hours, minutes];
} else if (minutes > 2) {
title = [NSString stringWithFormat:@"%ld minutes", minutes];
} else if (minutes > 0 && seconds == 0) {
title = [NSString stringWithFormat:@"%ld minutes", minutes];
} else if (minutes > 0) {
title = [NSString stringWithFormat:@"%ld minutes and %ld seconds", minutes, seconds];
} else {
title = [NSString stringWithFormat:@"%ld seconds", seconds];
}
return title;
}
/*
NSApp - Terminate Notification
Notify user if they still have Insomnia loaded
*/
- (IBAction)quitInsomniaX:(id)sender{
bool lidSleepState = [self insomniaState];
bool idleSleepState = [self getIdleSleepState];
if (idleSleepState) {
[NSApp activateIgnoringOtherApps:YES];
if (NSRunAlertPanel(@"InsomniaX",@"Idle Sleep is Disabled, Idle Sleep will be returned to normal if you continue",@"Continue",@"Cancel",NULL) == NSAlertAlternateReturn)
return;
[self setIdleSleepState:false];
}
if (lidSleepState){
[NSApp activateIgnoringOtherApps:YES];
if (NSRunAlertPanel(@"InsomniaX",@"Lid Sleep is Disabled, Lid Sleep will be returned to normal if you continue",@"Continue",@"Cancel",NULL) == NSAlertAlternateReturn)
return;
[self setInsomniaState:false];
}
[NSApp terminate:self];
}
- (void)appWillTerminate:(NSApplication *)sender{
bool lidSleepState = [self insomniaState];
bool idleSleepState = [self getIdleSleepState];
[defaults synchronize];
if ([defaults boolForKey:@"saveStateOnExit"] == TRUE) {
if (enableLidSleepTimer == nil) {
[defaults setBool:lidSleepState forKey:@"lidSleepState"];
}
if (enableIdleSleepTimer == nil) {
[defaults setBool:idleSleepState forKey:@"idleSleepState"];
}
}
//return NSTerminateCancel;
}
#pragma mark Menu Items
- (IBAction)insomnia:(id)sender
{
if (!licence){
[self makeReadme];
} else {
int state = [self insomniaState];
if (state) {
[self setInsomniaState:false];
} else {
[self setInsomniaState:true];
}
}
}
- (IBAction)idleSleepItem:(id)sender {
if (!licence){
[self makeReadme];
} else {
if ([self getIdleSleepState]) {
[self setIdleSleepState:false];
} else {
[self setIdleSleepState:true];
}
}
}
- (IBAction)disableLidSleepFor:(id)sender{
int timerLength = [disableLidSleepForSlider intValue];
if (enableLidSleepTimer == nil) {
enableLidSleepTimer = [NSTimer scheduledTimerWithTimeInterval: timerLength * 60
target: self
selector: @selector(disableLidSleepForTimer:)
userInfo: nil
repeats: NO];
[[NSRunLoop currentRunLoop] addTimer:enableLidSleepTimer forMode:NSDefaultRunLoopMode];
}
[disableLidSleepForItem setTitle:[NSString stringWithFormat:@"Lid Sleep will be enabled in %@", [self convertTimeIntervalToString:timerLength * 60]]];
[disableLidSleepForItem setEnabled:NO];
[self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Schedulded" andText:[NSString stringWithFormat:@"Lid Sleep will be enabled in %@", [self convertTimeIntervalToString:timerLength * 60]]];
[self setInsomniaState:true];
if (debug) NSLog(@"Disabling lid sleep for %i seconds", timerLength);
NSWindow *theWindow = [sender window];
[theWindow close];
}
-(void)disableLidSleepForTimer:(NSTimer *)timer{
[self setInsomniaState:false];
// [NSThread sleepForTimeInterval:1.0f];
// [self setInsomniaStatus];
[disableLidSleepForItem setTitle:@"Disable Lid Sleep For..."];
[disableLidSleepForItem setEnabled:true];
[enableLidSleepTimer invalidate];
enableLidSleepTimer = nil;
[self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Enabled" andText:@"Lid Sleep was enabled as scheduled"];
NSLog(@"Enabling lid sleep as per schedule");
}
- (IBAction)disableIdleSleepFor:(id)sender{
int timerLength = [disableIdleSleepForSlider intValue];
if (enableIdleSleepTimer == nil) {
enableIdleSleepTimer = [NSTimer scheduledTimerWithTimeInterval: timerLength * 60
target: self
selector: @selector(disableIdleSleepForTimer:)
userInfo: nil
repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:enableIdleSleepTimer forMode:NSDefaultRunLoopMode];
}
[disableIdleSleepForItem setTitle:[NSString stringWithFormat:@"Idle Sleep will be enabled in %@", [self convertTimeIntervalToString:timerLength * 60]]];
[disableIdleSleepForItem setEnabled:NO];
[self sendNotificationWithTitle:@"InsomniaX: Idle Sleep Schedulded" andText:[NSString stringWithFormat:@"Idle Sleep will be enabled in %@", [self convertTimeIntervalToString:timerLength * 60]]];
[self setIdleSleepState:true];
if (debug) NSLog(@"Disabling idle sleep for %i seconds", timerLength);
NSWindow *theWindow = [sender window];
[theWindow close];
}
-(void)disableIdleSleepForTimer:(NSTimer *)timer{
[self setIdleSleepState:false];
[disableIdleSleepForItem setTitle:@"Disable Idle Sleep For..."];
[disableIdleSleepForItem setEnabled:true];
[enableIdleSleepTimer invalidate];
enableIdleSleepTimer = nil;
[self sendNotificationWithTitle:@"InsomniaX: Idle Sleep Enabled" andText:@"Idle Sleep was enabled as scheduled"];
NSLog(@"Enabling idle sleep as per schedule");
}
- (IBAction)CPUSafety:(id)sender {
[[NSUserDefaults standardUserDefaults] synchronize];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"CPUSafety"] == FALSE) {
if ([self insomniaState]) {
NSLog(@"Found Insomnia Loaded will now engage CPU Safety");
[self setCPUSafetyState:TRUE];
}
[CPUSafetyItem setState:NSOnState];
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"CPUSafety"];
} else {
[self setCPUSafetyState:FALSE];
[[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"CPUSafety"];
[CPUSafetyItem setState:NSOffState];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)setStatusIcon {
bool lidSleepState = [self insomniaState];
bool idleSleepState = [self getIdleSleepState];
if (lidSleepState && idleSleepState)
[statusItem setImage:LidIdleSleepImage];
else if (lidSleepState)
[statusItem setImage:LidSleepImage];
else if (idleSleepState)
[statusItem setImage:IdleSleepImage];
else
[statusItem setImage:NormalImage];
}
- (IBAction)soundItem:(id)sender{
[[NSUserDefaults standardUserDefaults] synchronize];
//NSLog(@"Sound Item %@", [[NSUserDefaults standardUserDefaults] integerForKey:@"sound"]);
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"sound"] == FALSE){
loadSound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"beep3" ofType:@"wav"]
byReference:YES];
unloadSound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"beep4" ofType:@"wav"]
byReference:YES];
idleEnableSound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"beep1" ofType:@"wav"]
byReference:YES];
idleDisableSound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"beep2" ofType:@"wav"]
byReference:YES];
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"sound"];
[soundMenuItem setState:NSOnState];
if (debug) NSLog(@"Sounds enabled");
} else {
loadSound = nil;
unloadSound = nil;
idleDisableSound = nil;
idleEnableSound = nil;
[[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"sound"];
[soundMenuItem setState:NSOffState];
if (debug) NSLog(@"Sounds disabled");
}
}
#pragma mark AUTO Load Menu Items
- (IBAction)aboutItem:(id)sender{
[[NSApplication sharedApplication] orderFrontStandardAboutPanel:nil];
[NSApp activateIgnoringOtherApps:YES];
}
- (IBAction)disableLidSleepOnAC:(id)sender {
if ([defaults integerForKey:@"disableLidSleepOnAC"] == true) {
[disableLidSleepOnACItem setState:NSOffState];
[defaults setBool:false forKey:@"disableLidSleepOnAC"];
[defaults setBool:false forKey:@"enableLidSleepOnBattery"];
if (debug) NSLog(@"Enabling lid sleep on AC");
} else {
[disableLidSleepOnACItem setState:NSOnState];
[defaults setBool:true forKey:@"disableLidSleepOnAC"];
[defaults setBool:true forKey:@"enableLidSleepOnBattery"];
if (debug) NSLog(@"Disabling lid sleep on AC");
NSRunAlertPanel(@"InsomniaX", @"Lid sleep will be disabled while on charger, and enabled while on battery", @"Ok", nil, nil);
}
[defaults synchronize];
}
- (IBAction)disableIdleSleepOnAC:(id)sender {
if ([defaults integerForKey:@"disableIdleSleepOnAC"] == NSOnState) {
[disableIdleSleepOnACItem setState:NSOffState];
[defaults setBool:false forKey:@"disableIdleSleepOnAC"];
[defaults setBool:false forKey:@"enableIdleSleepOnBattery"];
if (debug) NSLog(@"Enabling idle sleep on AC");
} else {
[disableIdleSleepOnACItem setState:NSOnState];
[defaults setBool:true forKey:@"disableIdleSleepOnAC"];
[defaults setBool:true forKey:@"enableIdleSleepOnBattery"];
if (debug) NSLog(@"Disabling idle sleep on AC");
NSRunAlertPanel(@"InsomniaX", @"Idle sleep will be disabled while on charger, and enabled while on battery", @"Ok", nil, nil);
}
[defaults synchronize];
}
- (IBAction)startOnLogin:(id)sender {
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
BOOL launch = [launchController launchAtLogin];
if (launch) {
[launchController setLaunchAtLogin:NO];
[StartOnLoginItem setState:NSOffState];
if (debug) NSLog(@"Enabling start at login");
} else {
[launchController setLaunchAtLogin:YES];
[StartOnLoginItem setState:NSOnState];
if (debug) NSLog(@"Disabling start at login");
}
}
/* Sleep the display */
- (IBAction)sleepDisplay:(id)sender{
if (!licence){
[self makeReadme];
NSLog(@"Licence not accepted!");
} else {
io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (r) {
IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue);
IOObjectRelease(r);
}
}
}
/* Locates the readme file and opens it */
- (IBAction)readmeItem:(id)sender {
[NSApp activateIgnoringOtherApps:YES];
[self makeReadme];
}
#pragma mark Insomnia
-(BOOL)insomniaState{
BOOL kextState;
CFURLRef bundleURL = KextManagerCreateURLForBundleIdentifier(NULL, (CFStringRef)insomnia_id);
if (bundleURL == nil) {
kextState = FALSE;
} else {
kextState = TRUE;
}
bundleURL = nil;
if (debug) NSLog(@"Insomnia: %@", kextState ? @"Loaded" : @"Unloaded");
return kextState;
}
-(void)setInsomniaStatus{
int state = [self insomniaState];
if (state) {
[statusInsomniaItem setState:NSOnState];
//[self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Disabled" andText:@"Lid Sleep is disabled"];
}
else {
[statusInsomniaItem setState:NSOffState];
//[self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Enabled" andText:@"Lid Sleep is enabled"];
}
[self setStatusIcon];
}
- (void)setInsomniaState:(BOOL)state{
//int result;
if (!licence){
NSLog(@"Licence not accepted!");
[self makeReadme];
//result = 1;
} else if (disableInsomniaFunction){
NSLog(@"Insomnia Functions are currently disabled!");
} else {
CFURLRef bundleURL = KextManagerCreateURLForBundleIdentifier(NULL, (CFStringRef)@"org.binaervarianz.driver.insomnia");
if (bundleURL != nil) {
NSLog(@"We found a copy of another Insomnia loaded, ABORT!");
NSRunAlertPanel(@"InsomniaX", @"ERROR: We found another version of Insomnia loaded, we can not continue with this conflict", @"Ok", nil, nil);
} else {
const char *CinsomniaPath = [insomniaPath UTF8String];
if (!state) {
if ([self insomniaState])
myPerformAuthCommand(kMyAuthorizedUnload, (char*)CinsomniaPath);
[self setCPUSafetyState:FALSE];
if ([defaults integerForKey:@"sound"] && loadSound != nil){
[loadSound play];
}
if (enableLidSleepTimer != nil) {
[disableLidSleepForItem setTitle:@"Disable Lid Sleep For..."];
[disableLidSleepForItem setEnabled:true];
[enableLidSleepTimer invalidate];
enableLidSleepTimer = nil;
}
if (debug) NSLog(@"Enabling Lid Sleep");
} else {
if (![self insomniaState])
myPerformAuthCommand(kMyAuthorizedLoad, (char*)CinsomniaPath);
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"CPUSafety"] == NSOnState) {
[self setCPUSafetyState:TRUE];
}
if ([defaults integerForKey:@"sound"] && unloadSound != nil){
[unloadSound play];
}
if (debug) NSLog(@"Disabling Lid Sleep");
}
}
//[NSApp activateIgnoringOtherApps:YES];
}
[NSThread sleepForTimeInterval:1.0f];
[self setInsomniaStatus];
// int insomniaState = [self insomniaState];
// if (insomniaState) {
// [self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Disabled" andText:@"Lid Sleep is disabled"];
// }
// else {
// [self sendNotificationWithTitle:@"InsomniaX: Lid Sleep Enabled" andText:@"Lid Sleep is enabled"];
// }
//return result;
}
- (IBAction)runDiagnostics:(id)sender {
NSLog(@"Performing diagnostics");
if (disableInsomniaFunction) {
NSLog(@"Insomnia functions are disabled, skipping Insomnia diagnostics");
} else {
CFURLRef bundleURL;
bundleURL = KextManagerCreateURLForBundleIdentifier(NULL, (CFStringRef)@"org.binaervarianz.driver.insomnia");
if (bundleURL != nil) {
NSLog(@"org.binaervarianz.driver.insomnia is loaded, this will be an issue");
NSRunAlertPanel(@"InsomniaX", @"ERROR: We found another version of Insomnia loaded, this will cause issues, this Insomnia was loaded by a 3rd party", @"Ok", nil, nil);
}
bundleURL = KextManagerCreateURLForBundleIdentifier(NULL, (CFStringRef)@"net.semaja2.kext.insomnia");
if (bundleURL != nil) {
NSLog(@"net.semaja2.kext.insomnia was already loaded, we will unload before diagnostics");
NSRunAlertPanel(@"InsomniaX", @"WARNING: Lid Sleep is current disabled, we will disable for diagnostics", @"Ok", nil, nil);
[self setInsomniaState:false];
}
NSLog(@"Running Insomnia diagnostics");
myPerformAuthCommand(kMyAuthorizedDiag, "null");
}
NSRunAlertPanel(@"InsomniaX", @"Please wait while the diagnostics report is generated, this may take a few minutes", @"Ok", nil, nil);
[NSThread sleepForTimeInterval:2.0f];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/sbin/system_profiler"];
[task setArguments:@[ @"-xml" ]];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDesktopDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *outputFile = [documentsDirectory stringByAppendingString: [NSString stringWithFormat:@"/InsomniaX-Diagnostics-%f.spx", NSDate.date.timeIntervalSince1970 ]];
[[NSFileManager defaultManager] createFileAtPath:outputFile contents:nil attributes:nil];
NSFileHandle *outputHandle = [NSFileHandle fileHandleForWritingAtPath:outputFile];
[task setStandardOutput:outputHandle];
[task waitUntilExit];
[task launch];
[outputHandle closeFile];
[NSThread sleepForTimeInterval:8.0f];
NSRunAlertPanel(@"InsomniaX", @"Please send the diagnostics data on your desktop to [email protected]", @"Ok", nil, nil);
}
- (IBAction)uninstall:(id)sender {
// int result = NSRunAlertPanel(@"InsomniaX", @"InsomniaX will now return lid/idle sleep to normal, and remove its self", @"Uninstall", @"Cancel", nil);
//
// myPerformAuthCommand(kMyAuthorizedRemove, "null");
// NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
// [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
// [[NSFileManager defaultManager] removeFileAtPath:[[NSBundle mainBundle] bundlePath] handler:nil];
// [NSApp terminate:self];
}
#pragma mark Idle Display Sleep
-(void)setIdleSleepState:(bool)state{
if (!state) {
if (debug) NSLog(@"Enabling Idle Sleep");
// /* prevent the system from sleeping */
// IOReturn success;
// CFStringRef reasonForActivity= CFStringCreateWithCString( kCFAllocatorDefault, ("InsomniaX Idle Sleep"), kCFStringEncodingUTF8 );
// //if ( [self activeVideoPlayback] )
// // success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
// //else
// success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
// CFRelease( reasonForActivity );
// if (success == kIOReturnSuccess) {
// if (debug) NSLog(@"Idle Sleep disabled by IOKit");
// [statusIdleSleepItem setState:NSOffState];
// if ([defaults integerForKey:@"sound"] && idleDisableSound != nil){
// [idleDisableSound play];
// }
// } else {
// if (debug) NSLog(@"failed to prevent system sleep through IOKit");
// [self sendNotificationWithTitle:@"InsomniaX: Failed" andText:@"Failed to disable idle sleep"];
// }
if (jigglerTimer != nil) {
[jigglerTimer invalidate];
jigglerTimer = nil;
[statusIdleSleepItem setState:NSOffState];
if ([defaults integerForKey:@"sound"] && idleDisableSound != nil){
[idleDisableSound play];
}
//[statusIdleSleepItem setTitle:@"Disable Idle Sleep"];
}
if (enableIdleSleepTimer != nil) {
[disableIdleSleepForItem setTitle:@"Disable Idle Sleep For..."];
[disableIdleSleepForItem setEnabled:true];
[enableIdleSleepTimer invalidate];
enableIdleSleepTimer = nil;
}
//[self sendNotificationWithTitle:@"InsomniaX: Idle Sleep Enabled" andText:@"Idle Sleep is enabled"];
} else {
if (debug) NSLog(@"Disabling Idle Sleep");
// /* allow the system to sleep again */
// //if (debug) NSLog(@"releasing sleep blocker (%i)" , systemSleepAssertionID );
// IOPMAssertionRelease( systemSleepAssertionID );
// [statusIdleSleepItem setState:NSOnState];
// if ([defaults integerForKey:@"sound"] && idleEnableSound != nil){
// [idleEnableSound play];
// }
if (jigglerTimer == nil) {
jigglerTimer = [NSTimer scheduledTimerWithTimeInterval: 5
target: self
selector: @selector(shakeIt:)
userInfo: nil
repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:jigglerTimer forMode:NSDefaultRunLoopMode];
//[statusIdleSleepItem setTitle:@"Enable Idle Sleep"];
[statusIdleSleepItem setState:NSOnState];
if ([defaults integerForKey:@"sound"] && idleEnableSound != nil){
[idleEnableSound play];
}
}
//[self sendNotificationWithTitle:@"InsomniaX: Idle Sleep Disabled" andText:@"Idle Sleep is disabled"];
}
[self setStatusIcon];
}
-(bool)getIdleSleepState{
bool state;
if (jigglerTimer != nil)
state = TRUE;
else
state = FALSE;
return state;
}
-(void)shakeIt:(NSTimer *)timer{
UpdateSystemActivity(0);
}
#pragma mark Readme
-(void)makeReadme{
NSLog(@"Displaying readme dialog");
if (readmePanel == nil) {
NSView *readmeView;
NSRect screenRect = [[NSScreen mainScreen] frame];
float x = screenRect.size.width/2 - 225;
float y = screenRect.size.height/2 - 300;
NSRect windowRect = NSMakeRect(x,y,650,450);
readmePanel = [[NSPanel alloc] initWithContentRect:windowRect
styleMask:NSTitledWindowMask | NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:[NSScreen mainScreen]];
//[readmePanel setReleasedWhenClosed:YES];
[readmePanel setTitle:NSLocalizedString(@"readmeTitle", @"Readme Panel Title")];
[readmePanel center];
[readmePanel setReleasedWhenClosed:FALSE];
readmeView = [[NSView alloc] initWithFrame:windowRect];
NSImage *logo;
logo = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"InsomniaX" ofType:@"icns"]];
NSImageView *logoView;
logoView = [[NSImageView alloc] initWithFrame:NSMakeRect(8,windowRect.size.height - 12 -128,128,128)];
[logoView setImage:logo];
[readmeView addSubview:logoView];
NSTextField *versionNumber;
versionNumber = [[NSTextField alloc] initWithFrame:NSMakeRect(12,50,128,40)];
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:14.0] forKey:NSFontAttributeName];
NSDictionary *bolddict = [NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:14.0] forKey:NSFontAttributeName];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"InsomniaX" attributes:bolddict];
//NSString *strVersion;
//strVersion = [[NSString alloc] initWithString:[NSString stringWithFormat:@"\n Version: %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]]];
[str appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n Version: %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]] attributes:dict]];
[versionNumber setAttributedStringValue:str];
[versionNumber setBordered:NO];
[versionNumber setAlignment:NSCenterTextAlignment];
[versionNumber setEditable:NO];
[versionNumber setDrawsBackground:NO];
[readmeView addSubview:versionNumber];
NSTextView *message = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,650-142-12-16,800)];
[message setEditable:NO];
[message setRichText:YES];
[message readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"Readme" ofType:@"rtf"]];
NSScrollView *myScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(142,windowRect.size.height - (windowRect.size.height - 72) - 12,650-142-12,windowRect.size.height - 72)];
[myScrollView setDocumentView:message];
[myScrollView setHasVerticalScroller:YES];
[myScrollView setAutohidesScrollers:YES];
[myScrollView setBorderType:NSGrooveBorder];
[readmeView addSubview:myScrollView];
logoSubText = [[NSTextField alloc] initWithFrame:NSMakeRect(12,windowRect.size.height - 12 - 256 -12 -128,128,256)];
[logoSubText setStringValue:NSLocalizedString(@"readmeLicence", @"Readme Panel Licence")];
[logoSubText setBordered:NO];
//[logoSubText setAlignment:NSJustifiedTextAlignment];
[logoSubText setEditable:NO];
[logoSubText setDrawsBackground:NO];
[readmeView addSubview:logoSubText];
agreeButton = [[NSButton alloc] initWithFrame:NSMakeRect((650 - 100 - 12),12,100,32)];
[agreeButton setButtonType:NSMomentaryPushInButton];
[agreeButton setBezelStyle:NSRoundedBezelStyle];
[agreeButton setAction:@selector(acceptButton:)];
[agreeButton setTarget:self];
[agreeButton setTitle:NSLocalizedString(@"Agree", @"Agree")];
[readmeView addSubview:agreeButton];
disagreeButton = [[NSButton alloc] initWithFrame:NSMakeRect((650 - 100 - 100 - 12 - 12),12,100,32)];
[disagreeButton setButtonType:NSMomentaryPushInButton];
[disagreeButton setBezelStyle:NSRoundedBezelStyle];
[disagreeButton setAction:@selector(terminate:)];
[disagreeButton setTarget:NSApp];
[disagreeButton setTitle:NSLocalizedString(@"Disagree", @"Disagree")];
[readmeView addSubview:disagreeButton];
[readmePanel setContentView:readmeView];
}
if ([defaults boolForKey:kReadmeVersion] == TRUE) {
[logoSubText setHidden:TRUE];
[disagreeButton setHidden:TRUE];
[agreeButton setTitle:NSLocalizedString(@"Ok", @"Ok")];
[agreeButton setAction:@selector(close)];
[agreeButton setTarget:readmePanel];
}
//[readmeView autorelease];
[readmePanel makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
}
-(IBAction)acceptButton:(id)sender{
[defaults setBool:TRUE forKey:kReadmeVersion];
[defaults synchronize];
licence = [defaults integerForKey:kReadmeVersion];
[readmePanel close];
}
#pragma mark Temperature Safety
-(float)getTemperatureForKey:(char*)key {
smc_init();
float temperature = SMCGetTemperature(key);
if (debug) NSLog(@"CPU Temp: %f", temperature);
smc_close();
return temperature;
}
-(void)CPUSafetyCheck:(NSTimer *)timer{
//If Insomnia is not even loaded lets skip the check and remove the check
if ([self insomniaState]) {
float CPUTemp = [self getTemperatureForKey:smcSensorKey];
if (debug) NSLog(@"Max CPU Temp: %f, Current CPU Temp: %f", CPUSafetyTemp, CPUTemp);
if (CPUTemp > CPUSafetyTemp) {
[self setInsomniaState:false];
NSLog(@"Returning lid sleep to normal as CPU exceeded safe limits");
NSRunAlertPanel(@"InsomniaX", @"Lid Sleep was returned to normal due to the CPU exceeding safe limits", @"Ok", nil, nil);
[self sendNotificationWithTitle:@"InsomniaX: CPU Safety" andText:@"Lid Sleep was enabled as the CPU temperature exceeded safety limits"];
}
} else {
NSLog(@"Could not find Insomnia disable CPU check");
[self setCPUSafetyState:FALSE];
}
}
-(void)setCPUSafetyState:(BOOL)state{
/* CPU Safety Timer */
if (!cpuSafetyIsAvailable) {
NSLog(@"Unable to enable CPU Safety due to missing sensors!");
} else if (state) {
if (debug) NSLog(@"Engage CPU Safety");
CPUTempSafetyTimer = [NSTimer scheduledTimerWithTimeInterval: 30
target: self
selector: @selector(CPUSafetyCheck:)
userInfo: nil
repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:CPUTempSafetyTimer forMode:NSDefaultRunLoopMode];
} else {
if (debug) NSLog(@"Disengage CPU Safety");
if (CPUTempSafetyTimer != nil) {
[CPUTempSafetyTimer invalidate];
CPUTempSafetyTimer = nil;
}
}
}
#pragma mark Power
-(void)powerSourceChanged:(unsigned int) status{
//NSLog(@"Powerevent");
if (intLastPowerState != status) {
if (debug) NSLog(@"Power Source Changed");
bool idleSleepState = [self getIdleSleepState];
if (status == POWER_BATTERY) {
if (debug) NSLog(@"On Battery");
if ([defaults integerForKey:@"disableLidSleepOnBattery"] == NSOnState) {