Skip to content

Commit 5ae1a34

Browse files
authored
Merge pull request #9 from hft-app/ljans
Await data on initial start
2 parents c6f4fd8 + 1f26a26 commit 5ae1a34

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

scripts/handler/core.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ class CoreHandler {
2727
// Process request
2828
async process(request) {
2929

30+
// Auto refresh
31+
const checked = await this.controller.idb.state.get('checked');
32+
if(!checked || new Date() - checked > 15*60*1000) {
33+
await this.controller.idb.state.put(new Date(), 'checked');
34+
35+
// Only refresh when online, wait for data on initial refresh
36+
if(navigator.onLine) {
37+
if(!checked) await controller.refresh();
38+
else controller.refresh();
39+
}
40+
}
41+
3042
// Load page and module
3143
const page = request.params[1];
3244
const module = this.modules[page];
@@ -53,13 +65,6 @@ class CoreHandler {
5365
// Remember visitable page
5466
if(page != 'error') await this.controller.idb.state.put(page, 'page');
5567

56-
// Auto refresh
57-
const checked = await this.controller.idb.state.get('checked');
58-
if(!checked || new Date() - checked > 15*60*1000) {
59-
await this.controller.idb.state.put(new Date(), 'checked');
60-
if(navigator.onLine) controller.refresh();
61-
}
62-
6368
// Render template
6469
return await this.controller.renderTemplate(page, data);
6570
}

0 commit comments

Comments
 (0)