lwindolf / liferea

Liferea (Linux Feed Reader), a news reader for GTK/GNOME
https://lzone.de/liferea
GNU General Public License v2.0
825 stars 128 forks source link

Use monotonic clock in libnotify plugin #1207

Closed tatokis closed 1 year ago

tatokis commented 1 year ago

It is a good idea to use a monotonic clock as a way to check how much time has passed, as it will not be affected by the system clock changing (DST for example).

However, I am not sure what the minimum targeted Python 3 version is.

From the docs for time.monotonic():

New in version 3.3.

Changed in version 3.5: The function is now always available and always system-wide.

Changed in version 3.10: On macOS, the function is now system-wide.

If the minimum Python version is < 3.5, then a check needs to be added to use time.monotonic() if it's available.

lwindolf commented 1 year ago

This improvement makes sense. I guess the Python 3.5 requirement is not a problem as we depend on WebkitGtk4+ which on no system I know of is available with older Python version.

So I'd say let's merge this and maybe just add something like this to the plugin

import sys
MIN_PYTHON = (3, 5)
assert sys.version_info >= MIN_PYTHON, f"requires Python {'.'.join([str(n) for n in MIN_PYTHON])} or newer"
lwindolf commented 1 year ago

@tatokis What do you think about the suggestion above?

tatokis commented 1 year ago

@lwindolf Sounds good to me.

Sorry, I was thinking of scrapping this entirely and instead of timing it, just clearing the message when the notification is dismissed (as there seems to be a closed event, but I haven't actually tested it, and I have the suspicion some implementations might not implement it correctly).