From 33765861fefe2d77ba281639c14db682b4049f49 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Thu, 21 Aug 2025 15:33:51 +0200 Subject: [PATCH] Fully disable CliphistService when Clipboard is disabled --- Services/CliphistService.qml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Services/CliphistService.qml b/Services/CliphistService.qml index 1c77814..a15b809 100644 --- a/Services/CliphistService.qml +++ b/Services/CliphistService.qml @@ -12,6 +12,7 @@ Singleton { // Public API property var items: [] // [{id, preview, mime, isImage}] property bool loading: false + property bool enabled: Settings.data.appLauncher.enableClipboardHistory // Optional automatic watchers to feed cliphist DB property bool autoWatch: true @@ -30,14 +31,26 @@ Singleton { property string _b64CurrentMime: "" property string _b64CurrentId: "" - // Start watchers when the singleton loads - Component.onCompleted: startWatchers() + // Start/stop watchers when enabled changes + Component.onCompleted: { + if (root.enabled) startWatchers() + } + onEnabledChanged: { + if (root.enabled) { + startWatchers() + } else { + stopWatchers() + loading = false + // Optional: clear items to avoid stale UI + items = [] + } + } // Fallback: periodically refresh list so UI updates even if not in clip mode Timer { interval: 5000 repeat: true - running: true + running: root.enabled onTriggered: list() } @@ -134,7 +147,7 @@ Singleton { } function startWatchers() { - if (!autoWatch || watchersStarted) return + if (!root.enabled || !autoWatch || watchersStarted) return watchersStarted = true // Start text watcher watchText.command = ["wl-paste", "--type", "text", "--watch", "cliphist", "store"] @@ -144,7 +157,15 @@ Singleton { watchImage.running = true } + function stopWatchers() { + if (!watchersStarted) return + watchText.running = false + watchImage.running = false + watchersStarted = false + } + function list(maxPreviewWidth) { + if (!root.enabled) { return } if (listProc.running) return loading = true const width = maxPreviewWidth || 100