-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCAwake.mm
29 lines (24 loc) · 1.02 KB
/
CCAwake.mm
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
#import <Foundation/Foundation.h>
#import <AppKit/NSWorkspace.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
bool disableScreenSleep(const char *reason, unsigned int *noSleepAssertionID) {
CFStringRef reasonStr =
CFStringCreateWithCString(NULL, reason, kCFStringEncodingUTF8);
int noSleepReturn = IOPMAssertionCreateWithName(
kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonStr,
noSleepAssertionID);
bool noSleepEnable = noSleepReturn == kIOReturnSuccess;
return noSleepEnable;
}
bool enableScreenSleep(unsigned int noSleepAssertionID) {
int noSleepReturn = IOPMAssertionRelease(noSleepAssertionID);
bool noSleepEnable = noSleepReturn == kIOReturnSuccess;
return noSleepEnable;
}
bool openUrl(const char *urlChar) {
// CFStringRef urlStr = CFStringCreateWithCString(NULL, urlChar, kCFStringEncodingUTF8);
NSString* urlStr = [NSString stringWithUTF8String:urlChar];
NSURL* url = [[NSURL alloc]initWithString:urlStr];
bool isOk = [[NSWorkspace sharedWorkspace] openURL:url];
return isOk;
}