halinuxcompanion icon indicating copy to clipboard operation
halinuxcompanion copied to clipboard

Change default `idle` attribute to `false`

Open slovdahl opened this issue 1 year ago • 7 comments

Right now when the companion app is started, the status sensor will have the idle attribute set to unknown until the computer has been put in suspend or is shut down. I'm suggesting that we change the default value to false instead, because unless I'm mistaken, it should be safe to assume that the computer is not idle when the companion app starts.

Having only two valid states of the idle attribute simplifies using it in e.g. automations.

slovdahl avatar Feb 19 '24 20:02 slovdahl

Maybe there are some edge cases around this after all 🤔 If for some reason the companion app is restarted while the user running it has the screen locked for example.

slovdahl avatar Feb 21 '24 15:02 slovdahl

Can the state be queried?

slovdahl avatar Feb 21 '24 16:02 slovdahl

🤔 we would need to implement the query to be sure.

muniter avatar Feb 25 '24 14:02 muniter

Seems like it can be queried to dubs.

https://stackoverflow.com/questions/52510375/screensaver-status-on-linux-via-python-dbus-using-python3

muniter avatar Feb 25 '24 14:02 muniter

I think we do need querying for quite normal cases too. With this PR, when the computer wakes up the status is immediately considered "active". Only after logging in and locking the screen the status will be correct.

I noticed this because I sometimes get my desktop computer woken up (kids, wife, etc) when I'm not sitting there.

slovdahl avatar Sep 16 '24 16:09 slovdahl

I think we do need querying for quite normal cases too. With this PR, when the computer wakes up the status is immediately considered "active". Only after logging in and locking the screen the status will be correct.

I noticed this because I sometimes get my desktop computer woken up (kids, wife, etc) when I'm not sitting there.

Hmm, or has this been caused by some kind of timing issue/race condition somewhere.. I made a minimal Python script listening to the various DBus events and AFAICT the events arrive at the right times and in the right order. But I'm now testing it on an Ubuntu 24.04 laptop, and my desktop where I have been using it before is on Ubuntu 22.04. Need to dig a bit more.

slovdahl avatar Sep 16 '24 19:09 slovdahl

@muniter I managed to query the state from org.gnome.ScreenSaver at least. It doesn't seem like org.freedesktop.ScreenSaver exposes the current state. At least not on my Ubuntu 24.04.

bus = Dbus()
await bus.init()
screensaver_interface = await bus.get_interface("org.gnome.ScreenSaver")
is_active = await screensaver_interface.call_get_active()

Now I just wonder how or where to hook it in.

One idea I got was to query the state in status.py's updater method if self.attributes["idle"] == "unknown". But 1) the DBus instance is not available there 2) the method is not async.

Or we could try to do something similar to SIGNALS in dbus.py.. But I'm not sure how one would tell dbus.py when the querying should be done, unless we query it every refresh_interval, but that feels a bit overkill.

If you have some rough idea of how it could be done in a good way I'm all ears.

slovdahl avatar Sep 16 '24 19:09 slovdahl