ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
macos/keepawake.c
Go to the documentation of this file.
1
7#include <ascii-chat/platform/system.h>
8#include <ascii-chat/log/logging.h>
9#include <ascii-chat/asciichat_errno.h>
10#include <IOKit/pwr_mgt/IOPMLib.h>
11
12static IOPMAssertionID g_power_assertion = kIOPMNullAssertionID;
13
14asciichat_error_t platform_enable_keepawake(void) {
15 // macOS: Use IOKit power assertions
16 if (g_power_assertion != kIOPMNullAssertionID) {
17 log_debug("Keepawake already enabled");
18 return ASCIICHAT_OK;
19 }
20
21 CFStringRef reason = CFSTR("ascii-chat is running");
22 IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertionTypePreventSystemSleep, kIOPMAssertionLevelOn, reason,
23 &g_power_assertion);
24
25 if (result != kIOReturnSuccess) {
26 return SET_ERRNO(ERROR_PLATFORM_INIT, "Failed to create power assertion (error %d)", result);
27 }
28
29 log_debug("Keepawake enabled via IOKit (assertion ID: %u)", g_power_assertion);
30 return ASCIICHAT_OK;
31}
32
34 if (g_power_assertion != kIOPMNullAssertionID) {
35 IOPMAssertionRelease(g_power_assertion);
36 log_debug("Keepawake disabled (released assertion ID: %u)", g_power_assertion);
37 g_power_assertion = kIOPMNullAssertionID;
38 }
39}
void platform_disable_keepawake(void)
asciichat_error_t platform_enable_keepawake(void)