Skip to content

Commit

Permalink
Merge pull request #9 from hft-app/ljans
Browse files Browse the repository at this point in the history
Await data on initial start
  • Loading branch information
ljans committed Mar 13, 2024
2 parents c6f4fd8 + 1f26a26 commit 5ae1a34
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions scripts/handler/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ class CoreHandler {
// Process request
async process(request) {

// Auto refresh
const checked = await this.controller.idb.state.get('checked');
if(!checked || new Date() - checked > 15*60*1000) {
await this.controller.idb.state.put(new Date(), 'checked');

// Only refresh when online, wait for data on initial refresh
if(navigator.onLine) {
if(!checked) await controller.refresh();
else controller.refresh();
}
}

// Load page and module
const page = request.params[1];
const module = this.modules[page];
Expand All @@ -53,13 +65,6 @@ class CoreHandler {
// Remember visitable page
if(page != 'error') await this.controller.idb.state.put(page, 'page');

// Auto refresh
const checked = await this.controller.idb.state.get('checked');
if(!checked || new Date() - checked > 15*60*1000) {
await this.controller.idb.state.put(new Date(), 'checked');
if(navigator.onLine) controller.refresh();
}

// Render template
return await this.controller.renderTemplate(page, data);
}
Expand Down

0 comments on commit 5ae1a34

Please sign in to comment.