mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-04 04:42:05 -04:00
core: add DL helper, apply to TrackArt OSD, DankLocationSearch
- unrelated change to add gsettingsOrDconf helpers
This commit is contained in:
@@ -3,62 +3,62 @@ pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import QtQuick
|
||||
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.Mpris
|
||||
import qs.Common
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property string _lastArtUrl: ""
|
||||
property string _bgArtSource: ""
|
||||
|
||||
property string activeTrackArtFile: ""
|
||||
property bool loading: false
|
||||
|
||||
function loadArtwork(url) {
|
||||
if (!url || url == "") {
|
||||
if (!url || url === "") {
|
||||
_bgArtSource = "";
|
||||
_lastArtUrl = "";
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
if (url == _lastArtUrl)
|
||||
if (url === _lastArtUrl)
|
||||
return;
|
||||
_lastArtUrl = url;
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||
const filename = "/tmp/.dankshell/trackart_" + Date.now() + ".jpg";
|
||||
activeTrackArtFile = filename;
|
||||
|
||||
cleanupProcess.command = ["sh", "-c", "mkdir -p /tmp/.dankshell && find /tmp/.dankshell -name 'trackart_*' ! -name '" + filename.split('/').pop() + "' -delete"];
|
||||
cleanupProcess.running = true;
|
||||
_bgArtSource = "";
|
||||
loading = true;
|
||||
|
||||
imageDownloader.command = ["curl", "-L", "-s", "--user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36", "-o", filename, url];
|
||||
imageDownloader.targetFile = filename;
|
||||
imageDownloader.running = true;
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
const localUrl = url;
|
||||
const filePath = url.startsWith("file://") ? url.substring(7) : url;
|
||||
Proc.runCommand("trackart", ["test", "-f", filePath], (output, exitCode) => {
|
||||
if (_lastArtUrl !== localUrl)
|
||||
return;
|
||||
if (exitCode === 0)
|
||||
_bgArtSource = localUrl;
|
||||
loading = false;
|
||||
}, 200);
|
||||
return;
|
||||
}
|
||||
// otherwise
|
||||
_bgArtSource = url;
|
||||
|
||||
const filename = "/tmp/.dankshell/trackart_" + Date.now() + ".jpg";
|
||||
activeTrackArtFile = filename;
|
||||
|
||||
Proc.runCommand("trackart_cleanup", ["sh", "-c", "mkdir -p /tmp/.dankshell && find /tmp/.dankshell -name 'trackart_*' ! -name '" + filename.split('/').pop() + "' -delete"], null, 0);
|
||||
|
||||
Proc.runCommand("trackart", ["dms", "dl", "-o", filename, "--user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36", url], (output, exitCode) => {
|
||||
const resultPath = output.trim();
|
||||
if (resultPath !== filename)
|
||||
return;
|
||||
if (exitCode === 0)
|
||||
_bgArtSource = "file://" + resultPath;
|
||||
loading = false;
|
||||
}, 200);
|
||||
}
|
||||
|
||||
property MprisPlayer activePlayer: MprisController.activePlayer
|
||||
|
||||
onActivePlayerChanged: {
|
||||
loadArtwork(activePlayer.trackArtUrl);
|
||||
}
|
||||
|
||||
Process {
|
||||
id: imageDownloader
|
||||
running: false
|
||||
property string targetFile: ""
|
||||
|
||||
onExited: exitCode => {
|
||||
if (exitCode === 0 && targetFile)
|
||||
_bgArtSource = "file://" + targetFile;
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: cleanupProcess
|
||||
running: false
|
||||
loadArtwork(activePlayer?.trackArtUrl ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user