2019-06-30 21:40:23 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2019 Weixuan XIAO <veyx.shaw@gmail.com>
|
2019-06-30 21:40:23 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-06-30 21:40:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "screensaverinhibitplugin-macos.h"
|
|
|
|
|
2023-08-06 11:00:02 +01:00
|
|
|
#include "plugin_screensaver_inhibit_debug.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <KPluginFactory>
|
2019-06-30 21:40:23 +01:00
|
|
|
|
|
|
|
K_PLUGIN_CLASS_WITH_JSON(ScreensaverInhibitPlugin, "kdeconnect_screensaver_inhibit.json")
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args)
|
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
, m_caffeinateProcess(nullptr)
|
2019-06-30 21:40:23 +01:00
|
|
|
{
|
|
|
|
if (QFile::exists(QStringLiteral("/usr/bin/caffeinate"))) {
|
|
|
|
m_caffeinateProcess = new QProcess();
|
|
|
|
m_caffeinateProcess->setProgram(QStringLiteral("caffeinate"));
|
2022-09-10 22:23:52 +01:00
|
|
|
m_caffeinateProcess->setArguments({QStringLiteral("-d")}); // Prevent the display from sleeping
|
2019-06-30 21:40:23 +01:00
|
|
|
m_caffeinateProcess->start();
|
|
|
|
} else {
|
2023-08-06 11:00:02 +01:00
|
|
|
qWarning(KDECONNECT_PLUGIN_SCREENSAVER_INHIBIT) << "Cannot find caffeinate on macOS install";
|
2019-06-30 21:40:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
|
|
|
|
{
|
|
|
|
if (m_caffeinateProcess != nullptr) {
|
|
|
|
m_caffeinateProcess->terminate();
|
|
|
|
m_caffeinateProcess = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_screensaverinhibitplugin-macos.cpp"
|
2019-06-30 21:40:23 +01:00
|
|
|
#include "screensaverinhibitplugin-macos.moc"
|