From b447e16374283f7a0642b042ce3574811c1aefed Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 6 Jul 2026 23:57:04 -0400 Subject: [PATCH] launcher: dont cache clipboard results and fix image previews --- .../ClipboardLauncherPreview.qml | 9 ++- .../Modals/DankLauncherV2/Controller.qml | 43 ++++++++++--- quickshell/Services/AppSearchService.qml | 6 +- quickshell/Services/ClipboardService.qml | 63 ------------------- 4 files changed, 45 insertions(+), 76 deletions(-) diff --git a/quickshell/Modals/DankLauncherV2/ClipboardLauncherPreview.qml b/quickshell/Modals/DankLauncherV2/ClipboardLauncherPreview.qml index 4e0007276..022e76074 100644 --- a/quickshell/Modals/DankLauncherV2/ClipboardLauncherPreview.qml +++ b/quickshell/Modals/DankLauncherV2/ClipboardLauncherPreview.qml @@ -60,17 +60,22 @@ Rectangle { }, function (response) { if (_requestedEntryId !== entryId) return; - if (response.error) + if (response.error) { + _requestedEntryId = null; return; + } if (!response.result) { + _requestedEntryId = null; ClipboardService.refresh(); return; } const result = response.result; const mimeType = (result.mimeType ?? entry?.mimeType ?? "").toString(); const data = (result.data ?? "").toString(); - if (data.length === 0 || !resolvedSourceUrl(data, mimeType)) + if (data.length === 0 || !resolvedSourceUrl(data, mimeType)) { + _requestedEntryId = null; return; + } cachedMimeType = mimeType; cachedImageData = data; }); diff --git a/quickshell/Modals/DankLauncherV2/Controller.qml b/quickshell/Modals/DankLauncherV2/Controller.qml index e2ef918a0..ef668ea13 100644 --- a/quickshell/Modals/DankLauncherV2/Controller.qml +++ b/quickshell/Modals/DankLauncherV2/Controller.qml @@ -50,15 +50,15 @@ Item { } onActiveChanged: { - if (!active) { - SessionData.addLauncherHistory(searchQuery); + ClipboardService.invalidateLauncherSearchCache(); + if (active) + return; - sections = []; - flatModel = []; - selectedItem = null; - _clearModeCache(); - ClipboardService.invalidateLauncherSearchCache(); - } + SessionData.addLauncherHistory(searchQuery); + sections = []; + flatModel = []; + selectedItem = null; + _clearModeCache(); } onSearchModeChanged: { @@ -276,9 +276,23 @@ Item { property string appCategory: "" property var appCategories: [] + function builtInSectionViewPref(sectionId) { + switch (sectionId) { + case "clipboard": + return getPluginViewPref("dms_clipboard_search"); + case "settings": + return getPluginViewPref("dms_settings_search"); + default: + return null; + } + } + function getSectionViewMode(sectionId) { if (sectionId === "browse_plugins") return "list"; + var builtInPref = builtInSectionViewPref(sectionId); + if (builtInPref?.enforced) + return builtInPref.mode; if (pluginViewPreferences[sectionId]?.enforced) return pluginViewPreferences[sectionId].mode; if (sectionViewModes[sectionId]) @@ -302,6 +316,8 @@ Item { function setSectionViewMode(sectionId, mode) { if (sectionId === "browse_plugins") return; + if (builtInSectionViewPref(sectionId)?.enforced) + return; if (pluginViewPreferences[sectionId]?.enforced) return; sectionViewModes = Object.assign({}, sectionViewModes, { @@ -325,6 +341,8 @@ Item { function canChangeSectionViewMode(sectionId) { if (sectionId === "browse_plugins") return false; + if (builtInSectionViewPref(sectionId)?.enforced) + return false; return !pluginViewPreferences[sectionId]?.enforced; } @@ -713,6 +731,7 @@ Item { if (triggerMatch.isBuiltIn) { var builtInItems = AppSearchService.getBuiltInLauncherItems(triggerMatch.pluginId, triggerMatch.query); for (var j = 0; j < builtInItems.length; j++) { + builtInItems[j]._preScored = 1000 - j; allItems.push(transformBuiltInSearchItem(builtInItems[j], triggerMatch.pluginId)); } } @@ -1217,8 +1236,12 @@ Item { } function transformBuiltInSearchItem(item, pluginId) { - if (pluginId === "dms_clipboard_search" || item.type === "clipboard") - return transformClipboardEntry(item.data || item); + if (pluginId === "dms_clipboard_search" || item.type === "clipboard") { + var transformed = transformClipboardEntry(item.data || item); + if (item._preScored !== undefined) + transformed._preScored = item._preScored; + return transformed; + } return transformBuiltInLauncherItem(item, pluginId); } diff --git a/quickshell/Services/AppSearchService.qml b/quickshell/Services/AppSearchService.qml index 4ac2a37ec..4f066a71d 100644 --- a/quickshell/Services/AppSearchService.qml +++ b/quickshell/Services/AppSearchService.qml @@ -298,7 +298,11 @@ Singleton { function getBuiltInLauncherItems(pluginId, query) { if (pluginId === "dms_clipboard_search") { const trimmed = (query || "").toString().trim(); - const entries = ClipboardService.internalEntries.length > 0 ? ClipboardService.getLauncherEntries(trimmed, 20, 0) : ClipboardService.getCachedLauncherSearchEntries(trimmed, 20); + const entries = ClipboardService.getCachedLauncherSearchEntries(trimmed, 20).slice().sort((a, b) => { + if (a.pinned !== b.pinned) + return b.pinned ? 1 : -1; + return (b.id || 0) - (a.id || 0); + }); return entries.map(entry => ({ type: "clipboard", data: entry diff --git a/quickshell/Services/ClipboardService.qml b/quickshell/Services/ClipboardService.qml index f5e64c5f8..c8af91e84 100644 --- a/quickshell/Services/ClipboardService.qml +++ b/quickshell/Services/ClipboardService.qml @@ -30,7 +30,6 @@ Singleton { property int selectedIndex: 0 property bool keyboardNavigationActive: false property int refCount: 0 - property real _launcherLastRefresh: 0 property bool _launcherCacheValid: false property string _launcherCachedQuery: "" property var _launcherCachedEntries: [] @@ -138,18 +137,6 @@ Singleton { }); } - function ensureLauncherHistory() { - if (!clipboardAvailable) { - return; - } - - const now = Date.now(); - if (internalEntries.length === 0 || now - _launcherLastRefresh > 5000) { - _launcherLastRefresh = now; - refresh(); - } - } - function requestLauncherSearch(query, limit) { if (!clipboardAvailable) { return; @@ -207,56 +194,6 @@ Singleton { _launcherSearchSeq++; } - function getLauncherEntries(query, limit, minLength) { - if (!clipboardAvailable) { - return []; - } - - const trimmed = (query || "").toString().trim(); - const requiredLength = minLength !== undefined ? minLength : 2; - if (trimmed.length < requiredLength) { - return []; - } - - const lowerQuery = trimmed.toLowerCase(); - const maxItems = limit > 0 ? limit : 8; - const matches = []; - - for (var i = 0; i < internalEntries.length; i++) { - const entry = internalEntries[i]; - const preview = getEntryPreview(entry).toString(); - const typeText = entry.isImage ? "image picture screenshot clipboard" : "text clipboard"; - const haystack = (preview + " " + typeText).toLowerCase(); - if (haystack.indexOf(lowerQuery) === -1) { - continue; - } - matches.push(entry); - } - - matches.sort((a, b) => { - if (a.pinned !== b.pinned) - return b.pinned ? 1 : -1; - return (b.id || 0) - (a.id || 0); - }); - - return matches.slice(0, maxItems); - } - - function getRecentLauncherEntries(limit) { - if (!clipboardAvailable) { - return []; - } - - const maxItems = limit > 0 ? limit : 20; - const entries = internalEntries.slice(); - entries.sort((a, b) => { - if (a.pinned !== b.pinned) - return b.pinned ? 1 : -1; - return (b.id || 0) - (a.id || 0); - }); - return entries.slice(0, maxItems); - } - function reset() { searchText = ""; selectedIndex = 0;