From 72360758acfb825ec424c4a5ea0fbc0495b95beb Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Fri, 5 Jun 2026 18:52:32 +0100 Subject: [PATCH] Close SSE connection nicely on navigating away from the page --- core/constants.py | 2 +- templates/about.html | 2 +- templates/add_spot.html | 4 ++-- templates/alerts.html | 4 ++-- templates/bands.html | 6 +++--- templates/base.html | 8 ++++---- templates/conditions.html | 4 ++-- templates/map.html | 6 +++--- templates/spots.html | 6 +++--- templates/status.html | 4 ++-- webassets/js/spots.js | 8 ++++++++ 11 files changed, 31 insertions(+), 23 deletions(-) diff --git a/core/constants.py b/core/constants.py index cbe83b5..3d6a47c 100644 --- a/core/constants.py +++ b/core/constants.py @@ -4,7 +4,7 @@ from data.sig import SIG # General software SOFTWARE_NAME = "Spothole by M0TRT" -SOFTWARE_VERSION = "1.3" +SOFTWARE_VERSION = "1.4-pre" # HTTP headers used for spot providers that use HTTP HTTP_HEADERS = {"User-Agent": SOFTWARE_NAME + ", v" + SOFTWARE_VERSION + " (operated by " + SERVER_OWNER_CALLSIGN + ")"} diff --git a/templates/about.html b/templates/about.html index 7dac68d..6b53a7d 100644 --- a/templates/about.html +++ b/templates/about.html @@ -69,7 +69,7 @@

This software is dedicated to the memory of Tom G1PJB, SK, a friend and colleague who sadly passed away around the time I started writing it in Autumn 2025. I was looking forward to showing it to you when it was done.

- + {% end %} \ No newline at end of file diff --git a/templates/add_spot.html b/templates/add_spot.html index 80fdc18..74870fd 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -69,8 +69,8 @@ - - + + {% end %} \ No newline at end of file diff --git a/templates/alerts.html b/templates/alerts.html index c9dc8ed..4ddb4bb 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -70,8 +70,8 @@ - - + + {% end %} \ No newline at end of file diff --git a/templates/bands.html b/templates/bands.html index a672224..42d8119 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,9 +76,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index a874d0a..e25c601 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -19,9 +19,9 @@ integrity="sha384-L1eE4eD41kpBIWe2I0eHy+GnEUC4RIpcvibVW2JCminuPlTl+2Bc528iPdVMg5Dn" crossorigin="anonymous"> - - - + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 660c3f8..368c6f9 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -271,8 +271,8 @@
- - + + diff --git a/templates/map.html b/templates/map.html index 334d8d5..55f85ef 100644 --- a/templates/map.html +++ b/templates/map.html @@ -94,9 +94,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/spots.html b/templates/spots.html index 38cd070..d98b3ff 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -104,9 +104,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/status.html b/templates/status.html index a38542c..75320cd 100644 --- a/templates/status.html +++ b/templates/status.html @@ -59,8 +59,8 @@ - - + + diff --git a/webassets/js/spots.js b/webassets/js/spots.js index 104ce87..d1d2ddb 100644 --- a/webassets/js/spots.js +++ b/webassets/js/spots.js @@ -4,6 +4,14 @@ let restartSSEOnErrorTimeoutId; // Table row count, to alternate shading let rowCount = 0; +// Set up a listener to close the SSE connection nicely when we navigate away from the page, to prevent console errors +// and keep things nice and tidy for the server. +window.addEventListener('beforeunload', function() { + if (evtSource != null) { + evtSource.close(); + } +}); + // Load spots and populate the table. function loadSpots() { // If we have an ongoing SSE connection, stop it so it doesn't interfere with our reload