From 0393dc8cec3258f5f664b2ee6501c7b2709b095f Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 23 Apr 2025 12:22:03 +0200 Subject: [PATCH] quicksettings/caffeine: Port away from P5Support DataSource Port away from the deprecated DataSource component in favour of the inhibition plugin. --- quicksettings/caffeine/contents/ui/main.qml | 66 ++++----------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/quicksettings/caffeine/contents/ui/main.qml b/quicksettings/caffeine/contents/ui/main.qml index f232f69c..8f30d5d9 100644 --- a/quicksettings/caffeine/contents/ui/main.qml +++ b/quicksettings/caffeine/contents/ui/main.qml @@ -1,71 +1,27 @@ -/* - * SPDX-FileCopyrightText: 2022 Devin Lin - * - * SPDX-License-Identifier: LGPL-2.0-or-later - */ +// SPDX-FileCopyrightText: 2022-2025 Devin Lin +// SPDX-License-Identifier: LGPL-2.0-or-later 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 { text: i18n("Caffeine") icon: "system-suspend-hibernate" status: enabled ? i18n("Tap to disable sleep suspension") : i18n("Tap to suspend sleep") - enabled: false + enabled: inhibitionControl.isManuallyInhibited - P5Support.DataSource { - id: pmSource - engine: "powermanagement" - connectedSources: sources - onSourceAdded: source => { - disconnectSource(source); - connectSource(source); - } - onSourceRemoved: source => { - disconnectSource(source); - } + InhibitionControl { + id: inhibitionControl + isSilent: false } - 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; - }); + if (enabled) { + inhibitionControl.uninhibit(); } 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; - }); - + const reason = i18nc("@info", "Plasma Mobile has enabled system-wide inhibition"); + inhibitionControl.inhibit(reason); } - enabled = inhibit; } }