Last active
December 11, 2017 12:17
-
-
Save Zren/7d97586d7c38d7acd80a9e7f287e7c77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import org.kde.plasma.core 2.0 as PlasmaCore | |
Item { | |
property variant execQueue: [] | |
PlasmaCore.DataSource { | |
id: executeSource | |
engine: "executable" | |
connectedSources: [] | |
onNewData: { | |
// for (var key in executeSource) { | |
// console.log(key, executeSource[key]) | |
// } | |
// for (var key in executeSource.data) { | |
// console.log(key, executeSource.data[key]) | |
// } | |
// console.log(executeSource.data[sourceName]["exit code"]) | |
// console.log("cmd", sourceName) | |
// console.log("exit code", executeSource.data[sourceName]["exit code"]) | |
// console.log("exit status", executeSource.data[sourceName]["exit status"]) | |
// console.log("stdout", executeSource.data[sourceName]["stdout"]) | |
// console.log("stderr", executeSource.data[sourceName]["stderr"]) | |
execItemFinished(sourceName, executeSource.data[sourceName]) | |
} | |
} | |
function callExecItem() { | |
var execItem = execQueue[0] | |
executeSource.connectSource(execItem.cmd) | |
} | |
function execItemFinished(cmd, data) { | |
var execItem = execQueue[0] | |
var exitCode = data["exit code"] | |
var exitStatus = data["exit status"] | |
var stdout = data["stdout"] | |
var stderr = data["stderr"] | |
executeSource.disconnectSource(cmd) | |
if (execItem.callback) { | |
execItem.callback(stdout, exitCode, exitStatus, stderr) | |
} | |
execQueue.shift() | |
} | |
function exec(cmd, callback) { | |
var execItem = { | |
cmd: cmd, | |
callback: callback, | |
}; | |
execQueue.push(execItem) | |
callExecItem() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Item { | |
ExecUtil { id: executable } | |
function downloadWallpaper(url, callback) { | |
// var localUrl = config.localDir + '/wallhaven-' + item.wallpaperId + '.jpg' | |
var fileName = url.substr(url.lastIndexOf('/')+1) | |
var localUrl = config.localDir + '/' + fileName | |
var command = '[ -f ' + localUrl + ' ] || (cd ' + config.localDir + ' && wget ' + url + ')' | |
executable.exec(command, function(stdout, exitCode, exitStatus, stderr) { | |
// console.log('(stdout, exitCode, exitStatus, stderr)', stdout, exitCode, exitStatus, stderr) | |
callback() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment