1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-06-08 04:09:15 -04:00

fix(Spotlight): Update the new clipboard/settings merge w/cache & debouced refresh

This commit is contained in:
purian23
2026-05-19 01:39:16 -04:00
parent 81a1bb1cd7
commit 4845299cc2
4 changed files with 93 additions and 24 deletions
+11 -13
View File
@@ -44,16 +44,14 @@ Item {
signal searchQueryRequested(string query) signal searchQueryRequested(string query)
onActiveChanged: { onActiveChanged: {
if (active) { if (!active) {
if (clipboardSearchEnabledInAll())
ClipboardService.ensureLauncherHistory();
} else {
SessionData.addLauncherHistory(searchQuery); SessionData.addLauncherHistory(searchQuery);
sections = []; sections = [];
flatModel = []; flatModel = [];
selectedItem = null; selectedItem = null;
_clearModeCache(); _clearModeCache();
ClipboardService.invalidateLauncherSearchCache();
} }
} }
@@ -88,11 +86,17 @@ Item {
Connections { Connections {
target: ClipboardService target: ClipboardService
function onInternalEntriesChanged() { function onLauncherSearchReady(query) {
if (!active || !clipboardSearchEnabledInAll()) if (!active || !clipboardSearchEnabledInAll())
return; return;
if (searchMode === "all" && searchQuery.length >= 2) if (searchMode !== "all")
performSearch(); return;
const trimmed = (searchQuery || "").trim();
if (trimmed.length < 2 && query.length > 0)
return;
if (query !== trimmed)
return;
searchDebounce.restart();
} }
} }
@@ -403,9 +407,6 @@ Item {
searchQuery = query; searchQuery = query;
searchDebounce.restart(); searchDebounce.restart();
if (searchMode === "all" && clipboardSearchEnabledInAll() && query.length >= 2)
ClipboardService.ensureLauncherHistory();
var filesInAll = searchMode === "all" && (SettingsData.dankLauncherV2IncludeFilesInAll || SettingsData.dankLauncherV2IncludeFoldersInAll); var filesInAll = searchMode === "all" && (SettingsData.dankLauncherV2IncludeFilesInAll || SettingsData.dankLauncherV2IncludeFoldersInAll);
if (searchMode !== "plugins" && (searchMode === "files" || query.startsWith("/") || filesInAll) && query.length > 0) { if (searchMode !== "plugins" && (searchMode === "files" || query.startsWith("/") || filesInAll) && query.length > 0) {
fileSearchDebounce.restart(); fileSearchDebounce.restart();
@@ -424,8 +425,6 @@ Item {
searchMode = mode; searchMode = mode;
modeChanged(mode); modeChanged(mode);
performSearch(); performSearch();
if (mode === "all" && clipboardSearchEnabledInAll() && searchQuery.length >= 2)
ClipboardService.ensureLauncherHistory();
var filesInAll = mode === "all" && (SettingsData.dankLauncherV2IncludeFilesInAll || SettingsData.dankLauncherV2IncludeFoldersInAll) && searchQuery.length > 0; var filesInAll = mode === "all" && (SettingsData.dankLauncherV2IncludeFilesInAll || SettingsData.dankLauncherV2IncludeFoldersInAll) && searchQuery.length > 0;
if (mode === "files" || filesInAll) { if (mode === "files" || filesInAll) {
fileSearchDebounce.restart(); fileSearchDebounce.restart();
@@ -1209,7 +1208,6 @@ Item {
} }
if (clipboardSearchEnabledInAll()) { if (clipboardSearchEnabledInAll()) {
ClipboardService.ensureLauncherHistory();
var clipboardItems = AppSearchService.getBuiltInLauncherItems("dms_clipboard_search", query); var clipboardItems = AppSearchService.getBuiltInLauncherItems("dms_clipboard_search", query);
var clipboardLimit = Math.min(clipboardItems.length, 8); var clipboardLimit = Math.min(clipboardItems.length, 8);
for (var j = 0; j < clipboardLimit; j++) { for (var j = 0; j < clipboardLimit; j++) {
+2 -4
View File
@@ -296,9 +296,8 @@ Singleton {
function getBuiltInLauncherItems(pluginId, query) { function getBuiltInLauncherItems(pluginId, query) {
if (pluginId === "dms_clipboard_search") { if (pluginId === "dms_clipboard_search") {
ClipboardService.ensureLauncherHistory();
const trimmed = (query || "").toString().trim(); const trimmed = (query || "").toString().trim();
const entries = trimmed.length === 0 ? ClipboardService.getRecentLauncherEntries(20) : ClipboardService.getLauncherEntries(trimmed, 20, 1); const entries = ClipboardService.getCachedLauncherSearchEntries(trimmed, 20);
return entries.map(entry => ({ return entries.map(entry => ({
type: "clipboard", type: "clipboard",
data: entry data: entry
@@ -308,8 +307,7 @@ Singleton {
if (pluginId !== "dms_settings_search") if (pluginId !== "dms_settings_search")
return []; return [];
SettingsSearchService.search(query); const results = SettingsSearchService.searchForLauncher(query);
const results = SettingsSearchService.results;
const items = []; const items = [];
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
const r = results[i]; const r = results[i];
+62
View File
@@ -27,9 +27,14 @@ Singleton {
property bool keyboardNavigationActive: false property bool keyboardNavigationActive: false
property int refCount: 0 property int refCount: 0
property real _launcherLastRefresh: 0 property real _launcherLastRefresh: 0
property bool _launcherCacheValid: false
property string _launcherCachedQuery: ""
property var _launcherCachedEntries: []
property int _launcherSearchSeq: 0
signal historyCopied signal historyCopied
signal historyCleared signal historyCleared
signal launcherSearchReady(string query)
Process { Process {
id: wtypeProcess id: wtypeProcess
@@ -103,6 +108,63 @@ Singleton {
} }
} }
function requestLauncherSearch(query, limit) {
if (!clipboardAvailable) {
return;
}
const trimmed = (query || "").toString().trim();
const maxItems = limit > 0 ? limit : 20;
if (_launcherCacheValid && _launcherCachedQuery === trimmed) {
return;
}
_launcherSearchSeq++;
const seq = _launcherSearchSeq;
DMSService.sendRequest("clipboard.search", {
"query": trimmed,
"limit": maxItems
}, function (response) {
if (seq !== _launcherSearchSeq) {
return;
}
if (response.error) {
log.warn("Launcher clipboard search failed:", response.error);
_launcherCacheValid = true;
_launcherCachedQuery = trimmed;
_launcherCachedEntries = [];
launcherSearchReady(trimmed);
return;
}
const result = response.result || {};
_launcherCacheValid = true;
_launcherCachedQuery = trimmed;
_launcherCachedEntries = result.entries || [];
launcherSearchReady(trimmed);
});
}
function getCachedLauncherSearchEntries(query, limit) {
if (!clipboardAvailable) {
return [];
}
const trimmed = (query || "").toString().trim();
const maxItems = limit > 0 ? limit : 20;
if (!_launcherCacheValid || _launcherCachedQuery !== trimmed) {
requestLauncherSearch(trimmed, maxItems);
return [];
}
return _launcherCachedEntries.slice(0, maxItems);
}
function invalidateLauncherSearchCache() {
_launcherCacheValid = false;
_launcherCachedQuery = "";
_launcherCachedEntries = [];
_launcherSearchSeq++;
}
function getLauncherEntries(query, limit, minLength) { function getLauncherEntries(query, limit, minLength) {
if (!clipboardAvailable) { if (!clipboardAvailable) {
return []; return [];
+18 -7
View File
@@ -159,17 +159,15 @@ Singleton {
_translatedCache = cache; _translatedCache = cache;
} }
function search(text) { function _searchEntries(text, maxResults) {
query = text; if (!text)
if (!text) { return [];
results = [];
return;
}
var queryLower = text.toLowerCase().trim(); var queryLower = text.toLowerCase().trim();
var queryWords = queryLower.split(/\s+/).filter(w => w.length > 0); var queryWords = queryLower.split(/\s+/).filter(w => w.length > 0);
var scored = []; var scored = [];
var cache = _translatedCache; var cache = _translatedCache;
var limit = maxResults > 0 ? maxResults : 15;
for (var i = 0; i < cache.length; i++) { for (var i = 0; i < cache.length; i++) {
var entry = cache[i]; var entry = cache[i];
@@ -234,7 +232,20 @@ Singleton {
} }
scored.sort((a, b) => b.score - a.score); scored.sort((a, b) => b.score - a.score);
results = scored.slice(0, 15).map(s => s.item); return scored.slice(0, limit).map(s => s.item);
}
function searchForLauncher(text) {
return _searchEntries(text, 15);
}
function search(text) {
query = text;
if (!text) {
results = [];
return;
}
results = _searchEntries(text, 15);
} }
function clear() { function clear() {