From 126f2b75351d32822cc750cf4e8ec3ebe30019c1 Mon Sep 17 00:00:00 2001 From: matavach Date: Wed, 31 Jul 2024 23:20:34 -0500 Subject: [PATCH] added charging detection to battery icon (#53) --- modules/bar/battery/index.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/bar/battery/index.ts b/modules/bar/battery/index.ts index 13d1586..8dba0e4 100644 --- a/modules/bar/battery/index.ts +++ b/modules/bar/battery/index.ts @@ -8,11 +8,14 @@ const { label: show_label } = options.bar.battery; const BatteryLabel = () => { const isVis = Variable(battery.available); - - const icon = () => - battery - .bind("percent") - .as((p) => `battery-level-${Math.floor(p / 10) * 10}-symbolic`); + + const batIcon = Utils.merge([battery.bind("percent"), battery.bind("charging"), battery.bind("charged")], + (batPercent: number, batCharging, batCharged) => { + if(batCharged) + return `battery-level-100-charged-symbolic`; + else + return `battery-level-${Math.floor(batPercent / 10) * 10}${batCharging ? '-charging' : ''}-symbolic`; + }); battery.connect("changed", ({ available }) => { isVis.value = available; @@ -49,7 +52,7 @@ const BatteryLabel = () => { return [ Widget.Icon({ class_name: "bar-button-icon battery", - icon: icon() + icon: batIcon }), Widget.Label({ class_name: "bar-button-label battery", @@ -57,7 +60,7 @@ const BatteryLabel = () => { }), ]; } else if (batAvail && !showLabel) { - return [Widget.Icon({ icon: icon() })]; + return [Widget.Icon({ icon: batIcon })]; } else { return []; }