improved message displaying

This commit is contained in:
huangjx
2022-02-23 20:56:30 +08:00
parent 5429581f95
commit cf8b07932b
6 changed files with 73 additions and 20 deletions

View File

@@ -74,13 +74,18 @@ class MainController extends Controller
$params['ffmpeg_installed'] = Helper::ffmpegInstalled(); $params['ffmpeg_installed'] = Helper::ffmpegInstalled();
$errors = []; $errors = [];
if ($aria2_installed && !$aria2_executable) { if ($aria2_installed) {
array_push($errors, sprintf("aria2 is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $aria2_bin)); if (!$aria2_executable) {
array_push($errors, sprintf("aria2 is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $aria2_bin));
}
if (!$params['aria2_running']) {
array_push($errors, $this->l10n->t("Aria2c is not running!"));
}
} }
if ($youtube_installed && (!$youtube_executable || !@is_readable($youtube_bin))) { if ($youtube_installed && (!$youtube_executable || !@is_readable($youtube_bin))) {
array_push($errors, sprintf("youtube-dl is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $youtube_bin)); array_push($errors, sprintf("youtube-dl is installed but don't have the right permissions.Please execute command sudo chmod 755 %s", $youtube_bin));
} }
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
if (strpos($key, "_") === false) { if (strpos($key, "_") === false) {
continue; continue;
@@ -90,7 +95,7 @@ class MainController extends Controller
continue; continue;
} }
if (!$value) { if (!$value) {
array_push($errors, sprintf("%s is not installed", $name)); array_push($errors, $this->l10n->t(sprintf("%s is not installed", $name)));
} }
} }
$params['errors'] = $errors; $params['errors'] = $errors;

View File

@@ -161,7 +161,7 @@ class Youtube
$data = ['link' => $url]; $data = ['link' => $url];
$process->run(function ($type, $buffer) use ($data, $process) { $process->run(function ($type, $buffer) use ($data, $process) {
if (Process::ERR === $type) { if (Process::ERR === $type) {
// $this->onError($buffer); $this->onError($buffer);
} else { } else {
$data['pid'] = $process->getPid(); $data['pid'] = $process->getPid();
$this->onOutput($buffer, $data); $this->onOutput($buffer, $data);

View File

@@ -19,11 +19,11 @@ import nctable from "./lib/ncTable";
const successCallback = (data, element) => { const successCallback = (data, element) => {
if (!data) { if (!data) {
helper.message(t("ncdownloader", "Something must have gone wrong!")); helper.error(t("ncdownloader", "Something must have gone wrong!"));
return; return;
} }
if (data.hasOwnProperty("error")) { if (data.hasOwnProperty("error")) {
helper.message(t("ncdownloader", data.error)); helper.error(t("ncdownloader", data.error));
} else if (data.hasOwnProperty("message")) { } else if (data.hasOwnProperty("message")) {
helper.message(t("ncdownloader", data.message)); helper.message(t("ncdownloader", data.message));
} else if (data.hasOwnProperty("file")) { } else if (data.hasOwnProperty("file")) {
@@ -51,15 +51,19 @@ export default {
let formWrapper = element.closest("form"); let formWrapper = element.closest("form");
let formData = helper.getData(formWrapper); let formData = helper.getData(formWrapper);
let inputValue = formData["text-input-value"]; let inputValue = formData["text-input-value"];
let message;
//formData.audioOnly = document.getElementById('audio-only').checked; //formData.audioOnly = document.getElementById('audio-only').checked;
if (formData.type === "youtube-dl") { if (formData.type === "youtube-dl") {
formData["audio-only"] = formData["audio-only"] === "true"; formData["audio-only"] = formData["audio-only"] === "true";
message = helper.t("Download task started!");
} }
if (!helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) { if (!helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) {
helper.message(t("ncdownloader", inputValue + " is Invalid")); helper.error(t("ncdownloader", inputValue + " is Invalid"));
return; return;
} }
if (message) {
helper.info(message);
}
let url = formWrapper.getAttribute("action"); let url = formWrapper.getAttribute("action");
Http.getInstance(url) Http.getInstance(url)
.setData(formData) .setData(formData)
@@ -67,7 +71,6 @@ export default {
successCallback(data, element); successCallback(data, element);
}) })
.send(); .send();
helper.message(inputValue);
}, },
search(event, vm) { search(event, vm) {
let element = event.target; let element = event.target;
@@ -75,7 +78,7 @@ export default {
let formData = helper.getData(formWrapper); let formData = helper.getData(formWrapper);
let inputValue = formData["text-input-value"]; let inputValue = formData["text-input-value"];
if (inputValue && inputValue.length < 2) { if (inputValue && inputValue.length < 2) {
helper.message(t("ncdownloader", "Please enter valid keyword!")); helper.error(t("ncdownloader", "Please enter valid keyword!"));
vm.$data.loading = 0; vm.$data.loading = 0;
return; return;
} }

View File

@@ -29,7 +29,7 @@ const buttonHandler = (event, type) => {
console.log(error); console.log(error);
}).setHandler(function (data) { }).setHandler(function (data) {
if (data.hasOwnProperty('error')) { if (data.hasOwnProperty('error')) {
helper.message(data['error']); helper.error(data['error']);
return; return;
} }
if (data.hasOwnProperty('result')) { if (data.hasOwnProperty('result')) {

View File

@@ -55,7 +55,7 @@ window.addEventListener('DOMContentLoaded', function () {
if (!data.status) { if (!data.status) {
if (data.error) if (data.error)
helper.message(data.error); helper.error(data.error);
return; return;
} }
let element = document.querySelector("#start-aria2 button"); let element = document.querySelector("#start-aria2 button");

View File

@@ -51,18 +51,60 @@ const helper = {
return magnetURI.test(url.trim()); return magnetURI.test(url.trim());
}, },
message: function (message, duration = 3000) { _message: function (message, options = {}) {
Toastify({ message = message || "Empty"
const defaults = {
text: message, text: message,
duration: duration,
newWindow: true, newWindow: true,
close: true, close: true,
gravity: "top", // `top` or `bottom` gravity: "top", // `top` or `bottom`
position: "center", // `left`, `center` or `right` position: "center", // `left`, `center` or `right`
backgroundColor: "#295b86", // backgroundColor: "#295b86",
stopOnFocus: true, // Prevents dismissing of toast on hover stopOnFocus: true, // Prevents dismissing of toast on hover
onClick: function () { } // Callback after click onClick: function () { }, // Callback after click
}).showToast(); }
Object.assign(defaults, options);
Toastify(defaults).showToast();
},
error: function (message, duration = 20000) {
let options = {
style: {
color: '#721c24',
'background-color': '#f8d7da',
'border-color': '#f5c6cb',
},
duration: duration,
backgroundColor: '#f8d7da',
}
helper._message(message, options);
},
info: function (message, duration = 2000) {
const options = {
style: {
color: '#004085',
'background-color': '#cce5ff',
'border-color': '#b8daff',
},
duration: duration,
text: message,
backgroundColor: '#cce5ff',
}
helper._message(message, options);
},
warn: function (message, duration = 2000) {
const options = {
style: {
color: '#856404',
'background-color': '#fff3cd',
'border-color': '#ffeeba',
},
duration: duration,
backgroundColor: '#fff3cd',
}
helper._message(message, options);
},
message: function (message, duration = 2000) {
helper.info(message, duration);
}, },
getPathLast: function (path) { getPathLast: function (path) {
return path.substring(path.lastIndexOf('/') + 1) return path.substring(path.lastIndexOf('/') + 1)
@@ -182,7 +224,7 @@ const helper = {
errors.forEach(element => { errors.forEach(element => {
let msg; let msg;
if (msg = element.getAttribute('data-error-message')) if (msg = element.getAttribute('data-error-message'))
helper.message(msg, 20000); helper.error(msg, 20000);
}) })
}, },
str2Boolean: function (str) { str2Boolean: function (str) {
@@ -204,6 +246,9 @@ const helper = {
default: default:
return Boolean(str); return Boolean(str);
} }
},
t: function (str) {
return t("ncdownloader", str);
} }
} }