Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
2.24k stars 117 forks source link

Battery Service is not working #569

Closed fe2-Nyxar closed 1 month ago

fe2-Nyxar commented 1 month ago

when i log the battery:

Battery {
    "available": false,
    "percent": -1,
    "charging": false,
    "charged": false,
    "icon-name": "battery-missing-symbolic",
    "time-remaining": 0,
    "energy": 0,
    "energy-full": 0,
    "energy-rate": 0
}

and when i log upower:

 upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               HP
  model:                Primary
  serial:               SerialNumber
  power supply:         yes
  updated:              dim. 15 sept. 2024 18:22:15 (10 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              25,458 Wh
    energy-empty:        0 Wh
    energy-full:         35,256 Wh
    energy-full-design:  35,256 Wh
    energy-rate:         10,466 W
    voltage:             11,72 V
    charge-cycles:       37
    time to empty:       2,4 hours
    percentage:          72%
    capacity:            100%
    technology:          lithium-ion
    icon-name:          'battery-full-symbolic'
  History (charge):
    1726420845  72,000  discharging
  History (rate):
    1726420935  10,466  discharging
    1726420905  4,524   discharging
    1726420875  11,918  discharging
    1726420845  4,309   discharging
larkjkj commented 1 month ago

mine was doing this too, so i just verified, and i didn't have upower installed, so i installed, and it worked great, can you share the code of battery widget?

jtomski commented 1 month ago

Got the same issue on my machine, battery not available even tho upower is installed and detects the battery. Also tried using Battery.bind("available") to make sure the properties are initialized properly but without any success.

larkjkj commented 1 month ago

i dont use bind, instead i use a hook

Widget.Label().hook(battery => self {
   self.label = `${battery.percent}`
})

and it seems to work, try using this piece of code, but replacing, battery.percent for battery.available

jtomski commented 1 month ago

Using hooks seems to do the job, thanks @larkjkj. Had to do some slight adjustments but the following snippet now returns true:

Widget.Label().hook(battery, (self) => {
  self.label = `${battery.available}`
})
fe2-Nyxar commented 1 month ago

mine was doing this too, so i just verified, and i didn't have upower installed, so i installed, and it worked great, can you share the code of battery widget?

i already have upower and still doesn't work, here' the full code:

const battery = await Service.import('battery');

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`
        `icon-name`
    )

    console.log(value);
    return Widget.Box({
        class_name: "battery",
        visible: battery.bind("available"),
        children: [
            Widget.Icon({ icon }),
            Widget.LevelBar({
                widthRequest: 140,
                vpack: "center",
                value,
            }),
        ],
    })
}
fe2-Nyxar commented 1 month ago

Got the same issue on my machine, battery not available even tho upower is installed and detects the battery. Also tried using Battery.bind("available") to make sure the properties are initialized properly but without any success.

someone in the discord server said i should be using this:


    setInterval(() => {
        console.log(battery.percent)
        console.log(value);

    }, 5000)```
fe2-Nyxar commented 1 month ago
Widget.Label().hook(battery, (self) => {
  self.label = `${battery.available}`
})

can you tell me how your code works?

larkjkj commented 1 month ago

mine was doing this too, so i just verified, and i didn't have upower installed, so i installed, and it worked great, can you share the code of battery widget?

i already have upower and still doesn't work, here' the full code:

const battery = await Service.import('battery');

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`
        `icon-name`
    )

    console.log(value);
    return Widget.Box({
        class_name: "battery",
        visible: battery.bind("available"),
        children: [
            Widget.Icon({ icon }),
            Widget.LevelBar({
                widthRequest: 140,
                vpack: "center",
                value,
            }),
        ],
    })
}

remove the 'visible' and see if something changes

fe2-Nyxar commented 1 month ago

mine was doing this too, so i just verified, and i didn't have upower installed, so i installed, and it worked great, can you share the code of battery widget?

i already have upower and still doesn't work, here' the full code:

const battery = await Service.import('battery');

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`
        `icon-name`
    )

    console.log(value);
    return Widget.Box({
        class_name: "battery",
        visible: battery.bind("available"),
        children: [
            Widget.Icon({ icon }),
            Widget.LevelBar({
                widthRequest: 140,
                vpack: "center",
                value,
            }),
        ],
    })
}

remove the 'visible' and see if something changes

yeah nothing :(

MaximalCats commented 1 week ago

Hey, have you been able to fix this? Experiencing the same issue on Gentoo.