-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSApplicationPlus.m
More file actions
executable file
·52 lines (38 loc) · 1.19 KB
/
NSApplicationPlus.m
File metadata and controls
executable file
·52 lines (38 loc) · 1.19 KB
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
//
// NSApplicationPlus.m
// detectPowerApp
//
// Created by powerbookg4 on 23.06.07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "NSApplicationPlus.h"
io_connect_t root_port;
static NSApplicationPlus *me;
void callbackPwr(void *in){
[me powerSourceChanged];
}
@implementation NSApplicationPlus
- (id) init {
self = [super init];
if (self != nil) {
me = self;
CFRunLoopSourceRef maSource = NULL;
maSource = IOPSNotificationCreateRunLoopSource(callbackPwr, NULL);
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],maSource,kCFRunLoopDefaultMode);
CFRelease(maSource);
}
return self;
}
- (void)powerSourceChanged{
CFTypeRef sourcesInfo = IOPSCopyPowerSourcesInfo();
NSString* sourcesDesc = (NSString *)IOPSGetProvidingPowerSourceType(sourcesInfo);
CFRelease(sourcesInfo);
if (sourcesDesc == nil) sourcesDesc = @"Error";
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSDictionary *userDict = [NSDictionary dictionaryWithObject:sourcesDesc forKey:@"powerSourceState"];
[nc postNotification:[NSNotification notificationWithName:@"powerSourceChanged" object:self userInfo:userDict]];
}
- (void) dealloc {
[super dealloc];
}
@end