Fixed memory leak from multiple intervals.

Tutorial on first clock face causes multiple intervals to be created. Must be fixed to stop extra ticking.
pull/454/head
Ephraim Amiel Yusi 2020-05-28 00:42:53 +10:00 committed by GitHub
parent 52d2fa2efd
commit 194ed062e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -93,20 +93,21 @@ drawBattery();
var secondInterval = setInterval(()=>{
drawTimeDate();
}, 60000);
}, 15000);
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
if (secondInterval) clearInterval(secondInterval);
secondInterval = undefined;
if (on) {
secondInterval = setInterval(()=>{
drawTimeDate();
}, 15000);
//Screen on
setInterval(drawTimeDate, 60000);
drawBPM(HRMstate);
drawTimeDate();
drawBattery();
} else {
//Screen off
clearInterval(secondInterval);
}
});