mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
quicksettings/caffeine: Port away from P5Support DataSource
Port away from the deprecated DataSource component in favour of the inhibition plugin.
This commit is contained in:
parent
ee1a311af7
commit
0393dc8cec
1 changed files with 11 additions and 55 deletions
|
|
@ -1,71 +1,27 @@
|
||||||
/*
|
// SPDX-FileCopyrightText: 2022-2025 Devin Lin <devin@kde.org>
|
||||||
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
|
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
|
||||||
import org.kde.plasma.plasma5support 2.0 as P5Support
|
import org.kde.plasma.private.batterymonitor
|
||||||
|
|
||||||
QS.QuickSetting {
|
QS.QuickSetting {
|
||||||
text: i18n("Caffeine")
|
text: i18n("Caffeine")
|
||||||
icon: "system-suspend-hibernate"
|
icon: "system-suspend-hibernate"
|
||||||
status: enabled ? i18n("Tap to disable sleep suspension") : i18n("Tap to suspend sleep")
|
status: enabled ? i18n("Tap to disable sleep suspension") : i18n("Tap to suspend sleep")
|
||||||
enabled: false
|
enabled: inhibitionControl.isManuallyInhibited
|
||||||
|
|
||||||
P5Support.DataSource {
|
InhibitionControl {
|
||||||
id: pmSource
|
id: inhibitionControl
|
||||||
engine: "powermanagement"
|
isSilent: false
|
||||||
connectedSources: sources
|
|
||||||
onSourceAdded: source => {
|
|
||||||
disconnectSource(source);
|
|
||||||
connectSource(source);
|
|
||||||
}
|
|
||||||
onSourceRemoved: source => {
|
|
||||||
disconnectSource(source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property int cookie1: -1
|
|
||||||
property int cookie2: -1
|
|
||||||
|
|
||||||
function toggle() {
|
function toggle() {
|
||||||
let inhibit = !enabled;
|
if (enabled) {
|
||||||
const service = pmSource.serviceForSource("PowerDevil");
|
inhibitionControl.uninhibit();
|
||||||
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 {
|
} else {
|
||||||
const op1 = service.operationDescription("stopSuppressingSleep");
|
const reason = i18nc("@info", "Plasma Mobile has enabled system-wide inhibition");
|
||||||
op1.cookie = cookie1;
|
inhibitionControl.inhibit(reason);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue