mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
quicksettings: Add caffeine quicksetting
This commit is contained in:
parent
1f23de451e
commit
1101599e58
3 changed files with 90 additions and 0 deletions
|
|
@ -2,4 +2,5 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
plasma_install_package(airplanemode org.kde.plasma.airplanemode quicksettings)
|
||||
plasma_install_package(caffeine org.kde.plasma.caffeine quicksettings)
|
||||
add_subdirectory(nightcolor)
|
||||
|
|
|
|||
71
quicksettings/caffeine/contents/ui/main.qml
Normal file
71
quicksettings/caffeine/contents/ui/main.qml
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
|
||||
MobileShell.QuickSetting {
|
||||
text: i18n("Caffeine")
|
||||
icon: "system-suspend-hibernate"
|
||||
status: enabled ? i18n("Tap to disable sleep suspension") : i18n("Tap to suspend sleep")
|
||||
enabled: false
|
||||
|
||||
PlasmaCore.DataSource {
|
||||
id: pmSource
|
||||
engine: "powermanagement"
|
||||
connectedSources: sources
|
||||
onSourceAdded: {
|
||||
disconnectSource(source);
|
||||
connectSource(source);
|
||||
}
|
||||
onSourceRemoved: {
|
||||
disconnectSource(source);
|
||||
}
|
||||
}
|
||||
|
||||
property int cookie1: -1
|
||||
property int cookie2: -1
|
||||
|
||||
function toggle() {
|
||||
let inhibit = !enabled;
|
||||
const service = pmSource.serviceForSource("PowerDevil");
|
||||
if (inhibit) {
|
||||
const reason = i18n("Plasma Mobile has enabled system-wide inhibition");
|
||||
const op1 = service.operationDescription("beginSuppressingSleep");
|
||||
op1.reason = reason;
|
||||
const op2 = service.operationDescription("beginSuppressingScreenPowerManagement");
|
||||
op2.reason = reason;
|
||||
|
||||
const job1 = service.startOperationCall(op1);
|
||||
job1.finished.connect(job => {
|
||||
cookie1 = job.result;
|
||||
});
|
||||
|
||||
const job2 = service.startOperationCall(op2);
|
||||
job2.finished.connect(job => {
|
||||
cookie2 = job.result;
|
||||
});
|
||||
} else {
|
||||
const op1 = service.operationDescription("stopSuppressingSleep");
|
||||
op1.cookie = cookie1;
|
||||
const op2 = service.operationDescription("stopSuppressingScreenPowerManagement");
|
||||
op2.cookie = cookie2;
|
||||
|
||||
const job1 = service.startOperationCall(op1);
|
||||
job1.finished.connect(job => {
|
||||
cookie1 = -1;
|
||||
});
|
||||
|
||||
const job2 = service.startOperationCall(op2);
|
||||
job2.finished.connect(job => {
|
||||
cookie2 = -1;
|
||||
});
|
||||
|
||||
}
|
||||
enabled = inhibit;
|
||||
}
|
||||
}
|
||||
|
||||
18
quicksettings/caffeine/metadata.desktop
Normal file
18
quicksettings/caffeine/metadata.desktop
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
[Desktop Entry]
|
||||
Name=Caffeine
|
||||
Icon=system-suspend-hibernate
|
||||
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=KPackage/GenericQML
|
||||
|
||||
X-KDE-PluginInfo-Author=Devin Lin
|
||||
X-KDE-PluginInfo-Email=devin@kde.org
|
||||
X-KDE-PluginInfo-Name=org.kde.plasma.caffeine
|
||||
X-KDE-PluginInfo-Version=0.1
|
||||
X-KDE-PluginInfo-Website=https://kde.org
|
||||
X-KDE-PluginInfo-License=GPL
|
||||
|
||||
|
||||
Loading…
Reference in a new issue