fix: avoid calling weather.get twice in draw loop
parent
17464943fd
commit
9ed08a1542
|
|
@ -42,8 +42,11 @@ class TimeCalClock{
|
||||||
|
|
||||||
// X coord to center date and time text at
|
// X coord to center date and time text at
|
||||||
this.dtCenterX = Bangle.appRect.w/2;
|
this.dtCenterX = Bangle.appRect.w/2;
|
||||||
this.hasWeather = this.settings().showWeather && require('weather') && require('weather').get();
|
this.weather = undefined;
|
||||||
if(this.hasWeather){
|
if(this.settings().showWeather && require('weather')){
|
||||||
|
this.weather = require('weather').get();
|
||||||
|
}
|
||||||
|
if(this.weather){
|
||||||
this.dtCenterX =2*Bangle.appRect.w/3;
|
this.dtCenterX =2*Bangle.appRect.w/3;
|
||||||
}
|
}
|
||||||
this.nrgb = [g.theme.fg, "#E00", "#0E0", "#00E"]; //fg, r ,g , b
|
this.nrgb = [g.theme.fg, "#E00", "#0E0", "#00E"]; //fg, r ,g , b
|
||||||
|
|
@ -83,9 +86,11 @@ class TimeCalClock{
|
||||||
// require("weather").get = undefined;
|
// require("weather").get = undefined;
|
||||||
|
|
||||||
const d = this.date ? this.date : new Date();
|
const d = this.date ? this.date : new Date();
|
||||||
this.hasWeather = this.settings().showWeather && require('weather') && require('weather').get();
|
if (this.settings().showWeather && require('weather')){
|
||||||
|
this.weather = require('weather').get();
|
||||||
|
}
|
||||||
const prevCenterX = this.dtCenterX;
|
const prevCenterX = this.dtCenterX;
|
||||||
if(this.hasWeather){
|
if(this.weather){
|
||||||
this.dtCenterX = 2 * Bangle.appRect.w / 3;
|
this.dtCenterX = 2 * Bangle.appRect.w / 3;
|
||||||
} else {
|
} else {
|
||||||
this.dtCenterX = Bangle.appRect.w / 2;
|
this.dtCenterX = Bangle.appRect.w / 2;
|
||||||
|
|
@ -98,14 +103,13 @@ class TimeCalClock{
|
||||||
if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset())
|
if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset())
|
||||||
this.drawDateAndCal();
|
this.drawDateAndCal();
|
||||||
|
|
||||||
if(this.hasWeather){
|
if(this.weather){
|
||||||
this.drawWeather();
|
this.drawWeather();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawWeather() {
|
drawWeather() {
|
||||||
const weather = require('weather');
|
const curr = this.weather;
|
||||||
const curr = weather.get();
|
|
||||||
const temp = require("locale").temp(curr.temp-273.15).match(/^(\D*\d*)(.*)$/)[0];
|
const temp = require("locale").temp(curr.temp-273.15).match(/^(\D*\d*)(.*)$/)[0];
|
||||||
const iconRadius = 20;
|
const iconRadius = 20;
|
||||||
const widgetHeight = 24;
|
const widgetHeight = 24;
|
||||||
|
|
@ -115,7 +119,7 @@ class TimeCalClock{
|
||||||
Bangle.appRect.w/3,
|
Bangle.appRect.w/3,
|
||||||
Bangle.appRect.y + widgetHeight + iconRadius
|
Bangle.appRect.y + widgetHeight + iconRadius
|
||||||
);
|
);
|
||||||
weather.drawIcon(curr, Bangle.appRect.x + widgetHeight, Bangle.appRect.y + widgetHeight - 4, iconRadius);
|
(require('weather')).drawIcon(curr, Bangle.appRect.x + widgetHeight, Bangle.appRect.y + widgetHeight - 4, iconRadius);
|
||||||
g
|
g
|
||||||
.setFontAlign(0, -1)
|
.setFontAlign(0, -1)
|
||||||
.setFont('6x8', 2)
|
.setFont('6x8', 2)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue