mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-08 04:09:15 -04:00
feat(Clipboard): Implement clipboard/settings search functionality in DMS Launcher
This commit is contained in:
@@ -211,11 +211,21 @@ Singleton {
|
||||
},
|
||||
"dms_settings_search": {
|
||||
id: "dms_settings_search",
|
||||
name: I18n.tr("Settings", "settings window title"),
|
||||
name: I18n.tr("Settings Search"),
|
||||
cornerIcon: "search",
|
||||
comment: "DMS",
|
||||
comment: I18n.tr("DMS Settings"),
|
||||
defaultTrigger: "?",
|
||||
isLauncher: true
|
||||
},
|
||||
"dms_clipboard_search": {
|
||||
id: "dms_clipboard_search",
|
||||
name: I18n.tr("Clipboard"),
|
||||
cornerIcon: "content_paste",
|
||||
comment: "DMS",
|
||||
defaultTrigger: "cb",
|
||||
isLauncher: true,
|
||||
viewMode: "list",
|
||||
viewModeEnforced: true
|
||||
}
|
||||
})
|
||||
|
||||
@@ -285,6 +295,16 @@ Singleton {
|
||||
}
|
||||
|
||||
function getBuiltInLauncherItems(pluginId, query) {
|
||||
if (pluginId === "dms_clipboard_search") {
|
||||
ClipboardService.ensureLauncherHistory();
|
||||
const trimmed = (query || "").toString().trim();
|
||||
const entries = trimmed.length === 0 ? ClipboardService.getRecentLauncherEntries(20) : ClipboardService.getLauncherEntries(trimmed, 20, 1);
|
||||
return entries.map(entry => ({
|
||||
type: "clipboard",
|
||||
data: entry
|
||||
}));
|
||||
}
|
||||
|
||||
if (pluginId !== "dms_settings_search")
|
||||
return [];
|
||||
|
||||
@@ -295,10 +315,15 @@ Singleton {
|
||||
const r = results[i];
|
||||
items.push({
|
||||
name: r.label,
|
||||
type: "setting",
|
||||
section: "settings",
|
||||
icon: "material:" + r.icon,
|
||||
comment: r.category,
|
||||
comment: r.description || r.category,
|
||||
action: "settings_nav:" + r.tabIndex + ":" + r.section,
|
||||
categories: ["Settings"],
|
||||
keywords: r.keywords || [],
|
||||
source: I18n.tr("Settings", "settings window title"),
|
||||
badgeLabel: I18n.tr("Setting"),
|
||||
isCore: true,
|
||||
isBuiltInLauncher: true,
|
||||
builtInPluginId: pluginId
|
||||
|
||||
@@ -26,6 +26,7 @@ Singleton {
|
||||
property int selectedIndex: 0
|
||||
property bool keyboardNavigationActive: false
|
||||
property int refCount: 0
|
||||
property real _launcherLastRefresh: 0
|
||||
|
||||
signal historyCopied
|
||||
signal historyCleared
|
||||
@@ -90,6 +91,68 @@ Singleton {
|
||||
});
|
||||
}
|
||||
|
||||
function ensureLauncherHistory() {
|
||||
if (!clipboardAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (internalEntries.length === 0 || now - _launcherLastRefresh > 5000) {
|
||||
_launcherLastRefresh = now;
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user