feat: add pause buttons to individual notifs

This commit is contained in:
Matt Pumarlo
2026-06-24 16:01:25 -05:00
parent bf12f5e36d
commit 0b380f8c2d
3 changed files with 29 additions and 5 deletions

View File

@@ -202,7 +202,8 @@ def list_notification_urls() -> list[dict]:
events_str = cfg.get("notifications", f"events_{idx}", fallback="finished,failed,cancelled")
events = [e.strip() for e in events_str.split(",") if e.strip()]
include_image = cfg.get("notifications", f"image_{idx}", fallback="false").strip().lower() in ("1", "true", "yes")
result.append({"url": url, "events": events, "include_image": include_image})
enabled = cfg.get("notifications", f"enabled_{idx}", fallback="true").strip().lower() in ("1", "true", "yes")
result.append({"url": url, "events": events, "include_image": include_image, "enabled": enabled})
idx += 1
return result

View File

@@ -1111,7 +1111,8 @@ class KobraXBridge:
def _notify(self, event: str, filename: str = ""):
if self._notifications_paused:
return
matching = [e for e in self._notification_urls if event in e.get("events", [])]
matching = [e for e in self._notification_urls
if e.get("enabled", True) and event in e.get("events", [])]
if not matching:
return
printer_name = self._state.get("printer_name", "KX-Bridge")
@@ -1194,7 +1195,8 @@ class KobraXBridge:
def _check_progress_notifications(self):
if self._state.get("kobra_state") != "printing":
return
if not any("progress" in e.get("events", []) for e in self._notification_urls):
if not any("progress" in e.get("events", []) for e in self._notification_urls
if e.get("enabled", True)):
return
if self._notify_every_minutes == 0 and self._notify_every_layers == 0:
return
@@ -4453,12 +4455,14 @@ class KobraXBridge:
continue
events = [e for e in entry.get("events", []) if e in valid_events]
include_image = bool(entry.get("include_image", False))
entries.append({"url": url, "events": events, "include_image": include_image})
enabled = bool(entry.get("enabled", True))
entries.append({"url": url, "events": events, "include_image": include_image, "enabled": enabled})
cfg.add_section("notifications")
for i, entry in enumerate(entries, 1):
cfg.set("notifications", f"url_{i}", entry["url"])
cfg.set("notifications", f"events_{i}", ",".join(entry["events"]))
cfg.set("notifications", f"image_{i}", "true" if entry["include_image"] else "false")
cfg.set("notifications", f"enabled_{i}", "true" if entry["enabled"] else "false")
self._notification_urls = entries
elif not cfg.has_section("notifications"):
cfg.add_section("notifications")

View File

@@ -1565,6 +1565,7 @@ function notifRenderList(entries) {
url: e.url || "",
events: e.events || [],
include_image: !!e.include_image,
enabled: e.enabled === undefined ? true : !!e.enabled,
};
});
notifRefreshDOM();
@@ -1616,8 +1617,19 @@ function notifRefreshDOM() {
(T.settings_notif_send_image || "Image") +
"</label>";
return (
'<div style="background:var(--raised);border-radius:6px;padding:8px;margin-bottom:6px">' +
'<div style="background:var(--raised);border-radius:6px;padding:8px;margin-bottom:6px' +
(row.enabled ? "" : ";opacity:0.5") +
'">' +
'<div style="display:flex;gap:6px;align-items:center;margin-bottom:6px">' +
'<button onclick="notifToggleEnabled(' +
idx +
')" title="' +
(row.enabled ? T.settings_notif_active || "Active" : T.settings_notif_paused || "Paused") +
'" style="background:' +
(row.enabled ? "var(--ok,#2e9e4f)" : "var(--warn,#c08a2d)") +
';border:none;color:#fff;border-radius:4px;cursor:pointer;padding:2px 8px;font-size:11px;white-space:nowrap">' +
(row.enabled ? T.settings_notif_active || "Active" : T.settings_notif_paused || "Paused") +
"</button>" +
'<input type="text" value="' +
_escHtml(row.url) +
'" placeholder="discord://… telegram://… gotify://…"' +
@@ -1659,6 +1671,7 @@ function notifAddRow() {
url: "",
events: ["finished", "failed"],
include_image: false,
enabled: true,
});
notifRefreshDOM();
}
@@ -1679,6 +1692,11 @@ function notifToggleEvent(idx, ev) {
function notifToggleImage(idx) {
if (_notifRows[idx]) _notifRows[idx].include_image = !_notifRows[idx].include_image;
}
function notifToggleEnabled(idx) {
if (!_notifRows[idx]) return;
_notifRows[idx].enabled = !_notifRows[idx].enabled;
notifRefreshDOM();
}
function notifCollect() {
return _notifRows
.filter(function (r) {
@@ -1689,6 +1707,7 @@ function notifCollect() {
url: r.url.trim(),
events: r.events,
include_image: !!r.include_image,
enabled: r.enabled === undefined ? true : !!r.enabled,
};
});
}