pushraker 0.2.4__tar.gz → 0.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {pushraker-0.2.4/src/pushraker.egg-info → pushraker-0.2.6}/PKG-INFO +1 -1
  2. {pushraker-0.2.4 → pushraker-0.2.6}/pyproject.toml +1 -1
  3. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/__init__.py +1 -1
  4. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/component.py +3 -8
  5. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/printers/snapmaker_u1.py +1 -1
  6. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/settings.py +4 -70
  7. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/web/index.html +117 -58
  8. {pushraker-0.2.4 → pushraker-0.2.6/src/pushraker.egg-info}/PKG-INFO +1 -1
  9. {pushraker-0.2.4 → pushraker-0.2.6}/tests/test_pushraker.py +2 -2
  10. {pushraker-0.2.4 → pushraker-0.2.6}/tests/test_settings.py +5 -20
  11. {pushraker-0.2.4 → pushraker-0.2.6}/LICENSE +0 -0
  12. {pushraker-0.2.4 → pushraker-0.2.6}/README.md +0 -0
  13. {pushraker-0.2.4 → pushraker-0.2.6}/setup.cfg +0 -0
  14. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/__main__.py +0 -0
  15. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/discord.py +0 -0
  16. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/email_html.py +0 -0
  17. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/images.py +0 -0
  18. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/klipper/pushraker.cfg +0 -0
  19. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker/printers/__init__.py +0 -0
  20. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker.egg-info/SOURCES.txt +0 -0
  21. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker.egg-info/dependency_links.txt +0 -0
  22. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker.egg-info/requires.txt +0 -0
  23. {pushraker-0.2.4 → pushraker-0.2.6}/src/pushraker.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pushraker
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Push notifications for Klipper printers: a Moonraker component with pictures, sent through Apprise (ntfy, Pushover, Telegram, Discord, webhooks, email)
5
5
  Author: noon92
6
6
  License-Expression: GPL-3.0-or-later
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pushraker"
7
- version = "0.2.4"
7
+ version = "0.2.6"
8
8
  description = "Push notifications for Klipper printers: a Moonraker component with pictures, sent through Apprise (ntfy, Pushover, Telegram, Discord, webhooks, email)"
9
9
  readme = "README.md"
10
10
  license = "GPL-3.0-or-later"
@@ -4,4 +4,4 @@
4
4
 
5
5
  """Push notifications for Klipper printers, as a Moonraker component."""
6
6
 
7
- __version__ = "0.2.4"
7
+ __version__ = "0.2.6"
@@ -1013,12 +1013,7 @@ class PushNotifications:
1013
1013
  spoolman = re.sub(r"/api(/v\d+)?/?$", "", url.rstrip("/"))
1014
1014
  except Exception:
1015
1015
  spoolman = ""
1016
- try:
1017
- ts = await self.eventloop.run_in_thread(cfgmod.tailscale_info)
1018
- except Exception:
1019
- ts = ("", "")
1020
1016
  return cfgmod.Env(cameras=cams, spoolman_url=spoolman,
1021
- local_ip=cfgmod.local_ip(), tailscale=ts,
1022
1017
  error_index_url=self.error_index_url,
1023
1018
  name=self.store.default_name if self.store
1024
1019
  else self.name,
@@ -2901,7 +2896,7 @@ class PushNotifications:
2901
2896
  return ""
2902
2897
  # A blank line before it unless the pauses line has one
2903
2898
  return ("" if self._job_pauses else "\n") + \
2904
- "Pre-print calibrations selected: " + \
2899
+ "📐 Pre-print calibrations selected: " + \
2905
2900
  ", ".join(self._pp_names) + "."
2906
2901
 
2907
2902
  def _track_preprint(self) -> None:
@@ -2951,8 +2946,8 @@ class PushNotifications:
2951
2946
  where = (f" (layer {layers[0]})" if len(layers) == 1 else
2952
2947
  " (layers " + ", ".join(str(n) for n in layers[:-1])
2953
2948
  + f" and {layers[-1]})")
2954
- return ("\nPrint job contains a pause" if len(ps) == 1 else
2955
- f"\nPrint job contains {len(ps)} pauses") + where + "."
2949
+ return ("\n⏸️ Print job contains a pause" if len(ps) == 1 else
2950
+ f"\n⏸️ Print job contains {len(ps)} pauses") + where + "."
2956
2951
 
2957
2952
  def _file_pause(self, position: Any) -> Optional[int]:
2958
2953
  """Index of the file's pause the print job stopped at, if the file
@@ -5,7 +5,7 @@
5
5
  """The Snapmaker U1 (with the extended firmware): what its Klipper adds
6
6
  beyond the standard objects. The firmware-side harness (the install step,
7
7
  the nginx alias, the Firmware Config entry) lives in the firmware's own
8
- repository, overlay 42-feature-notifications."""
8
+ repository, overlay 42-feature-pushraker."""
9
9
 
10
10
  from __future__ import annotations
11
11
  from typing import Sequence
@@ -19,8 +19,6 @@ import io
19
19
  import json
20
20
  import os
21
21
  import re
22
- import socket
23
- import subprocess
24
22
  import urllib.error
25
23
  import urllib.request
26
24
  from typing import Any, Dict, List, Optional, Sequence, Tuple
@@ -197,8 +195,6 @@ class Env:
197
195
  the component fetches (absolute), "stream": the live
198
196
  view's path or URL for the notification's link}
199
197
  spoolman_url Spoolman's base URL when Moonraker has [spoolman], else ""
200
- local_ip the printer's LAN address, for the printer URL buttons
201
- tailscale (MagicDNS name, IPv4) when Tailscale runs, else ("", "")
202
198
  error_index_url the printer maker's error-code index, linked from
203
199
  fault notifications ("" for none)
204
200
  name the printer's default name
@@ -209,8 +205,7 @@ class Env:
209
205
  """
210
206
 
211
207
  def __init__(self, cameras: Optional[Dict[str, Dict[str, str]]] = None,
212
- spoolman_url: str = "", local_ip: str = "",
213
- tailscale: Tuple[str, str] = ("", ""),
208
+ spoolman_url: str = "",
214
209
  error_index_url: str = "", name: str = "Printer",
215
210
  rows_unavailable: Sequence[str] = (),
216
211
  preprint: bool = False) -> None:
@@ -218,8 +213,6 @@ class Env:
218
213
  self.preprint = preprint
219
214
  self.rows_unavailable = set(rows_unavailable)
220
215
  self.spoolman_url = spoolman_url.rstrip("/")
221
- self.local_ip = local_ip
222
- self.tailscale = tailscale
223
216
  self.error_index_url = error_index_url
224
217
  self.name = name
225
218
 
@@ -627,15 +620,6 @@ def validate(data: Dict[str, Any], current: Dict[str, Any],
627
620
  raise ValueError("host or port")
628
621
  except ValueError:
629
622
  raise ConfigError("Printer URL must look like http://100.64.0.1")
630
- if s["printer_url"] and s["provider"] == "telegram" and s["push_enabled"]:
631
- host = urlparse(printer_root(s, env)).hostname or ""
632
- if "." not in host and ":" not in host:
633
- # Telegram drops text links whose host has no dot; the Tailscale
634
- # name was already replaced by the IP in printer_root
635
- raise ConfigError("Telegram doesn't link to a name without a "
636
- "dot, such as http://u1. Use the Tailscale "
637
- "name (Use Tailscale) or an IP address.")
638
-
639
623
  validate_email(s)
640
624
  if s["webhook_enabled"]:
641
625
  try:
@@ -854,56 +838,9 @@ def camera_live_url(s: Dict[str, Any], env: Env) -> str:
854
838
 
855
839
 
856
840
  def printer_root(s: Dict[str, Any], env: Optional[Env]) -> str:
857
- """The Printer URL without a trailing slash, as sent: for Telegram the
858
- Tailscale name becomes the Tailscale IP, because Telegram drops text
859
- links whose host has no dot (the text stays, the link is gone)."""
860
- root = s["printer_url"].rstrip("/")
861
- if env and s["provider"] == "telegram" and s["push_enabled"]:
862
- host, ip = env.tailscale
863
- try:
864
- u = urlparse(root)
865
- if host and ip and (u.hostname or "").lower() == host.lower():
866
- port = f":{u.port}" if u.port else ""
867
- root = u._replace(netloc=f"{ip}{port}").geturl()
868
- except ValueError:
869
- pass
870
- return root
871
-
872
-
873
- def local_ip() -> str:
874
- """The printer's LAN address (the source address of its default route)."""
875
- try:
876
- with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
877
- sock.connect(("192.0.2.1", 9)) # no packet is sent
878
- return sock.getsockname()[0]
879
- except OSError:
880
- return ""
881
-
882
-
883
- def tailscale_info(binary: str = "tailscale") -> Tuple[str, str]:
884
- """(MagicDNS name, IPv4) of this machine, if Tailscale is installed
885
- and running; ("", "") otherwise."""
886
- for path in (binary, "/usr/local/bin/tailscale", "/usr/bin/tailscale"):
887
- try:
888
- out = subprocess.run([path, "status", "--json"],
889
- capture_output=True, text=True, timeout=5)
890
- st = json.loads(out.stdout)
891
- break
892
- except (OSError, ValueError, subprocess.SubprocessError):
893
- continue
894
- else:
895
- return "", ""
896
- if st.get("BackendState") != "Running":
897
- return "", ""
898
- me = st.get("Self") or {}
899
- dns = (me.get("DNSName") or "").rstrip(".")
900
- # The short MagicDNS name resolves on devices with MagicDNS enabled
901
- host = dns.split(".")[0] if dns else (me.get("HostName") or "")
902
- ip = next((a for a in me.get("TailscaleIPs") or [] if ":" not in a), "")
903
- return host, ip
904
-
841
+ """The Printer URL without a trailing slash, as sent."""
842
+ return s["printer_url"].rstrip("/")
905
843
 
906
- # ---- Apprise URLs --------------------------------------------------------
907
844
 
908
845
  def links(s: Dict[str, Any], rid: str, env: Env) -> List[Tuple[str, str]]:
909
846
  """(title, url) buttons for a notification."""
@@ -1232,7 +1169,7 @@ def summary(s: Dict[str, Any], env: Optional[Env] = None) -> str:
1232
1169
  if stored_error(s, env):
1233
1170
  return "Needs attention"
1234
1171
  if not s["enabled"]:
1235
- return "Disabled"
1172
+ return "Notifications disabled"
1236
1173
  on = []
1237
1174
  if push_configured(s):
1238
1175
  on.append({"discord_dm": "Discord"}.get(
@@ -1275,9 +1212,6 @@ def public_view(s: Dict[str, Any], env: Env, busy: bool,
1275
1212
  "cameras": {name: {"snapshot": bool(c.get("snapshot")),
1276
1213
  "stream": bool(c.get("stream"))}
1277
1214
  for name, c in env.cameras.items()},
1278
- "local_ip": env.local_ip,
1279
- "tailscale_host": env.tailscale[0],
1280
- "tailscale_ip": env.tailscale[1],
1281
1215
  "busy": busy,
1282
1216
  "default_name": env.name,
1283
1217
  "stored_error": stored_error(s, env),
@@ -29,22 +29,33 @@
29
29
  .btn-primary:hover:not(:disabled) { background: #29b6f6; }
30
30
  .btn-secondary { background: #555; color: #fff; }
31
31
  .btn-secondary:hover:not(:disabled) { background: #666; }
32
- .pr-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; }
32
+ .pr-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg); padding: 12px 10px; }
33
33
  .pr-status { font-size: 13px; color: var(--muted); }
34
34
  /* Save & Apply is a group of its own: a gap from Cancel and Send Test
35
35
  (on a phone: one line, those two at the left, it at the right) */
36
- .btn-save { background: #2e7d32; color: #fff; font-size: 15px; min-height: 42px; padding: 10px 24px; margin-left: 40px; }
36
+ .btn-save { background: #2e7d32; color: #fff; margin-left: 40px; }
37
37
  @media (max-width: 600px) {
38
- .btn-save { padding: 10px 16px; white-space: nowrap; }
39
- .pr-save-wrap { margin-left: auto; }
38
+ .btn-save { white-space: nowrap; }
39
+ .pr-actions .pr-save-wrap { margin-right: auto; }
40
+ .pr-actions .btn { padding: 8px 9px; font-size: 12px; }
41
+ .pr-actions:has(.pr-safe.on) { padding-bottom: 12px; }
42
+ .pr-actions:has(.pr-safe.on) .pr-status { margin-top: 16px; }
43
+ .pr-actions { gap: 8px; padding: 12px 8px; }
40
44
  .pr-actions .btn { white-space: nowrap; }
41
45
  .pr-status { flex-basis: 100%; }
42
46
  }
43
47
  .btn-save:hover:not(:disabled) { background: #388e3c; }
44
- .pr-save-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: 3px; margin-left: 40px; }
48
+ /* The note hangs under Save & Apply without moving it: the buttons
49
+ stay on one line, tops level */
50
+ .pr-save-wrap { position: relative; display: inline-flex; margin-right: 30px; }
45
51
  .pr-save-wrap .btn-save { margin-left: 0; }
46
- .pr-safe { display: none; font-size: 11px; color: var(--success); white-space: nowrap; }
52
+ .pr-safe { display: none; position: absolute; top: 100%; left: 0; margin-top: 3px; font-size: 11px; color: var(--success); white-space: nowrap; }
47
53
  .pr-safe.on { display: block; }
54
+ .pr-actions:has(.pr-safe.on) { padding-bottom: 28px; }
55
+ @media (max-width: 380px) {
56
+ .pr-actions { gap: 6px; padding-left: 6px; padding-right: 6px; }
57
+ .pr-actions .btn { padding: 8px 6px; font-size: 11px; }
58
+ }
48
59
  /* Save and Send Test progress: a popup like Firmware Config's */
49
60
  .pr-run .pr-modal-box { max-width: 720px; border-radius: 12px; padding: 24px; max-height: 80vh; display: flex; flex-direction: column; }
50
61
  .pr-run h3 { font-size: 18px; margin-bottom: 16px; }
@@ -98,7 +109,7 @@
98
109
  .nt-name { color: #fff; }
99
110
  .nt-icon { display: inline-block; width: 24px; }
100
111
  .nt-table select.nt-input.nt-layer { width: auto; padding: 4px 6px; display: inline-block; font-family: inherit; }
101
- .nt-sub { display: block; margin-top: 4px; padding-left: 26px; font-size: 12px; color: #8a8f98; white-space: nowrap; }
112
+ .nt-sub { display: block; margin-top: 4px; padding-left: 26px; font-size: 12px; color: #8a8f98; white-space: normal; }
102
113
  .nt-sub select.nt-input.nt-layer { font-size: 12px; padding: 2px 4px; max-width: 140px; }
103
114
  .nt-sub input.nt-input.nt-deg { width: 56px; font-size: 12px; padding: 2px 4px; display: inline-block; }
104
115
  .nt-foot { font-size: 12px; color: #8a8f98; margin: 0 0 16px; }
@@ -109,6 +120,17 @@
109
120
  .nt-inline { display: flex; gap: 6px; }
110
121
  .nt-inline .btn { min-height: 0; padding: 0 12px; white-space: nowrap; }
111
122
  .nt-inline .btn.nt-active { border-color: var(--accent); color: var(--accent); }
123
+ /* Printer URL: Fill in lists this page's address and the printer's
124
+ network addresses; the list is as wide as the field and button */
125
+ .nt-fill-wrap { position: relative; }
126
+ .nt-fill-menu { display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: #1e1e1e; border: 1px solid #555; border-radius: 8px; overflow: hidden; box-shadow: 0 6px 20px rgba(0,0,0,0.5); }
127
+ .nt-fill-menu.open { display: block; }
128
+ .nt-fill-menu button { display: block; width: 100%; text-align: left; background: none; border: none; border-top: 1px solid #333; color: var(--text); font: inherit; font-size: 14px; padding: 12px; cursor: pointer; }
129
+ .nt-fill-menu button:first-child { border-top: none; }
130
+ .nt-fill-menu button:hover, .nt-fill-menu button:focus { background: #3a3a3a; outline: none; }
131
+ .nt-fill-menu code { font-family: monospace; }
132
+ .nt-fill-menu small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
133
+ .nt-fill-menu .nt-fill-clear { color: var(--muted); }
112
134
  .nt-field .nt-hint a { color: var(--accent); }
113
135
  .nt-disabled .nt-body { opacity: 0.55; }
114
136
  .nt-unit { align-items: center; }
@@ -361,14 +383,16 @@
361
383
  </div>
362
384
  <div class="nt-field" style="grid-column: 1 / -1">
363
385
  <label for="nt-printer-url">Printer URL for buttons (optional)</label>
364
- <div class="nt-inline">
365
- <input class="nt-input" id="nt-printer-url" placeholder="http://u1" autocomplete="off" spellcheck="false">
366
- <button type="button" class="btn btn-secondary" id="nt-use-local">Use local IP</button>
367
- <button type="button" class="btn btn-secondary" id="nt-use-tailscale">Use Tailscale</button>
386
+ <div class="nt-fill-wrap">
387
+ <div class="nt-inline">
388
+ <input class="nt-input" id="nt-printer-url" placeholder="http://u1.home" autocomplete="off" spellcheck="false">
389
+ <button type="button" class="btn btn-secondary" id="nt-fill" aria-haspopup="true" aria-expanded="false">Fill in ▾</button>
390
+ </div>
391
+ <div class="nt-fill-menu" id="nt-fill-menu" role="menu"></div>
368
392
  </div>
369
393
  <div class="nt-hint" id="nt-printer-url-hint"></div>
370
394
  <div class="nt-public" id="nt-local-warn" style="display:none">
371
- Local IP: the buttons only work when your phone is on the same network as the printer.
395
+ Local IP detected - may not work when not on same network as printer.
372
396
  </div>
373
397
  <div class="nt-public" id="nt-tg-warn" style="display:none"></div>
374
398
  </div>
@@ -413,12 +437,12 @@
413
437
 
414
438
  <div class="pr-error" id="pr-error" style="display:none"></div>
415
439
  <div class="pr-actions">
416
- <button type="button" class="btn btn-secondary" id="pr-close">Cancel</button>
417
- <button type="button" class="btn btn-secondary" id="pr-test">Send Test</button>
418
440
  <span class="pr-save-wrap">
419
441
  <button type="button" class="btn btn-save" id="pr-save">Save &amp; Apply</button>
420
442
  <span class="pr-safe" id="pr-safe">✓ Safe to save while printing</span>
421
443
  </span>
444
+ <button type="button" class="btn btn-secondary" id="pr-test">Send Test</button>
445
+ <button type="button" class="btn btn-secondary" id="pr-close" disabled>Discard changes</button>
422
446
  <span class="pr-status" id="pr-status"></span>
423
447
  </div>
424
448
 
@@ -435,8 +459,8 @@
435
459
 
436
460
  <div class="pr-modal pr-discard" id="pr-discard" role="alertdialog" aria-labelledby="pr-discard-title">
437
461
  <div class="pr-modal-box">
438
- <h3 id="pr-discard-title">Leave without saving?</h3>
439
- <p>The changes you made on this page will not be kept.</p>
462
+ <h3 id="pr-discard-title">Discard changes?</h3>
463
+ <p>The settings go back to the last saved ones. The changes you made on this page will not be kept.</p>
440
464
  <div class="pr-buttons">
441
465
  <button type="button" class="btn btn-discard" id="pr-discard-yes" disabled>Discard changes</button>
442
466
  <button type="button" class="btn btn-keep" id="pr-discard-no">Keep editing</button>
@@ -465,7 +489,6 @@
465
489
  const el = id => document.getElementById(id);
466
490
  const esc = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c]);
467
491
  let state = null;
468
- let localWarned = false; // the local IP popup shows once per opening
469
492
  let saved = ''; // the payload as last loaded or saved
470
493
 
471
494
  // ---- Moonraker ------------------------------------------------------
@@ -586,7 +609,7 @@
586
609
  return html + `<tr data-row="${meta.id}">
587
610
  <td><span class="nt-icon">${meta.icon}</span>${layer ? `${layer} <span class="nt-name">layer complete</span>` : `<span class="nt-name">${esc(meta.label)}</span>`}${objects}${driver}${report}${calib}</td>
588
611
  <td class="nt-c nt-col-push"><input type="checkbox" data-enabled="${meta.id}"${row.enabled ? ' checked' : ''}></td>
589
- <td class="nt-col-push">${meta.id === 'macro' ? '<span class="nt-sub" style="margin:0 0 2px">Default:</span>' : ''}<select class="nt-input nt-dim-push" data-priority="${meta.id}">${prio}</select></td>
612
+ <td class="nt-col-push"><select class="nt-input nt-dim-push" data-priority="${meta.id}">${prio}</select></td>
590
613
  <td class="nt-c nt-col-email"><input type="checkbox" data-email="${meta.id}"${row.email ? ' checked' : ''}></td>
591
614
  <td class="nt-c nt-img"><span class="nt-dim">${image}</span></td>
592
615
  </tr>`;
@@ -674,9 +697,9 @@
674
697
  'notifications, including camera images, model previews and file names.\n\n' +
675
698
  'It is fine for testing. For everyday use, setting up your own ntfy server is a good idea. ' +
676
699
  'On the public server, use a long random topic (the Random button creates one).';
677
- const LOCAL_WARNING = 'With the local IP, the Web UI and Live Camera buttons only work when your phone ' +
678
- 'is on the same network as the printer.\n\nUse Tailscale (or another address your phone can reach) ' +
679
- 'for buttons that work from anywhere.';
700
+ const TG_WARNING = 'Telegram does not support clickable URLs without a <code>.</code> (period character), ' +
701
+ 'so the Web UI and Live Camera buttons won\'t work in Telegram. Pick an IP address from <b>Fill in</b>, ' +
702
+ 'or use a full name such as <code>u1.home</code>.';
680
703
  const isPublic = server => /^https?:\/\/(www\.)?ntfy\.sh\/?$/i.test(server.trim());
681
704
 
682
705
  function randomTopic() {
@@ -702,23 +725,74 @@
702
725
  try { return new URL(url).hostname.toLowerCase(); } catch (e) { return ''; }
703
726
  }
704
727
 
728
+ // The warnings follow the field once it's left (or filled in), not
729
+ // while typing
705
730
  function updatePrinterUrl() {
706
731
  const url = el('nt-printer-url').value.trim();
707
732
  el('nt-local-warn').style.display = url && isLanOnly(url) ? '' : 'none';
708
- const same = (host) => !!host && url.replace(/\/+$/, '').toLowerCase() === ('http://' + host).toLowerCase();
709
- el('nt-use-local').classList.toggle('nt-active', same(state.meta.local_ip));
710
- el('nt-use-tailscale').classList.toggle('nt-active', same(state.meta.tailscale_host));
711
733
  const prov = el('nt-provider').value;
712
734
  el('nt-printer-url-hint').innerHTML = prov === 'pushover'
713
735
  ? 'Adds a <b>Web UI</b> link. Without it, fault notifications link to the Error Index.'
714
736
  : ['gotify', 'telegram', 'discord', 'discord_dm'].includes(prov)
715
737
  ? 'Adds <b>Web UI</b> and <b>Live Camera</b> links. Leave empty for no links.'
716
738
  : 'Adds <b>Web UI</b> and <b>Live Camera</b> buttons. Leave empty for no buttons.';
717
- const tg = prov === 'telegram' && state.meta.tailscale_ip && hostOf(url) === (state.meta.tailscale_host || '').toLowerCase();
739
+ const host = hostOf(url);
740
+ const tg = prov === 'telegram' && el('nt-push-enabled').checked && !!host && !host.includes('.') && !host.includes(':');
718
741
  el('nt-tg-warn').style.display = tg ? '' : 'none';
719
- if (tg) el('nt-tg-warn').textContent = `Telegram can't link to a Tailscale name, so the Tailscale IP (${state.meta.tailscale_ip}) is used for Telegram links.`;
742
+ if (tg) el('nt-tg-warn').innerHTML = TG_WARNING;
720
743
  }
721
744
 
745
+ // Fill in: this page's own address (how you reach the printer now),
746
+ // and the IPv4 address of each network interface Moonraker reports
747
+ // (/machine/system_info), by interface name; nothing is detected by
748
+ // name. Then Clear.
749
+ let fillChoices = null;
750
+ async function fillOptions() {
751
+ if (fillChoices) return fillChoices;
752
+ const out = [];
753
+ if (/^https?:$/.test(location.protocol) && location.hostname) {
754
+ out.push({ url: location.protocol + '//' + location.host, html:
755
+ `This browser's address: <code>${esc(location.host)}</code><small>Works wherever this address works for you</small>` });
756
+ }
757
+ try {
758
+ const info = await api('/machine/system_info');
759
+ const net = (info && info.system_info && info.system_info.network) || {};
760
+ for (const [name, iface] of Object.entries(net)) {
761
+ if (name === 'lo') continue;
762
+ for (const a of iface.ip_addresses || []) {
763
+ if (a.family !== 'ipv4' || a.is_link_local || !a.address || a.address.startsWith('127.')) continue;
764
+ out.push({ url: 'http://' + a.address, html: `${esc(name)}: <code>${esc(a.address)}</code>` });
765
+ }
766
+ }
767
+ } catch (e) { /* the browser's address is still offered */ }
768
+ fillChoices = out;
769
+ return out;
770
+ }
771
+ function closeFill() {
772
+ el('nt-fill-menu').classList.remove('open');
773
+ el('nt-fill').setAttribute('aria-expanded', 'false');
774
+ }
775
+ async function openFill() {
776
+ const menu = el('nt-fill-menu');
777
+ const choices = await fillOptions();
778
+ menu.innerHTML = choices.map((c, i) =>
779
+ `<button type="button" role="menuitem" data-i="${i}">${c.html}</button>`).join('') +
780
+ '<button type="button" role="menuitem" class="nt-fill-clear" data-i="clear">Clear (no buttons)</button>';
781
+ menu.querySelectorAll('button').forEach(b => b.onclick = () => {
782
+ el('nt-printer-url').value = b.dataset.i === 'clear' ? '' : choices[+b.dataset.i].url;
783
+ closeFill();
784
+ updatePrinterUrl();
785
+ });
786
+ menu.classList.add('open');
787
+ el('nt-fill').setAttribute('aria-expanded', 'true');
788
+ const first = menu.querySelector('button');
789
+ if (first) first.focus();
790
+ }
791
+ document.addEventListener('click', e => {
792
+ if (!e.target.closest('.nt-fill-wrap')) closeFill();
793
+ });
794
+ document.addEventListener('keydown', e => { if (e.key === 'Escape') closeFill(); });
795
+
722
796
  function updatePublicWarning() {
723
797
  const pub = el('nt-provider').value === 'ntfy' && isPublic(el('nt-server').value);
724
798
  el('nt-public-warn').style.display = pub ? '' : 'none';
@@ -792,7 +866,6 @@
792
866
  // ---- load / collect ----------------------------------------------------
793
867
  function render(data) {
794
868
  state = data;
795
- localWarned = false;
796
869
  el('pr-version').textContent = data.meta.version ? `pushraker ${data.meta.version}` : '';
797
870
  el('nt-enabled').checked = data.enabled;
798
871
  el('nt-push-enabled').checked = data.push_enabled !== false;
@@ -867,28 +940,17 @@
867
940
  el('nt-auth').onchange = updateAuth;
868
941
  el('nt-provider').onchange = updateProvider;
869
942
  el('nt-use-public').onclick = usePublicServer;
870
- el('nt-printer-url').oninput = updatePrinterUrl;
871
- el('nt-use-local').disabled = !data.meta.local_ip;
872
- el('nt-use-local').onclick = async () => {
873
- if (!localWarned && !await confirmModal('Use the local IP?', LOCAL_WARNING, 'Use local IP')) return;
874
- localWarned = true;
875
- el('nt-printer-url').value = 'http://' + data.meta.local_ip;
876
- updatePrinterUrl();
943
+ el('nt-printer-url').onchange = updatePrinterUrl;
944
+ el('nt-fill').onclick = e => {
945
+ e.stopPropagation();
946
+ if (el('nt-fill-menu').classList.contains('open')) closeFill(); else openFill();
877
947
  };
878
- const ts = data.meta.tailscale_host;
879
- // First setup only: suggest the best printer address. Once saved,
880
- // an empty field means "no buttons" and is left alone.
948
+ // First setup only: the address this page was opened with. Once
949
+ // saved, an empty field means "no buttons" and is left alone.
881
950
  const firstSetup = !data.enabled && !data.server && !data.pushover_user && !data.has_secret;
882
- if (firstSetup && !data.printer_url) {
883
- if (ts) el('nt-printer-url').value = 'http://' + ts;
884
- else if (data.meta.local_ip) el('nt-printer-url').value = 'http://' + data.meta.local_ip;
951
+ if (firstSetup && !data.printer_url && /^https?:$/.test(location.protocol) && location.hostname) {
952
+ el('nt-printer-url').value = location.protocol + '//' + location.host;
885
953
  }
886
- el('nt-use-tailscale').disabled = !ts;
887
- el('nt-use-tailscale').title = ts ? `http://${ts}` : 'Tailscale is not running on the printer';
888
- el('nt-use-tailscale').onclick = () => {
889
- el('nt-printer-url').value = 'http://' + ts;
890
- updatePrinterUrl();
891
- };
892
954
  updatePrinterUrl();
893
955
  el('nt-server').oninput = updatePublicWarning;
894
956
  el('nt-topic').oninput = () => {
@@ -1124,11 +1186,13 @@
1124
1186
 
1125
1187
  el('pr-save').onclick = save;
1126
1188
  el('pr-test').onclick = test;
1127
- // Close without saving: embedded (an iframe in a host page's modal),
1128
- // tell the host, which closes it; on its own, go back to the page it
1129
- // was opened from, or close the tab, or go to the printer's start page
1189
+ // Discard changes: back to the last saved settings, on this page.
1190
+ // Only with unsaved changes (the button is greyed out otherwise)
1130
1191
  let closing = false;
1131
1192
  const dirty = () => !!state && JSON.stringify(collect(false)) !== saved;
1193
+ const markDirty = () => { el('pr-close').disabled = !dirty(); };
1194
+ document.addEventListener('input', markDirty);
1195
+ document.addEventListener('change', markDirty);
1132
1196
  // With unsaved changes, a warning first: the discard button only
1133
1197
  // works after 5 seconds, so a misclick can't throw the changes away
1134
1198
  function confirmDiscard() {
@@ -1157,15 +1221,10 @@
1157
1221
  });
1158
1222
  }
1159
1223
  el('pr-close').onclick = async () => {
1160
- if (dirty() && !(await confirmDiscard())) return;
1161
- closing = true;
1162
- if (window.parent !== window) {
1163
- window.parent.postMessage({ type: 'pushraker:close' }, '*');
1164
- return;
1165
- }
1166
- if (history.length > 1) { history.back(); return; }
1167
- window.close();
1168
- setTimeout(() => { location.href = '/'; }, 300);
1224
+ if (!dirty() || !(await confirmDiscard())) return;
1225
+ render(state);
1226
+ el('pr-close').disabled = true;
1227
+ el('pr-status').textContent = 'Changes discarded';
1169
1228
  };
1170
1229
  window.addEventListener('beforeunload', e => {
1171
1230
  if (closing) return;
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pushraker
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Push notifications for Klipper printers: a Moonraker component with pictures, sent through Apprise (ntfy, Pushover, Telegram, Discord, webhooks, email)
5
5
  Author: noon92
6
6
  License-Expression: GPL-3.0-or-later
@@ -1183,7 +1183,7 @@ async def test_file_pauses():
1183
1183
  (55, "", "filament change")],
1184
1184
  c._job_pauses)
1185
1185
  check("started says so", log and log[0]["body"].endswith(
1186
- "\n\nPrint job contains 3 pauses (layers 12, 40 and 55)."),
1186
+ "\n\n⏸️ Print job contains 3 pauses (layers 12, 40 and 55)."),
1187
1187
  log and log[0]["body"])
1188
1188
  log.clear()
1189
1189
  # The file's pause: file position just past the pause line
@@ -1261,7 +1261,7 @@ async def test_file_mode():
1261
1261
  "case": {"snapshot": True, "stream": True}}
1262
1262
  and view["meta"]["default_name"] == "U1"
1263
1263
  and view["meta"]["spoolman"] and view["meta"]["summary"]
1264
- == "Disabled", view["meta"])
1264
+ == "Notifications disabled", view["meta"])
1265
1265
  check("Spoolman's base URL from Moonraker's [spoolman] (its URL ends in /api)",
1266
1266
  c.env.spoolman_url == "http://spoolman:7912", c.env.spoolman_url)
1267
1267
  try:
@@ -74,33 +74,18 @@ def run_settings_tests():
74
74
  gopts["error"].startswith("none, gotifys://g.example.com:8443/")
75
75
  and gopts["web_ui_url"] == "http://u1/"
76
76
  and gopts["camera_url"] == "http://u1/webcam/webrtc", gopts)
77
- bad(dict(provider="telegram", secret="12345:" + "A" * 35,
78
- telegram_chat="123", printer_url="http://u1"),
79
- "rejects a dot-less printer host for Telegram (links are dropped)")
80
77
  st.validate(dict(provider="telegram", secret="12345:" + "A" * 35,
81
78
  telegram_chat="123", printer_url="http://100.64.0.10"),
82
79
  fresh(), ENV)
83
80
  st.validate(dict(provider="ntfy", server="https://ntfy.example.com",
84
81
  topic="u1", printer_url="http://u1"), fresh(), ENV)
85
82
  check("a dot-less printer host is fine for the other services", True)
86
- ts = st.Env(cameras=ENV.cameras, tailscale=("u1", "100.64.0.10"))
87
83
  tg = dict(enabled=True, provider="telegram", secret="12345:" + "A" * 35,
88
- telegram_chat="123", printer_url="http://U1/", camera="case")
89
- s = st.validate(tg, fresh(), ts)
90
- check("Telegram: the Tailscale name is accepted and sent as the IP",
91
- st.links(s, "test", ts)[:2] == [
92
- ("Web UI", "http://100.64.0.10/"),
93
- ("Live Camera", "http://100.64.0.10/webcam/webrtc")]
94
- and st.render_options(s, ts)["web_ui_url"] == "http://100.64.0.10/"
95
- and s["printer_url"] == "http://U1/", st.links(s, "test", ts))
96
- bad(dict(provider="telegram", secret="12345:" + "A" * 35,
97
- telegram_chat="123", printer_url="http://other"),
98
- "Telegram: another dot-less name is still refused", ts)
99
- s = st.validate(dict(enabled=True, provider="ntfy",
100
- server="https://ntfy.example.com", topic="u1",
101
- printer_url="http://u1"), fresh(), ts)
102
- check("other services keep the Tailscale name",
103
- st.links(s, "test", ts)[0] == ("Web UI", "http://u1/"))
84
+ telegram_chat="123", printer_url="http://u1/", camera="case")
85
+ s = st.validate(tg, fresh(), ENV)
86
+ check("Telegram: a dot-less printer URL is saved as entered (the page "
87
+ "warns)", st.links(s, "test", ENV)[0] == ("Web UI", "http://u1/"),
88
+ st.links(s, "test", ENV))
104
89
  bad(dict(provider="discord", secret="https://example.com/x"),
105
90
  "rejects a URL that isn't a Discord webhook")
106
91
 
File without changes
File without changes
File without changes