mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 15:49:31 -07:00
removed existing auto-reload
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { json } from './modules/utils/fetch.mjs';
|
import { json } from './modules/utils/fetch.mjs';
|
||||||
import noSleep from './modules/utils/nosleep.mjs';
|
import noSleep from './modules/utils/nosleep.mjs';
|
||||||
import {
|
import {
|
||||||
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
|
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived,
|
||||||
} from './modules/navigation.mjs';
|
} from './modules/navigation.mjs';
|
||||||
import { round2 } from './modules/utils/units.mjs';
|
import { round2 } from './modules/utils/units.mjs';
|
||||||
import { parseQueryString } from './modules/share.mjs';
|
import { parseQueryString } from './modules/share.mjs';
|
||||||
@@ -32,8 +32,6 @@ const init = () => {
|
|||||||
e.target.select();
|
e.target.select();
|
||||||
});
|
});
|
||||||
|
|
||||||
registerRefreshData(loadData);
|
|
||||||
|
|
||||||
document.querySelector('#NavigateMenu').addEventListener('click', btnNavigateMenuClick);
|
document.querySelector('#NavigateMenu').addEventListener('click', btnNavigateMenuClick);
|
||||||
document.querySelector('#NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
|
document.querySelector('#NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
|
||||||
document.querySelector('#NavigateNext').addEventListener('click', btnNavigateNextClick);
|
document.querySelector('#NavigateNext').addEventListener('click', btnNavigateNextClick);
|
||||||
@@ -249,7 +247,6 @@ const loadData = (_latLon, haveDataCallback) => {
|
|||||||
if (!latLon) return;
|
if (!latLon) return;
|
||||||
|
|
||||||
document.querySelector(TXT_ADDRESS_SELECTOR).blur();
|
document.querySelector(TXT_ADDRESS_SELECTOR).blur();
|
||||||
stopAutoRefreshTimer();
|
|
||||||
latLonReceived(latLon, haveDataCallback);
|
latLonReceived(latLon, haveDataCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,26 +15,11 @@ let playing = false;
|
|||||||
let progress;
|
let progress;
|
||||||
const weatherParameters = {};
|
const weatherParameters = {};
|
||||||
|
|
||||||
// auto refresh
|
|
||||||
const AUTO_REFRESH_INTERVAL_MS = 500;
|
|
||||||
const AUTO_REFRESH_TIME_MS = 600_000; // 10 min.
|
|
||||||
const CHK_AUTO_REFRESH_SELECTOR = '#chkAutoRefresh';
|
|
||||||
let AutoRefreshIntervalId = null;
|
|
||||||
let AutoRefreshCountMs = 0;
|
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
// set up resize handler
|
// set up resize handler
|
||||||
window.addEventListener('resize', resize);
|
window.addEventListener('resize', resize);
|
||||||
resize();
|
resize();
|
||||||
|
|
||||||
// auto refresh
|
|
||||||
const autoRefresh = localStorage.getItem('autoRefresh');
|
|
||||||
if (!autoRefresh || autoRefresh === 'true') {
|
|
||||||
document.querySelector(CHK_AUTO_REFRESH_SELECTOR).checked = true;
|
|
||||||
} else {
|
|
||||||
document.querySelector(CHK_AUTO_REFRESH_SELECTOR).checked = false;
|
|
||||||
}
|
|
||||||
document.querySelector(CHK_AUTO_REFRESH_SELECTOR).addEventListener('change', autoRefreshChange);
|
|
||||||
generateCheckboxes();
|
generateCheckboxes();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,12 +108,6 @@ const updateStatus = (value) => {
|
|||||||
if (isPlaying() && value.id === firstDisplayIndex && value.status === STATUS.loaded) {
|
if (isPlaying() && value.id === firstDisplayIndex && value.status === STATUS.loaded) {
|
||||||
navTo(msg.command.firstFrame);
|
navTo(msg.command.firstFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send loaded messaged to parent
|
|
||||||
if (countLoadedDisplays() < displays.length) return;
|
|
||||||
|
|
||||||
// everything loaded, set timestamps
|
|
||||||
AssignLastUpdate(new Date());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// note: a display that is "still waiting"/"retrying" is considered loaded intentionally
|
// note: a display that is "still waiting"/"retrying" is considered loaded intentionally
|
||||||
@@ -202,8 +181,6 @@ const loadDisplay = (direction) => {
|
|||||||
idx = wrap(curIdx + (i + 1) * direction, totalDisplays);
|
idx = wrap(curIdx + (i + 1) * direction, totalDisplays);
|
||||||
if (displays[idx].status === STATUS.loaded && displays[idx].timing.totalScreens > 0) break;
|
if (displays[idx].status === STATUS.loaded && displays[idx].timing.totalScreens > 0) break;
|
||||||
}
|
}
|
||||||
// if new display index is less than current display a wrap occurred, test for reload timeout
|
|
||||||
if (idx <= curIdx && refreshCheck()) return;
|
|
||||||
const newDisplay = displays[idx];
|
const newDisplay = displays[idx];
|
||||||
// hide all displays
|
// hide all displays
|
||||||
hideAllCanvases();
|
hideAllCanvases();
|
||||||
@@ -320,83 +297,8 @@ const populateWeatherParameters = (params) => {
|
|||||||
document.querySelector('#spanZoneId').innerHTML = params.zoneId;
|
document.querySelector('#spanZoneId').innerHTML = params.zoneId;
|
||||||
};
|
};
|
||||||
|
|
||||||
const autoRefreshChange = (e) => {
|
|
||||||
const { checked } = e.target;
|
|
||||||
|
|
||||||
if (checked) {
|
|
||||||
startAutoRefreshTimer();
|
|
||||||
} else {
|
|
||||||
stopAutoRefreshTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem('autoRefresh', checked);
|
|
||||||
};
|
|
||||||
|
|
||||||
const AssignLastUpdate = (date) => {
|
|
||||||
if (date) {
|
|
||||||
document.querySelector('#spanLastRefresh').innerHTML = date.toLocaleString('en-US', {
|
|
||||||
weekday: 'short', month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short',
|
|
||||||
});
|
|
||||||
if (document.querySelector(CHK_AUTO_REFRESH_SELECTOR).checked) startAutoRefreshTimer();
|
|
||||||
} else {
|
|
||||||
document.querySelector('#spanLastRefresh').innerHTML = '(none)';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const latLonReceived = (data, haveDataCallback) => {
|
const latLonReceived = (data, haveDataCallback) => {
|
||||||
getWeather(data, haveDataCallback);
|
getWeather(data, haveDataCallback);
|
||||||
AssignLastUpdate(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const startAutoRefreshTimer = () => {
|
|
||||||
// Ensure that any previous timer has already stopped.
|
|
||||||
// check if timer is running
|
|
||||||
if (AutoRefreshIntervalId) return;
|
|
||||||
|
|
||||||
// Reset the time elapsed.
|
|
||||||
AutoRefreshCountMs = 0;
|
|
||||||
|
|
||||||
const AutoRefreshTimer = () => {
|
|
||||||
// Increment the total time elapsed.
|
|
||||||
AutoRefreshCountMs += AUTO_REFRESH_INTERVAL_MS;
|
|
||||||
|
|
||||||
// Display the count down.
|
|
||||||
let RemainingMs = (AUTO_REFRESH_TIME_MS - AutoRefreshCountMs);
|
|
||||||
if (RemainingMs < 0) {
|
|
||||||
RemainingMs = 0;
|
|
||||||
}
|
|
||||||
const dt = new Date(RemainingMs);
|
|
||||||
document.querySelector('#spanRefreshCountDown').innerHTML = `${dt.getMinutes().toString().padStart(2, '0')}:${dt.getSeconds().toString().padStart(2, '0')}`;
|
|
||||||
|
|
||||||
// Time has elapsed.
|
|
||||||
if (AutoRefreshCountMs >= AUTO_REFRESH_TIME_MS && !isPlaying()) loadTwcData();
|
|
||||||
};
|
|
||||||
AutoRefreshIntervalId = window.setInterval(AutoRefreshTimer, AUTO_REFRESH_INTERVAL_MS);
|
|
||||||
AutoRefreshTimer();
|
|
||||||
};
|
|
||||||
const stopAutoRefreshTimer = () => {
|
|
||||||
if (AutoRefreshIntervalId) {
|
|
||||||
window.clearInterval(AutoRefreshIntervalId);
|
|
||||||
document.querySelector('#spanRefreshCountDown').innerHTML = '--:--';
|
|
||||||
AutoRefreshIntervalId = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const refreshCheck = () => {
|
|
||||||
// Time has elapsed.
|
|
||||||
if (AutoRefreshCountMs >= AUTO_REFRESH_TIME_MS && isPlaying()) {
|
|
||||||
loadTwcData();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadTwcData = () => {
|
|
||||||
if (loadTwcData.callback) loadTwcData.callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
const registerRefreshData = (callback) => {
|
|
||||||
loadTwcData.callback = callback;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const timeZone = () => weatherParameters.timeZone;
|
const timeZone = () => weatherParameters.timeZone;
|
||||||
@@ -414,7 +316,5 @@ export {
|
|||||||
msg,
|
msg,
|
||||||
message,
|
message,
|
||||||
latLonReceived,
|
latLonReceived,
|
||||||
stopAutoRefreshTimer,
|
|
||||||
registerRefreshData,
|
|
||||||
timeZone,
|
timeZone,
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -745,8 +745,7 @@ body {
|
|||||||
>.heading,
|
>.heading,
|
||||||
#enabledDisplays,
|
#enabledDisplays,
|
||||||
#settings,
|
#settings,
|
||||||
#divInfo,
|
#divInfo {
|
||||||
#divRefresh {
|
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,11 +163,6 @@
|
|||||||
Zone Id: <span id="spanZoneId"></span><br />
|
Zone Id: <span id="spanZoneId"></span><br />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="divRefresh">
|
|
||||||
Last Update: <span id="spanLastRefresh">(None)</span><br />
|
|
||||||
<input id="chkAutoRefresh" name="chkAutoRefresh" type="checkbox" /><label id="lblRefreshCountDown" for="chkAutoRefresh">Auto Refresh: <span id="spanRefreshCountDown">--:--</span></label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -52,11 +52,7 @@
|
|||||||
"[html]": {
|
"[html]": {
|
||||||
"editor.defaultFormatter": "j69.ejs-beautify"
|
"editor.defaultFormatter": "j69.ejs-beautify"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {},
|
||||||
"**/node_modules": true,
|
|
||||||
"**/debug.log": true,
|
|
||||||
"server/scripts/custom.js": true
|
|
||||||
},
|
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
|
|||||||
Reference in New Issue
Block a user