1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-05 04:58:30 -04:00

qs: numerous performance optimizations

- ClippingRectangle usages
- Asynchronous loader usages
- Replace cava visualizers with shaders
This commit is contained in:
bbedward
2026-07-07 16:11:11 -04:00
parent 71b1901ab0
commit 0511cd19df
26 changed files with 558 additions and 366 deletions
+19 -21
View File
@@ -84,31 +84,30 @@ Singleton {
}
function updateFilteredModel() {
let filtered = internalEntries;
const query = searchText.trim().toLowerCase();
const filterAll = activeFilter === "all";
const unpinned = [];
const pinned = [];
if (activeFilter !== "all") {
filtered = filtered.filter(entry => getEntryType(entry) === activeFilter);
for (let i = 0; i < internalEntries.length; i++) {
const entry = internalEntries[i];
if (!filterAll && getEntryType(entry) !== activeFilter)
continue;
if (query.length > 0 && !entry.preview.toLowerCase().includes(query))
continue;
(entry.pinned ? pinned : unpinned).push(entry);
}
const query = searchText.trim();
const byIdDesc = (a, b) => b.id - a.id;
pinned.sort(byIdDesc);
unpinned.sort(byIdDesc);
if (query.length > 0) {
const lowerQuery = query.toLowerCase();
filtered = filtered.filter(entry => entry.preview.toLowerCase().includes(lowerQuery));
}
filtered.sort((a, b) => {
if (a.pinned !== b.pinned)
return b.pinned ? 1 : -1;
return b.id - a.id;
});
clipboardEntries = filtered;
unpinnedEntries = filtered.filter(e => !e.pinned);
pinnedEntries = filtered.filter(e => e.pinned);
pinnedEntries = pinned;
unpinnedEntries = unpinned;
clipboardEntries = pinned.concat(unpinned);
totalCount = clipboardEntries.length;
const activeCount = Math.max(unpinnedEntries.length, pinnedEntries.length);
const activeCount = Math.max(unpinned.length, pinned.length);
if (activeCount === 0) {
keyboardNavigationActive = false;
@@ -116,9 +115,8 @@ Singleton {
return;
}
if (selectedIndex >= activeCount) {
if (selectedIndex >= activeCount)
selectedIndex = activeCount - 1;
}
}
function refresh() {
+30 -5
View File
@@ -56,18 +56,19 @@ Singleton {
function loadArtwork(url) {
if (!url || url === "") {
resolvedArtUrl = "";
// Keep stale art; only blank once the empty url debounce settles.
_lastArtUrl = "";
loading = false;
_clearDebounce.restart();
return;
}
_clearDebounce.stop();
if (url === _lastArtUrl)
return;
_lastArtUrl = url;
if (url.startsWith("http://") || url.startsWith("https://")) {
loading = true;
resolvedArtUrl = ""; // Clear stale artwork immediately while loading
const targetUrl = url;
const hash = djb2Hash(url);
const cacheDir = Paths.strip(Paths.imagecache);
@@ -134,19 +135,30 @@ Singleton {
}
loading = true;
resolvedArtUrl = ""; // Clear stale artwork immediately while verifying local file
const localUrl = url;
const filePath = url.startsWith("file://") ? url.substring(7) : url;
Proc.runCommand(null, ["test", "-f", filePath], (output, exitCode) => {
// Cover file often lands after the metadata update, so poll briefly.
Proc.runCommand(null, ["sh", "-c", "for i in $(seq 20); do [ -f \"$1\" ] && exit 0; sleep 0.15; done; exit 1", "sh", filePath], (output, exitCode) => {
if (_lastArtUrl !== localUrl)
return;
resolvedArtUrl = exitCode === 0 ? localUrl : "";
loading = false;
}, 200);
}, 50, 5000);
}
Timer {
id: _clearDebounce
interval: 800
onTriggered: {
if (root._lastArtUrl === "")
root.resolvedArtUrl = "";
}
}
property MprisPlayer activePlayer: MprisController.activePlayer
property string _resolvedTrackKey: ""
onActivePlayerChanged: _updateArtUrl()
Connections {
@@ -157,8 +169,21 @@ Singleton {
function onMetadataChanged() { root._updateArtUrl(); }
}
function _trackKey() {
const p = activePlayer;
if (!p)
return "";
return (p.trackTitle || "") + "" + (p.trackArtist || "") + "" + (p.trackAlbum || "");
}
function _updateArtUrl() {
const url = getArtworkUrl(activePlayer);
const key = _trackKey();
// Ignore metadata jitter once resolved, but only when the url still matches
// (trackArtUrl can update before the title, and skipping then wedges old art).
if (key !== "" && key === _resolvedTrackKey && url === _lastArtUrl && resolvedArtUrl !== "")
return;
_resolvedTrackKey = key;
loadArtwork(url);
}
}