Skip to content

Commit

Permalink
Tries to reduce CPU usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
conor-f committed Aug 29, 2023
1 parent 621d0be commit 5e9806b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name='spotibar',
description='Spotify plugin for Polybar',
version='0.3.10',
version='0.3.11',
url='https://github.com/conor-f/spotibar',
python_requires='>=3.6',
packages=find_packages('src'),
Expand Down
13 changes: 5 additions & 8 deletions src/spotibar/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def get_simple_timestamp(self):
"""
return int(datetime.now().timestamp())

def is_playing_locally(self):
def is_playing(self):
"""
Returns True if dbus thinks we are currently playing Spotify locally, False otherwise.
"""
Expand All @@ -289,8 +289,9 @@ def is_playing_locally(self):

return False
except Exception as e:
# This is an expected case if X11 isn't running. Just return False.
return False
# This is an expected case if X11 isn't running. Do the expensive
# check of polling the API:
return self.is_currently_playing()

def was_playing_recently(self, seconds=20):
"""
Expand All @@ -305,11 +306,7 @@ def is_live(self):
"""
Returns True if Spotify is currently playing, False otherwise.
"""
return (
self.is_playing_locally()
or self.was_playing_recently()
or self.is_currently_playing()
)
return self.is_playing() or self.was_playing_recently()

def get_current_album_image_url(self):
"""
Expand Down

0 comments on commit 5e9806b

Please sign in to comment.