Skip to content

Commit

Permalink
clear browser console at midnight
Browse files Browse the repository at this point in the history
  • Loading branch information
benderl committed Nov 19, 2024
1 parent 3756889 commit 92d072f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/modules/display_themes/cards/source/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default {
],
mqttStore: useMqttStore(),
chartInterval: "",
clearConsoleHandler: undefined
};
},
computed: {
Expand Down Expand Up @@ -102,14 +103,38 @@ export default {
this.doSubscribe(this.mqttTopicsToSubscribe);
// timer for chart data
this.chartInterval = setInterval(this.mqttStore.updateChartData, 5000);
// schedule first clearance of browser console at midnight
const now = new Date();
const midnight = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1,
0,
0,
0,
0,
);
const timeout = midnight.getTime() - now.getTime();
console.debug("clear console in", timeout, "ms");
this.clearConsoleHandler = setTimeout(() => this.clearConsole(), timeout);
},
beforeUnmount() {
// unsubscribe our topics
this.doUnsubscribe(this.mqttTopicsToSubscribe);
// clear timer for chart data
clearInterval(this.chartInterval);
// clear timer for console clearing
clearTimeout(this.clearConsoleHandler);
},
methods: {
/**
* clears the browser console and reschedules this task after 24 hours
*/
clearConsole() {
console.clear();
console.debug("console cleared at", new Date());
this.clearConsoleHandler = setTimeout(() => this.clearConsole(), 24 * 60 * 60 * 1000);
},
/**
* Establishes a connection to the configured broker
*/
Expand Down

0 comments on commit 92d072f

Please sign in to comment.