petrol show latest up price

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-04-10 17:11:35 +02:00
parent 9847b2c087
commit d4848d3700
+38 -17
View File
@@ -9,6 +9,7 @@ class PetrolAction extends ActionBase {
}; };
this.previousPrice = null; this.previousPrice = null;
this.lastDelta = null; this.lastDelta = null;
this.lastRised = null;
this.$UD.onDidReceiveSettings(jsn => { this.$UD.onDidReceiveSettings(jsn => {
if (jsn.context !== this.context) return; if (jsn.context !== this.context) return;
@@ -16,6 +17,7 @@ class PetrolAction extends ActionBase {
this.config = Object.assign(this.config, s); this.config = Object.assign(this.config, s);
if (s.previousPrice != null) this.previousPrice = s.previousPrice; if (s.previousPrice != null) this.previousPrice = s.previousPrice;
if (s.lastDelta != null) this.lastDelta = s.lastDelta; if (s.lastDelta != null) this.lastDelta = s.lastDelta;
if (s.lastRised != null) this.lastRised = s.lastRised;
}); });
} }
@@ -46,10 +48,11 @@ class PetrolAction extends ActionBase {
if (this.previousPrice !== null) { if (this.previousPrice !== null) {
const delta = current - this.previousPrice; const delta = current - this.previousPrice;
if (delta !== 0) this.lastDelta = delta; if (delta !== 0) this.lastDelta = delta;
if (delta > 0) this.lastRised = current;
} }
this.previousPrice = current; this.previousPrice = current;
this.renderButton(`${parseFloat(raw).toFixed(3)}`, this.lastDelta); this.renderButton(`${parseFloat(raw).toFixed(3)}`, this.lastDelta);
this.$UD.setSettings({ ...this.config, previousPrice: this.previousPrice, lastDelta: this.lastDelta }, this.context); this.$UD.setSettings({ ...this.config, previousPrice: this.previousPrice, lastDelta: this.lastDelta, lastRised: this.lastRised }, this.context);
} else { } else {
this.renderButton('N/A', null); this.renderButton('N/A', null);
} }
@@ -74,24 +77,42 @@ class PetrolAction extends ActionBase {
renderButton(priceText, delta) { renderButton(priceText, delta) {
const { canvas, ctx } = this.createCanvas(); const { canvas, ctx } = this.createCanvas();
// Fuel type — top, light blue if (this.lastRised !== null) {
ctx.fillStyle = '#7ec8e3'; const lastRised = this.lastRised;
ctx.font = 'bold 28px "Source Han Sans SC"'; // Compact layout with lastRised
ctx.fillText(this.config.fuelType, 98, 45); ctx.fillStyle = '#7ec8e3';
ctx.font = 'bold 24px "Source Han Sans SC"';
ctx.fillText(this.config.fuelType, 98, 28);
// Price — middle, yellow const fSize = priceText.length > 6 ? 38 : 46;
const fSize = priceText.length > 6 ? 38 : 46; ctx.fillStyle = '#f0c040';
ctx.fillStyle = '#f0c040'; ctx.font = `bold ${fSize}px "Source Han Sans SC"`;
ctx.font = `bold ${fSize}px "Source Han Sans SC"`; ctx.fillText(priceText, 98, 95);
ctx.fillText(priceText, 98, 105);
// Delta — bottom ctx.fillStyle = '#888888';
if (delta !== null) { ctx.font = '22px "Source Han Sans SC"';
const arrow = delta > 0 ? '▲' : '▼'; ctx.fillText('Last Rised', 98, 143);
const color = delta > 0 ? '#ff6b6b' : '#6bff6b'; ctx.fillStyle = '#ff6b6b';
ctx.fillStyle = color; ctx.font = 'bold 30px "Source Han Sans SC"';
ctx.font = '24px "Source Han Sans SC"'; ctx.fillText(`${lastRised.toFixed(3)}`, 98, 168);
ctx.fillText(`${arrow} ${Math.abs(delta).toFixed(3)}`, 98, 142); } else {
// Original layout
ctx.fillStyle = '#7ec8e3';
ctx.font = 'bold 28px "Source Han Sans SC"';
ctx.fillText(this.config.fuelType, 98, 45);
const fSize = priceText.length > 6 ? 38 : 46;
ctx.fillStyle = '#f0c040';
ctx.font = `bold ${fSize}px "Source Han Sans SC"`;
ctx.fillText(priceText, 98, 105);
if (delta !== null) {
const arrow = delta > 0 ? '▲' : '▼';
const color = delta > 0 ? '#ff6b6b' : '#6bff6b';
ctx.fillStyle = color;
ctx.font = '24px "Source Han Sans SC"';
ctx.fillText(`${arrow} ${Math.abs(delta).toFixed(3)}`, 98, 142);
}
} }
this.setIcon(canvas); this.setIcon(canvas);