* @brief Keeps the system and display awake for the process lifetime so long recording * sessions survive an untouched laptop; the OS releases every inhibition on exit. * Call after QApplication exists (the Linux path needs the session D-Bus). * No-op when "App/InhibitIdleSleep" (Misc::ModuleManager) is disabled. */
| 475 | * No-op when "App/InhibitIdleSleep" (Misc::ModuleManager) is disabled. |
| 476 | */ |
| 477 | void inhibitIdleSleep() |
| 478 | { |
| 479 | if (!QSettings().value("App/InhibitIdleSleep", true).toBool()) |
| 480 | return; |
| 481 | |
| 482 | #if defined(Q_OS_WIN) |
| 483 | (void)SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); |
| 484 | #elif defined(Q_OS_MACOS) |
| 485 | static IOPMAssertionID assertion = kIOPMNullAssertionID; |
| 486 | if (assertion == kIOPMNullAssertionID) |
| 487 | (void)IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep, |
| 488 | kIOPMAssertionLevelOn, |
| 489 | CFSTR("Serial Studio data acquisition session"), |
| 490 | &assertion); |
| 491 | #elif defined(Q_OS_LINUX) |
| 492 | if (!QDBusConnection::sessionBus().isConnected()) |
| 493 | return; |
| 494 | |
| 495 | const auto app = QStringLiteral("Serial Studio"); |
| 496 | const auto reason = QStringLiteral("Data acquisition session in progress"); |
| 497 | |
| 498 | QDBusInterface screenSaver(QStringLiteral("org.freedesktop.ScreenSaver"), |
| 499 | QStringLiteral("/org/freedesktop/ScreenSaver"), |
| 500 | QStringLiteral("org.freedesktop.ScreenSaver")); |
| 501 | if (screenSaver.isValid()) |
| 502 | (void)screenSaver.call(QStringLiteral("Inhibit"), app, reason); |
| 503 | |
| 504 | QDBusInterface powerManagement(QStringLiteral("org.freedesktop.PowerManagement"), |
| 505 | QStringLiteral("/org/freedesktop/PowerManagement/Inhibit"), |
| 506 | QStringLiteral("org.freedesktop.PowerManagement.Inhibit")); |
| 507 | if (powerManagement.isValid()) |
| 508 | (void)powerManagement.call(QStringLiteral("Inhibit"), app, reason); |
| 509 | #endif |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * @brief Registers .ssproj with this executable in the Windows registry (HKCU). |