Skip to content

Commit

Permalink
fix infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingeek committed Feb 19, 2024
1 parent 64064f1 commit 9405bf4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.19.30] - 2024-02-19

### Fixed

- Le cache du Kp causait une loupe infinie sous Safari (changement CORS du serveur NOAA)

## [1.19.29] - 2024-02-19

### Fixed
Expand Down
1 change: 1 addition & 0 deletions assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lang": "fr",
"dir": "ltr",
"scope": "/lido-online/",
"Scope": "/lido-online/",
"start_url": "./index.html",
"launch_handler": {
"client_mode": ["navigate-existing", "auto"]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lido-svelte",
"version": "1.19.29",
"version": "1.19.30",
"type": "module",
"config": {
"AIRAC": "2401"
Expand Down
37 changes: 21 additions & 16 deletions src/components/KpUpdater.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@
}
};
export const noaaKp = writable();
const setNoaaKp = (data) => {
try {
const timetable = [];
for (let i=data.length - 1; i>=1; i--){
const [d, k] = data[i];
const t = Date.parse(d.replace(' ', 'T') + 'Z'); // Safari needs the T
timetable.push([t, parseFloat(k)])
}
if (timetable.length > 0) {
noaaKp.set(timetable);
}
} catch (error) {
console.error('kp store update error', error);
}
};
const fetchNoaaKpAndSet = async () => {
return fetch('CONF_NOAA_KP_JSON')
.then(response => response.json())
.then(data => {
try {
const timetable = [];
for (let i=data.length - 1; i>=1; i--){
const [d, k] = data[i];
const t = Date.parse(d.replace(' ', 'T') + 'Z'); // Safari needs the T
timetable.push([t, parseFloat(k)])
}
if (timetable.length > 0) {
noaaKp.set(timetable);
}
} catch (error) {
console.error('kp store update error', error);
}
})
.then(data => setNoaaKp(data))
.catch(function(error) {
console.log('Could not update Kp store', error);
});
Expand Down Expand Up @@ -162,7 +163,11 @@
const {updatedURL} = event.data.payload;
if (updatedURL === 'CONF_NOAA_KP_JSON') {
//console.log('loading noaa kp store (sw cache updated)');
fetchNoaaKpAndSet();
navigator.serviceWorker.removeEventListener('message', predictedKpUpdated);
fetch('CONF_NOAA_KP_JSON')
.then(response => response.json())
.then(data => setNoaaKp(data))
.finally(() => setTimeout( () => navigator.serviceWorker.addEventListener('message', predictedKpUpdated), 5000));
}
}
};
Expand Down

0 comments on commit 9405bf4

Please sign in to comment.