Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/luci-app-adblock-fast/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PKG_NAME:=luci-app-adblock-fast
PKG_LICENSE:=AGPL-3.0-or-later
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.ca>
PKG_VERSION:=1.2.2
PKG_RELEASE:=6
PKG_RELEASE:=8

LUCI_TITLE:=AdBlock-Fast Web UI
LUCI_URL:=https://github.com/mossdef-org/luci-app-adblock-fast/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
isObjEmpty: function (obj) {
return Object.keys(obj).length === 0;
},
formatPauseTimeout: function (seconds) {
var s = parseInt(seconds) || 20;
if (s < 60) return s + "s";
var m = Math.floor(s / 60);
var rem = s % 60;
if (rem === 0) return m + "m";
return m + "m " + rem + "s";
},

statusTable: {
statusNoInstall: _("%s is not installed or not found").format(
Expand Down Expand Up @@ -99,12 +107,6 @@
warningCronMissing: _(
"Cron daemon is not available. If BusyBox crond is present, enable it with: %s; otherwise install another cron daemon.",
),
warningCronEntryMissing: _(
"Cron entry is missing; click %s to recreate it.",
),
warningCronEntryMismatch: _(
"Cron entry does not match the schedule; click %s to overwrite it.",
),
},

errorTable: {
Expand Down Expand Up @@ -199,12 +201,6 @@
params: ["name"],
});

var getCronEntry = rpc.declare({
object: "luci." + pkg.Name,
method: "getCronEntry",
params: ["name"],
});

var setCronEntry = rpc.declare({
object: "luci." + pkg.Name,
method: "setCronEntry",
Expand Down Expand Up @@ -380,16 +376,14 @@
],
});
}
var cronSyncNeeded = false;
var showCronWarnings =
if (
reply.status.enabled &&
reply.status.running &&
(reply.cron.auto_update_enabled ||
reply.cron.cron_line_state === "suspended");
if (showCronWarnings) {
reply.cron.cron_line_state === "suspended")
) {
var enableCronCmd =
"<code>/etc/init.d/cron enable && /etc/init.d/cron start</code>";
var resyncLabel = "<code>" + _("Resync Cron") + "</code>";
if (!reply.cron.cron_init || !reply.cron.cron_bin) {
reply.ubus.warnings.push({
code: "warningCronMissing",
Expand All @@ -401,37 +395,6 @@
info: enableCronCmd,
});
}
if (reply.cron.cron_line_state === "suspended") {
reply.ubus.warnings.push({
code: "warningCronEntryMismatch",
info: resyncLabel,
});
cronSyncNeeded = true;
} else if (
reply.cron.auto_update_enabled &&
(reply.cron.cron_line_state === "unsupported" ||
reply.cron.cron_line_state === "multi")
) {
reply.ubus.warnings.push({
code: "warningCronEntryMismatch",
info: resyncLabel,
});
cronSyncNeeded = true;
} else if (reply.cron.auto_update_enabled) {
if (!reply.cron.cron_line_present) {
reply.ubus.warnings.push({
code: "warningCronEntryMissing",
info: resyncLabel,
});
cronSyncNeeded = true;
} else if (!reply.cron.cron_line_match) {
reply.ubus.warnings.push({
code: "warningCronEntryMismatch",
info: resyncLabel,
});
cronSyncNeeded = true;
}
}
}
var text = "";
var outputFile = reply.status.outputFile;
Expand Down Expand Up @@ -641,65 +604,55 @@
_("Redownload"),
);

var btn_sync_cron = E(
"button",
{
class: "btn cbi-button cbi-button-apply",
disabled: true,
click: function (ev) {
ui.showModal(null, [
E("p", { class: "spinning" }, _("Syncing cron schedule")),
]);
return L.resolveDefault(getCronEntry(pkg.Name), {})
.then(function (response) {
var entry =
(response?.[pkg.Name] && response[pkg.Name].entry) || "";
if (!entry) {
return Promise.reject(new Error("No cron entry"));
}
entry = entry.replace(/^\s*#\s*/, "");
entry = entry.replace(
/adblock-fast-auto-(suspended|disabled)/g,
"adblock-fast-auto",
);
return L.resolveDefault(setCronEntry(pkg.Name, entry), {
result: false,
});
})
.then(
function (result) {
if (!result || result.result === false) {
throw new Error("Failed to update cron schedule");
}
ui.hideModal();
location.reload();
},
function (error) {
ui.hideModal();
ui.addNotification(
null,
E("p", {}, _("Failed to sync cron schedule")),
);
},
);
},
},
_("Resync Cron"),
);

var pauseTimeout = parseInt(reply.status.pause_timeout) || 20;
var pauseLabel =
_("Pause") + " (" + pkg.formatPauseTimeout(pauseTimeout) + ")";
var btn_action_pause = E(
"button",
{
class: "btn cbi-button cbi-button-apply",
disabled: true,
click: function (ev) {
ui.showModal(null, [
E("p", { class: "spinning" }, _("Pausing %s").format(pkg.Name)),
]);
return RPC.setInitAction(pkg.Name, "pause");
var remaining = pauseTimeout;
var allButtons = [
btn_start,
btn_action_dl,
btn_action_pause,
btn_stop,
btn_enable,
btn_disable,
];
if (typeof btn_sync_cron !== "undefined")
allButtons.push(btn_sync_cron);

Check warning on line 626 in applications/luci-app-adblock-fast/htdocs/luci-static/resources/adblock-fast/status.js

View workflow job for this annotation

GitHub Actions / eslint

'btn_sync_cron' is not defined
allButtons.forEach(function (b) {
b.disabled = true;
});
btn_action_pause.textContent =
_("Pause") +
" (" +
pkg.formatPauseTimeout(remaining) +
")";
RPC.setInitAction(pkg.Name, "pause");
var countdown = setInterval(function () {
remaining--;
if (remaining > 0) {
btn_action_pause.textContent =
_("Pause") +
" (" +
pkg.formatPauseTimeout(remaining) +
")";
} else {
clearInterval(countdown);
btn_action_pause.textContent =
_("Pause") + " (" + _("Restarting") + "…)";
pollServiceStatus(function () {
location.reload();
});
}
}, 1000);
},
},
_("Pause"),
pauseLabel,
);

var btn_stop = E(
Expand Down Expand Up @@ -792,10 +745,6 @@
btn_enable.disabled = false;
btn_disable.disabled = true;
}
if (cronSyncNeeded) {
btn_sync_cron.disabled = false;
}

var buttonsDiv = [];
var buttonsTitle = E(
"label",
Expand All @@ -805,21 +754,16 @@
var buttonsTextItems = [
btn_start,
btn_gap,
// btn_action_pause,
// btn_gap,
btn_action_dl,
];
if (cronSyncNeeded) {
buttonsTextItems.push(btn_gap, btn_sync_cron);
}
buttonsTextItems.push(
btn_gap,
btn_action_pause,
btn_gap,
btn_stop,
btn_gap_long,
btn_enable,
btn_gap,
btn_disable,
);
];
var buttonsText = E("div", {}, buttonsTextItems);
var buttonsField = E("div", { class: "cbi-value-field" }, buttonsText);
if (reply.status.version) {
Expand Down Expand Up @@ -857,7 +801,6 @@
getFileUrlFilesizes: getFileUrlFilesizes,
syncCron: syncCron,
getCronStatus: getCronStatus,
getCronEntry: getCronEntry,
setCronEntry: setCronEntry,
getPlatformSupport: getPlatformSupport,
getServiceInfo: getServiceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,18 @@ return view.extend({
o.default = "20";
o.datatype = "range(1,60)";

o = s1.taboption(
"tab_advanced",
form.Value,
"pause_timeout",
_("Pause time-out (in seconds)"),
_(
"Pause ad-blocking for the specified number of seconds when the Pause button is pressed.",
),
);
o.default = "20";
o.datatype = "range(1,600)";

o = s1.taboption(
"tab_advanced",
form.Value,
Expand Down
Loading