diff --git a/src/js/Connection.js b/src/js/Connection.js index c16fb09..f41e7d1 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -77,6 +77,10 @@ class Connection { // update ui GlobalState.connection = null; + // clear previous connection timers + clearInterval(GlobalState.batteryPercentageInterval); + GlobalState.batteryPercentageInterval = null; + } static async onConnected() { @@ -155,7 +159,7 @@ class Connection { await this.updateBatteryPercentage(); // auto update battery percentage once per minute - setInterval(async () => { + GlobalState.batteryPercentageInterval = setInterval(async () => { await this.updateBatteryPercentage(); }, 60000); diff --git a/src/js/GlobalState.js b/src/js/GlobalState.js index 7d1fa3d..b715c74 100644 --- a/src/js/GlobalState.js +++ b/src/js/GlobalState.js @@ -6,6 +6,7 @@ const globalState = reactive({ isDatabaseReady: false, selfInfo: null, batteryPercentage: null, + batteryPercentageInterval: null, contacts: [], channels: [ {