Feature: Add power management to keep macOS client always responsive

This commit is contained in:
yuanyuanxiang
2026-05-01 21:43:55 +02:00
parent 36ba9ccc1d
commit 3607f1d768
3 changed files with 61 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ ScreenHandler::ScreenHandler(IOCPClient* client)
, m_maxFPS(15)
, m_qualityLevel(QUALITY_GOOD) // Use fixed QUALITY_GOOD (H264) for web compatibility
, m_h264Bitrate(3000000) // 3 Mbps (matches Windows QUALITY_GOOD)
, m_displayAssertionID(0)
{
memset(&m_bmpHeader, 0, sizeof(m_bmpHeader));
@@ -115,6 +116,21 @@ void ScreenHandler::start(IOCPClient* client, uint64_t clientID)
m_clientID = clientID;
m_running = true;
// Prevent display sleep during remote desktop session
if (m_displayAssertionID == 0) {
IOReturn result = IOPMAssertionCreateWithName(
kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
CFSTR("SimpleRemoter - remote desktop session active"),
&m_displayAssertionID
);
if (result == kIOReturnSuccess) {
NSLog(@"Display sleep disabled for remote desktop (ID: %u)", m_displayAssertionID);
} else {
NSLog(@"Warning: Failed to prevent display sleep (error: 0x%x)", result);
}
}
m_captureThread = std::thread(&ScreenHandler::captureLoop, this);
}
@@ -130,6 +146,13 @@ void ScreenHandler::stop()
m_h264Encoder->close();
m_h264Encoder.reset();
}
// Release display sleep assertion - allow screen to turn off
if (m_displayAssertionID != 0) {
IOPMAssertionRelease(m_displayAssertionID);
NSLog(@"Display sleep re-enabled (released ID: %u)", m_displayAssertionID);
m_displayAssertionID = 0;
}
}
void ScreenHandler::sendBitmapInfo()