-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
84 lines (76 loc) · 2.43 KB
/
Copy pathapp.js
File metadata and controls
84 lines (76 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const widgets = [
themeWidget,
greetingWidget,
clockWidget,
weatherWidget,
calendarWidget,
tasksWidget,
statusGridWidget,
connectivityWidget,
updateWidget,
settingsWidget,
versionWidget,
];
let configuredRefreshMinutes = 15;
let activeRefreshPolicy = DEFAULT_REFRESH_POLICY;
let configuredRefreshTimer = null;
let refreshScheduleGeneration = 0;
function configuredRefreshWidgets() {
return widgets.filter((widget) => widget.usesConfiguredRefresh);
}
function scheduleConfiguredRefresh() {
refreshScheduleGeneration += 1;
const generation = refreshScheduleGeneration;
if (configuredRefreshTimer) clearTimeout(configuredRefreshTimer);
const delay = millisecondsUntilNextRefresh(
new Date(),
configuredRefreshMinutes,
activeRefreshPolicy,
);
configuredRefreshTimer = setTimeout(async () => {
if (generation !== refreshScheduleGeneration) return;
await Promise.allSettled(configuredRefreshWidgets().map((widget) => widget.update(true)));
if (generation === refreshScheduleGeneration) scheduleConfiguredRefresh();
}, delay);
}
function applyLiveConfigPatch(patch) {
const nextStatusConfig = patch && patch.statusColors
? validateStatusTierConfig(patch.statusColors)
: getBundledStatusTierConfig();
const nextRefreshPolicy = patch && patch.refreshPolicy
? validateRefreshPolicy(patch.refreshPolicy)
: getBundledRefreshPolicy();
applyStatusTierConfig(nextStatusConfig);
activeRefreshPolicy = nextRefreshPolicy;
scheduleConfiguredRefresh();
if (statusGridWidget.el) statusGridWidget.update();
if (connectivityWidget.el) connectivityWidget.update();
return true;
}
async function startWidgets() {
await Promise.all([
loadStatusTierConfig(),
loadRefreshPolicy(),
]);
activeRefreshPolicy = getBundledRefreshPolicy();
try {
const response = await fetch('/api/config', { cache: 'no-store' });
const config = await response.json();
if (Number.isInteger(config.refresh_minutes)) {
configuredRefreshMinutes = config.refresh_minutes;
}
} catch {}
widgets.forEach((widget) => {
widget.init();
if (widget.interval && !widget.usesConfiguredRefresh) {
setInterval(() => widget.update(), widget.interval);
}
});
scheduleConfiguredRefresh();
}
startWidgets().then(() => {
if (window.panelApp) window.panelApp.reportRuntimeReady();
});
setInterval(() => {
widgets.forEach((widget) => widget.refreshUpdated && widget.refreshUpdated());
}, 30000);