diff --git a/src/actions/updatePage.js b/src/actions/updatePage.js index 97fad37..21d0c30 100644 --- a/src/actions/updatePage.js +++ b/src/actions/updatePage.js @@ -11,9 +11,6 @@ export default { let container = document.querySelector(tableContainer); let currentType = container.getAttribute("type"); let path = basePath + type; - if (type === "youtube-dl") { - path = "/apps/ncdownloader/youtube/get"; - } let name = type + "-downloads"; //avoid repeated click if (currentType === name && helper.isPolling()) { @@ -21,11 +18,15 @@ export default { } container.setAttribute("type", name); container.className = "table " + name; - let delay = 15000; - if (['active', 'youtube-dl'].includes(type)) { - delay = 1500; + let delay; + if (!['active', 'youtube-dl'].includes(type)) { + delay = 15000; + } + if (type === "youtube-dl") { + helper.pollingYoutube(); + } else { + helper.polling(delay, path); } - helper.polling(delay, path); }; eventHandler.add("click", ".waiting-downloads a", event => clickHandler(event, 'waiting')); eventHandler.add("click", ".complete-downloads a", event => clickHandler(event, 'complete')); diff --git a/src/lib/polling.ts b/src/lib/polling.ts index fb04bc3..0b4dedf 100644 --- a/src/lib/polling.ts +++ b/src/lib/polling.ts @@ -3,7 +3,7 @@ type callback = (...args: any[]) => void class Polling { private static instance: Polling; private timeoutID: number; - private delay: number = 1000; + private delay: number = 1500; private enabled: boolean = false; constructor() { this.enabled = false; @@ -24,7 +24,7 @@ class Polling { isEnabled() { return this.enabled; } - setDelay(time: number): Polling { + setDelay(time: number = 1500): Polling { this.delay = time; return this; } diff --git a/src/utils/helper.js b/src/utils/helper.js index 9ba6948..5361490 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -7,7 +7,6 @@ import { translate as t, translatePlural as n } from '@nextcloud/l10n' import contentTable from '../lib/contentTable'; import Http from '../lib/http' import Polling from "../lib/polling"; - const helper = { vue: {}, addVue(name, object) { @@ -26,7 +25,7 @@ const helper = { disablePolling() { Polling.create().disable().clear(); }, - polling(delay = 1000, path) { + polling(delay = 1500, path) { Polling.create().setDelay(delay).run(helper.refresh, path); }, scanFolder(path = "/apps/ncdownloader/scanfolder") { @@ -37,9 +36,12 @@ const helper = { }).send(); }); }, - pollingFolder(delay = 1000) { + pollingFolder(delay = 1500) { Polling.create().setDelay(delay).run(helper.scanFolder); }, + pollingYoutube(delay = 1500) { + Polling.create().setDelay(delay).run(helper.refresh, "/apps/ncdownloader/youtube/get"); + }, refresh(path) { path = path || "/apps/ncdownloader/status/active"; let url = helper.generateUrl(path);