Closed fe2-Nyxar closed 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?
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.
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
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}`
})
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,
}),
],
})
}
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)```
Widget.Label().hook(battery, (self) => { self.label = `${battery.available}` })
can you tell me how your code works?
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
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 :(
Hey, have you been able to fix this? Experiencing the same issue on Gentoo.
when i log the battery:
and when i log upower: