diff --git a/plugin/actions/PetrolAction.js b/plugin/actions/PetrolAction.js index 5c0a2fa..9915194 100644 --- a/plugin/actions/PetrolAction.js +++ b/plugin/actions/PetrolAction.js @@ -9,6 +9,7 @@ class PetrolAction extends ActionBase { }; this.previousPrice = null; this.lastDelta = null; + this.lastRised = null; this.$UD.onDidReceiveSettings(jsn => { if (jsn.context !== this.context) return; @@ -16,6 +17,7 @@ class PetrolAction extends ActionBase { this.config = Object.assign(this.config, s); if (s.previousPrice != null) this.previousPrice = s.previousPrice; 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) { const delta = current - this.previousPrice; if (delta !== 0) this.lastDelta = delta; + if (delta > 0) this.lastRised = current; } this.previousPrice = current; 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 { this.renderButton('N/A', null); } @@ -74,24 +77,42 @@ class PetrolAction extends ActionBase { renderButton(priceText, delta) { const { canvas, ctx } = this.createCanvas(); - // Fuel type — top, light blue - ctx.fillStyle = '#7ec8e3'; - ctx.font = 'bold 28px "Source Han Sans SC"'; - ctx.fillText(this.config.fuelType, 98, 45); + if (this.lastRised !== null) { + const lastRised = this.lastRised; + // Compact layout with lastRised + 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; - ctx.fillStyle = '#f0c040'; - ctx.font = `bold ${fSize}px "Source Han Sans SC"`; - ctx.fillText(priceText, 98, 105); + const fSize = priceText.length > 6 ? 38 : 46; + ctx.fillStyle = '#f0c040'; + ctx.font = `bold ${fSize}px "Source Han Sans SC"`; + ctx.fillText(priceText, 98, 95); - // Delta — bottom - 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); + ctx.fillStyle = '#888888'; + ctx.font = '22px "Source Han Sans SC"'; + ctx.fillText('Last Rised', 98, 143); + ctx.fillStyle = '#ff6b6b'; + ctx.font = 'bold 30px "Source Han Sans SC"'; + ctx.fillText(`${lastRised.toFixed(3)}€`, 98, 168); + } 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);