Skip to content

Commit b447e16

Browse files
committed
launcher: dont cache clipboard results and fix image previews
1 parent 0bb8353 commit b447e16

4 files changed

Lines changed: 45 additions & 76 deletions

File tree

quickshell/Modals/DankLauncherV2/ClipboardLauncherPreview.qml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,22 @@ Rectangle {
6060
}, function (response) {
6161
if (_requestedEntryId !== entryId)
6262
return;
63-
if (response.error)
63+
if (response.error) {
64+
_requestedEntryId = null;
6465
return;
66+
}
6567
if (!response.result) {
68+
_requestedEntryId = null;
6669
ClipboardService.refresh();
6770
return;
6871
}
6972
const result = response.result;
7073
const mimeType = (result.mimeType ?? entry?.mimeType ?? "").toString();
7174
const data = (result.data ?? "").toString();
72-
if (data.length === 0 || !resolvedSourceUrl(data, mimeType))
75+
if (data.length === 0 || !resolvedSourceUrl(data, mimeType)) {
76+
_requestedEntryId = null;
7377
return;
78+
}
7479
cachedMimeType = mimeType;
7580
cachedImageData = data;
7681
});

quickshell/Modals/DankLauncherV2/Controller.qml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ Item {
5050
}
5151

5252
onActiveChanged: {
53-
if (!active) {
54-
SessionData.addLauncherHistory(searchQuery);
53+
ClipboardService.invalidateLauncherSearchCache();
54+
if (active)
55+
return;
5556

56-
sections = [];
57-
flatModel = [];
58-
selectedItem = null;
59-
_clearModeCache();
60-
ClipboardService.invalidateLauncherSearchCache();
61-
}
57+
SessionData.addLauncherHistory(searchQuery);
58+
sections = [];
59+
flatModel = [];
60+
selectedItem = null;
61+
_clearModeCache();
6262
}
6363

6464
onSearchModeChanged: {
@@ -276,9 +276,23 @@ Item {
276276
property string appCategory: ""
277277
property var appCategories: []
278278

279+
function builtInSectionViewPref(sectionId) {
280+
switch (sectionId) {
281+
case "clipboard":
282+
return getPluginViewPref("dms_clipboard_search");
283+
case "settings":
284+
return getPluginViewPref("dms_settings_search");
285+
default:
286+
return null;
287+
}
288+
}
289+
279290
function getSectionViewMode(sectionId) {
280291
if (sectionId === "browse_plugins")
281292
return "list";
293+
var builtInPref = builtInSectionViewPref(sectionId);
294+
if (builtInPref?.enforced)
295+
return builtInPref.mode;
282296
if (pluginViewPreferences[sectionId]?.enforced)
283297
return pluginViewPreferences[sectionId].mode;
284298
if (sectionViewModes[sectionId])
@@ -302,6 +316,8 @@ Item {
302316
function setSectionViewMode(sectionId, mode) {
303317
if (sectionId === "browse_plugins")
304318
return;
319+
if (builtInSectionViewPref(sectionId)?.enforced)
320+
return;
305321
if (pluginViewPreferences[sectionId]?.enforced)
306322
return;
307323
sectionViewModes = Object.assign({}, sectionViewModes, {
@@ -325,6 +341,8 @@ Item {
325341
function canChangeSectionViewMode(sectionId) {
326342
if (sectionId === "browse_plugins")
327343
return false;
344+
if (builtInSectionViewPref(sectionId)?.enforced)
345+
return false;
328346
return !pluginViewPreferences[sectionId]?.enforced;
329347
}
330348

@@ -713,6 +731,7 @@ Item {
713731
if (triggerMatch.isBuiltIn) {
714732
var builtInItems = AppSearchService.getBuiltInLauncherItems(triggerMatch.pluginId, triggerMatch.query);
715733
for (var j = 0; j < builtInItems.length; j++) {
734+
builtInItems[j]._preScored = 1000 - j;
716735
allItems.push(transformBuiltInSearchItem(builtInItems[j], triggerMatch.pluginId));
717736
}
718737
}
@@ -1217,8 +1236,12 @@ Item {
12171236
}
12181237

12191238
function transformBuiltInSearchItem(item, pluginId) {
1220-
if (pluginId === "dms_clipboard_search" || item.type === "clipboard")
1221-
return transformClipboardEntry(item.data || item);
1239+
if (pluginId === "dms_clipboard_search" || item.type === "clipboard") {
1240+
var transformed = transformClipboardEntry(item.data || item);
1241+
if (item._preScored !== undefined)
1242+
transformed._preScored = item._preScored;
1243+
return transformed;
1244+
}
12221245
return transformBuiltInLauncherItem(item, pluginId);
12231246
}
12241247

quickshell/Services/AppSearchService.qml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ Singleton {
298298
function getBuiltInLauncherItems(pluginId, query) {
299299
if (pluginId === "dms_clipboard_search") {
300300
const trimmed = (query || "").toString().trim();
301-
const entries = ClipboardService.internalEntries.length > 0 ? ClipboardService.getLauncherEntries(trimmed, 20, 0) : ClipboardService.getCachedLauncherSearchEntries(trimmed, 20);
301+
const entries = ClipboardService.getCachedLauncherSearchEntries(trimmed, 20).slice().sort((a, b) => {
302+
if (a.pinned !== b.pinned)
303+
return b.pinned ? 1 : -1;
304+
return (b.id || 0) - (a.id || 0);
305+
});
302306
return entries.map(entry => ({
303307
type: "clipboard",
304308
data: entry

quickshell/Services/ClipboardService.qml

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Singleton {
3030
property int selectedIndex: 0
3131
property bool keyboardNavigationActive: false
3232
property int refCount: 0
33-
property real _launcherLastRefresh: 0
3433
property bool _launcherCacheValid: false
3534
property string _launcherCachedQuery: ""
3635
property var _launcherCachedEntries: []
@@ -138,18 +137,6 @@ Singleton {
138137
});
139138
}
140139

141-
function ensureLauncherHistory() {
142-
if (!clipboardAvailable) {
143-
return;
144-
}
145-
146-
const now = Date.now();
147-
if (internalEntries.length === 0 || now - _launcherLastRefresh > 5000) {
148-
_launcherLastRefresh = now;
149-
refresh();
150-
}
151-
}
152-
153140
function requestLauncherSearch(query, limit) {
154141
if (!clipboardAvailable) {
155142
return;
@@ -207,56 +194,6 @@ Singleton {
207194
_launcherSearchSeq++;
208195
}
209196

210-
function getLauncherEntries(query, limit, minLength) {
211-
if (!clipboardAvailable) {
212-
return [];
213-
}
214-
215-
const trimmed = (query || "").toString().trim();
216-
const requiredLength = minLength !== undefined ? minLength : 2;
217-
if (trimmed.length < requiredLength) {
218-
return [];
219-
}
220-
221-
const lowerQuery = trimmed.toLowerCase();
222-
const maxItems = limit > 0 ? limit : 8;
223-
const matches = [];
224-
225-
for (var i = 0; i < internalEntries.length; i++) {
226-
const entry = internalEntries[i];
227-
const preview = getEntryPreview(entry).toString();
228-
const typeText = entry.isImage ? "image picture screenshot clipboard" : "text clipboard";
229-
const haystack = (preview + " " + typeText).toLowerCase();
230-
if (haystack.indexOf(lowerQuery) === -1) {
231-
continue;
232-
}
233-
matches.push(entry);
234-
}
235-
236-
matches.sort((a, b) => {
237-
if (a.pinned !== b.pinned)
238-
return b.pinned ? 1 : -1;
239-
return (b.id || 0) - (a.id || 0);
240-
});
241-
242-
return matches.slice(0, maxItems);
243-
}
244-
245-
function getRecentLauncherEntries(limit) {
246-
if (!clipboardAvailable) {
247-
return [];
248-
}
249-
250-
const maxItems = limit > 0 ? limit : 20;
251-
const entries = internalEntries.slice();
252-
entries.sort((a, b) => {
253-
if (a.pinned !== b.pinned)
254-
return b.pinned ? 1 : -1;
255-
return (b.id || 0) - (a.id || 0);
256-
});
257-
return entries.slice(0, maxItems);
258-
}
259-
260197
function reset() {
261198
searchText = "";
262199
selectedIndex = 0;

0 commit comments

Comments
 (0)