mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-07 05:58:28 -04:00
launcher: dont cache clipboard results and fix image previews
This commit is contained in:
@@ -60,17 +60,22 @@ Rectangle {
|
|||||||
}, function (response) {
|
}, function (response) {
|
||||||
if (_requestedEntryId !== entryId)
|
if (_requestedEntryId !== entryId)
|
||||||
return;
|
return;
|
||||||
if (response.error)
|
if (response.error) {
|
||||||
|
_requestedEntryId = null;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (!response.result) {
|
if (!response.result) {
|
||||||
|
_requestedEntryId = null;
|
||||||
ClipboardService.refresh();
|
ClipboardService.refresh();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = response.result;
|
const result = response.result;
|
||||||
const mimeType = (result.mimeType ?? entry?.mimeType ?? "").toString();
|
const mimeType = (result.mimeType ?? entry?.mimeType ?? "").toString();
|
||||||
const data = (result.data ?? "").toString();
|
const data = (result.data ?? "").toString();
|
||||||
if (data.length === 0 || !resolvedSourceUrl(data, mimeType))
|
if (data.length === 0 || !resolvedSourceUrl(data, mimeType)) {
|
||||||
|
_requestedEntryId = null;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
cachedMimeType = mimeType;
|
cachedMimeType = mimeType;
|
||||||
cachedImageData = data;
|
cachedImageData = data;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,15 +50,15 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onActiveChanged: {
|
onActiveChanged: {
|
||||||
if (!active) {
|
ClipboardService.invalidateLauncherSearchCache();
|
||||||
SessionData.addLauncherHistory(searchQuery);
|
if (active)
|
||||||
|
return;
|
||||||
|
|
||||||
sections = [];
|
SessionData.addLauncherHistory(searchQuery);
|
||||||
flatModel = [];
|
sections = [];
|
||||||
selectedItem = null;
|
flatModel = [];
|
||||||
_clearModeCache();
|
selectedItem = null;
|
||||||
ClipboardService.invalidateLauncherSearchCache();
|
_clearModeCache();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchModeChanged: {
|
onSearchModeChanged: {
|
||||||
@@ -276,9 +276,23 @@ Item {
|
|||||||
property string appCategory: ""
|
property string appCategory: ""
|
||||||
property var appCategories: []
|
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) {
|
function getSectionViewMode(sectionId) {
|
||||||
if (sectionId === "browse_plugins")
|
if (sectionId === "browse_plugins")
|
||||||
return "list";
|
return "list";
|
||||||
|
var builtInPref = builtInSectionViewPref(sectionId);
|
||||||
|
if (builtInPref?.enforced)
|
||||||
|
return builtInPref.mode;
|
||||||
if (pluginViewPreferences[sectionId]?.enforced)
|
if (pluginViewPreferences[sectionId]?.enforced)
|
||||||
return pluginViewPreferences[sectionId].mode;
|
return pluginViewPreferences[sectionId].mode;
|
||||||
if (sectionViewModes[sectionId])
|
if (sectionViewModes[sectionId])
|
||||||
@@ -302,6 +316,8 @@ Item {
|
|||||||
function setSectionViewMode(sectionId, mode) {
|
function setSectionViewMode(sectionId, mode) {
|
||||||
if (sectionId === "browse_plugins")
|
if (sectionId === "browse_plugins")
|
||||||
return;
|
return;
|
||||||
|
if (builtInSectionViewPref(sectionId)?.enforced)
|
||||||
|
return;
|
||||||
if (pluginViewPreferences[sectionId]?.enforced)
|
if (pluginViewPreferences[sectionId]?.enforced)
|
||||||
return;
|
return;
|
||||||
sectionViewModes = Object.assign({}, sectionViewModes, {
|
sectionViewModes = Object.assign({}, sectionViewModes, {
|
||||||
@@ -325,6 +341,8 @@ Item {
|
|||||||
function canChangeSectionViewMode(sectionId) {
|
function canChangeSectionViewMode(sectionId) {
|
||||||
if (sectionId === "browse_plugins")
|
if (sectionId === "browse_plugins")
|
||||||
return false;
|
return false;
|
||||||
|
if (builtInSectionViewPref(sectionId)?.enforced)
|
||||||
|
return false;
|
||||||
return !pluginViewPreferences[sectionId]?.enforced;
|
return !pluginViewPreferences[sectionId]?.enforced;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,6 +731,7 @@ Item {
|
|||||||
if (triggerMatch.isBuiltIn) {
|
if (triggerMatch.isBuiltIn) {
|
||||||
var builtInItems = AppSearchService.getBuiltInLauncherItems(triggerMatch.pluginId, triggerMatch.query);
|
var builtInItems = AppSearchService.getBuiltInLauncherItems(triggerMatch.pluginId, triggerMatch.query);
|
||||||
for (var j = 0; j < builtInItems.length; j++) {
|
for (var j = 0; j < builtInItems.length; j++) {
|
||||||
|
builtInItems[j]._preScored = 1000 - j;
|
||||||
allItems.push(transformBuiltInSearchItem(builtInItems[j], triggerMatch.pluginId));
|
allItems.push(transformBuiltInSearchItem(builtInItems[j], triggerMatch.pluginId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1217,8 +1236,12 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function transformBuiltInSearchItem(item, pluginId) {
|
function transformBuiltInSearchItem(item, pluginId) {
|
||||||
if (pluginId === "dms_clipboard_search" || item.type === "clipboard")
|
if (pluginId === "dms_clipboard_search" || item.type === "clipboard") {
|
||||||
return transformClipboardEntry(item.data || item);
|
var transformed = transformClipboardEntry(item.data || item);
|
||||||
|
if (item._preScored !== undefined)
|
||||||
|
transformed._preScored = item._preScored;
|
||||||
|
return transformed;
|
||||||
|
}
|
||||||
return transformBuiltInLauncherItem(item, pluginId);
|
return transformBuiltInLauncherItem(item, pluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -298,7 +298,11 @@ Singleton {
|
|||||||
function getBuiltInLauncherItems(pluginId, query) {
|
function getBuiltInLauncherItems(pluginId, query) {
|
||||||
if (pluginId === "dms_clipboard_search") {
|
if (pluginId === "dms_clipboard_search") {
|
||||||
const trimmed = (query || "").toString().trim();
|
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 => ({
|
return entries.map(entry => ({
|
||||||
type: "clipboard",
|
type: "clipboard",
|
||||||
data: entry
|
data: entry
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ Singleton {
|
|||||||
property int selectedIndex: 0
|
property int selectedIndex: 0
|
||||||
property bool keyboardNavigationActive: false
|
property bool keyboardNavigationActive: false
|
||||||
property int refCount: 0
|
property int refCount: 0
|
||||||
property real _launcherLastRefresh: 0
|
|
||||||
property bool _launcherCacheValid: false
|
property bool _launcherCacheValid: false
|
||||||
property string _launcherCachedQuery: ""
|
property string _launcherCachedQuery: ""
|
||||||
property var _launcherCachedEntries: []
|
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) {
|
function requestLauncherSearch(query, limit) {
|
||||||
if (!clipboardAvailable) {
|
if (!clipboardAvailable) {
|
||||||
return;
|
return;
|
||||||
@@ -207,56 +194,6 @@ Singleton {
|
|||||||
_launcherSearchSeq++;
|
_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() {
|
function reset() {
|
||||||
searchText = "";
|
searchText = "";
|
||||||
selectedIndex = 0;
|
selectedIndex = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user