From a6defdb54eb0ff3d0d88e3cc74f9f303479ea489 Mon Sep 17 00:00:00 2001 From: Sakooooo <78461130+Sakooooo@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:29:33 +0400 Subject: [PATCH] (config) ags: fix battery icon --- config/ags/config.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/config/ags/config.js b/config/ags/config.js index a8717c65..f5757edb 100644 --- a/config/ags/config.js +++ b/config/ags/config.js @@ -161,22 +161,38 @@ function Volume() { function BatteryLabel() { - const value = battery.bind("percent").as(p => p > 0 ? p / 100 : 0) - const icon = battery.bind("percent").as(p => - `battery-level-${Math.floor(p / 10) * 10}-symbolic`) + const icons = { + 100: "full", + 50: "good", + 25: "low", + 0: "empty", + }; + const value = battery.bind("percent").as(p => p > 0 ? p / 100 : 0); + // const icon = battery.bind("percent").as(p => + // `battery-level-${Math.floor(p / 10) * 10}-symbolic`) - const percent = battery.bind("percent").as(x => x.toString()) + "%" + const percent = battery.bind("percent").as(x => x.toString()) + "%"; + + function getIcon() { + const icon = [100, 50, 25, 0].find(threshold => threshold <= battery.percent); + + return `battery-${icons[icon]}-symbolic`; + } + + const icon = Widget.Icon({ + icon: Utils.watch(getIcon(), battery, getIcon), + }); return Widget.Box({ class_name: "battery", visible: battery.bind("available"), children: [ - Widget.Icon({ icon }), + icon, Widget.Label({ label: battery.bind('percent').as(x => x.toString()), }) ], - }) + }); }