diff --git a/appinfo/info.xml b/appinfo/info.xml index db28e4d..824794b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -8,7 +8,7 @@ Search for torrents within the app from mutiple BT sites; Control Aria2 and manage download tasks from the web; download videos from 700+ video sites(youtube,youku,vimo,dailymotion,twitter,facebook and the likes - 0.5.2 + 0.6.0 agpl jiaxinhuang NCDownloader diff --git a/lib/Tools/Aria2.php b/lib/Tools/Aria2.php index 69f1876..08a21f6 100644 --- a/lib/Tools/Aria2.php +++ b/lib/Tools/Aria2.php @@ -308,7 +308,7 @@ class Aria2 $filename = Helper::getBasicFilename($file); $torrent = base64_encode($data); $resp = $this->addTorrent($torrent, []); - }else{ + } else { return ['error' => "no valid torrents file!"]; } if (isset($resp['error'])) { @@ -353,7 +353,7 @@ class Aria2 } public function start($bin = null) { - //aria2c wont't start without any errors when input-file is set but missing + //aria2c refuses to start with no errors when input-file is set but missing if (!file_exists($this->sessionFile)) { file_put_contents($this->sessionFile, ''); } @@ -389,6 +389,7 @@ class Aria2 public function stop() { $resp = $this->shutdown(); + sleep(1); return $resp ?? null; } private function confTemplate() diff --git a/src/index.js b/src/index.js index 6a67ba0..5c61ef2 100644 --- a/src/index.js +++ b/src/index.js @@ -24,11 +24,39 @@ window.addEventListener('DOMContentLoaded', function () { let vm = app.mount('#' + container); helper.addVue(vm.$options.name, vm); - eventHandler.add("click", "#start-aria2 button", function (e) { + eventHandler.add("click", "#start-aria2", "button", function (e) { const path = basePath + "/aria2/start"; + let element = e.target + if (element.classList.contains("notinstalled")) { + return; + } + let parent = element.parentElement; + let oldHtml = parent.innerHTML; + parent.innerHTML = helper.loadingTpl(); let url = helper.generateUrl(path); + const callback = function (parent, html, data) { + parent.innerHTML = html; + if (!data.status) { + return; + } + if (!data.status && data.error) { + helper.message(data.error); + } + let element = document.querySelector("#start-aria2 button"); + let aria2 = element.getAttribute("data-aria2"); + if (!aria2) { + return; + } + if (aria2 === 'on') { + element.setAttribute("data-aria2", "off"); + element.textContent = t("ncdownloader", "Start Aria2"); + } else { + element.setAttribute("data-aria2", "on"); + element.textContent = t("ncdownloader", "Stop Aria2"); + } + } Http.getInstance(url).setHandler(function (data) { - helper.aria2Toggle(data); + callback(parent, oldHtml, data); }).send(); }) eventHandler.add("click", "#app-navigation", "#search-download", helper.showDownload); diff --git a/src/utils/helper.js b/src/utils/helper.js index 0fbd785..7f41624 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -61,28 +61,11 @@ const helper = { close: true, gravity: "top", // `top` or `bottom` position: "center", // `left`, `center` or `right` - backgroundColor: "linear-gradient(to right, rgb(26, 28, 27), rgb(126, 138, 105))", + backgroundColor: "#295b86", stopOnFocus: true, // Prevents dismissing of toast on hover onClick: function () { } // Callback after click }).showToast(); }, - aria2Toggle: function (data) { - if (!data.status) { - return; - } - if (!data.status && data.error) { - return; - } - let element = document.querySelector("#start-aria2 button"); - let aria2 = element.getAttribute("data-aria2"); - if (aria2 === 'on') { - element.setAttribute("data-aria2", "off"); - element.textContent = t("ncdownloader", "Start Aria2"); - } else { - element.setAttribute("data-aria2", "on"); - element.textContent = t("ncdownloader", "Stop Aria2"); - } - }, getPathLast: function (path) { return path.substring(path.lastIndexOf('/') + 1) }, @@ -178,6 +161,17 @@ const helper = { container.style.top = 0; container.style.left = 0; container.style.width = "100%"; + }, + loadingTpl() { + let html = ` + -