TypeError: UPower is undefined
enku opened this issue · 8 comments
Upgraded to version 24
on GNOME 42. Not sure why this is happening but
JS ERROR: TypeError: UPower is undefined
update/<@/home/marduk/.local/share/gnome-shell/extensions/autohide-battery@sitnik.ru/extension.js:22:25
getBattery@/home/marduk/.local/share/gnome-shell/extensions/autohide-battery@sitnik.ru/extension.js:39:13
update@/home/marduk/.local/share/gnome-shell/extensions/autohide-battery@sitnik.ru/extension.js:21:13
Although UPower
seems to be defined on line 2
. I've tried UPower = imports.ui.status.power.UPower
on the Looking Glass prompt and get an object. Could there be some kind of race?
Very strange. Sorry, I have no idea.
(re)importing upower after line 19
works around the issue.
Can you try this hack?
const ExtensionUtils = imports.misc.extensionUtils
- const UPower = imports.ui.status.power.UPower
+ const Power = imports.ui.status.power
const Main = imports.ui.main
let batteryWatching, settingsWatching, settings, disabled
function show() {
getBattery((proxy, icon) => {
icon.show()
})
}
function hide() {
getBattery((proxy, icon) => {
icon.hide()
})
}
function update() {
let hideOn = settings.get_int('hide-on')
getBattery(proxy => {
- let isDischarging = proxy.State === UPower.DeviceState.DISCHARGING
- let isFullyCharged = proxy.State === UPower.DeviceState.FULLY_CHARGED
- if (proxy.Type !== UPower.DeviceKind.BATTERY) {
+ let isDischarging = proxy.State === Power.UPower.DeviceState.DISCHARGING
+ let isFullyCharged = proxy.State === Power.UPower.DeviceState.FULLY_CHARGED
+ if (proxy.Type !== Power.UPower.DeviceKind.BATTERY) {
show()
} else if (isFullyCharged) {
hide()
} else if (proxy.Percentage >= hideOn && !isDischarging) {
hide()
} else {
show()
}
})
}
Can you try this hack?
Yes, that works too. So seems like some race between when UPower
is defined in power
and when it is referenced in update()
.
Great. I will release a fix in an hour. If you want, you can send PR to save your name in the project history.
We can add if (Power.UPower)
check to update
Version 25 was pushed to https://extensions.gnome.org/extension/595/autohide-battery/
Feel free to open new issue if you find a problem.