Skip to content

Commit

Permalink
switch from ponymix to wpctl
Browse files Browse the repository at this point in the history
  • Loading branch information
alkazar committed Aug 5, 2024
1 parent 534023f commit 4e39f2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 43 deletions.
42 changes: 7 additions & 35 deletions chimera_app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,35 +1011,16 @@ def storage_task(device, func):


def get_audio():
if not shutil.which('ponymix'):
if not shutil.which('wpctl'):
return None

try:
raw = subprocess.check_output(["ponymix", "list-profiles"])
entries = raw.decode('utf8').split('\n')

volume = subprocess.check_output(["ponymix", "get-volume"])
volume = volume.decode('utf8')

muted = subprocess.call(["ponymix", "is-muted"])
print(muted)

active = None
grouped = []
for i in range(0, len(entries), 2):
if '[active]' in entries[i]:
active = entries[i].replace(' [active]', '')
grouped.append((active, entries[i+1].strip()))
elif entries[i]:
grouped.append((entries[i], entries[i+1].strip()))

results = [e for e in grouped if 'input' not in e[0] and e[0] != 'off']
volume_raw = subprocess.check_output(["wpctl", "get-volume", "@DEFAULT_AUDIO_SINK@"]).decode('utf8')
volume = int(float(volume_raw.split(':')[1].split('[')[0].strip()) * 100)

return {
'active': active,
'options': results,
'volume': volume,
'muted': muted != 0
'muted': '[MUTED]' in volume_raw
}
except:
return None
Expand All @@ -1049,7 +1030,7 @@ def get_audio():
@authenticate
def toggle_mute():
try:
subprocess.call(["ponymix", "toggle"])
subprocess.call(["wpctl", "set-mute", "@DEFAULT_AUDIO_SINK@", "toggle"])
finally:
redirect('/actions')

Expand All @@ -1058,7 +1039,7 @@ def toggle_mute():
@authenticate
def volume_up():
try:
subprocess.call(["ponymix", "increase", "10"])
subprocess.call(["wpctl", "set-volume", "--limit", "1.0", "@DEFAULT_AUDIO_SINK@", "10%+"])
finally:
redirect('/actions')

Expand All @@ -1067,20 +1048,11 @@ def volume_up():
@authenticate
def volume_down():
try:
subprocess.call(["ponymix", "decrease", "10"])
subprocess.call(["wpctl", "set-volume", "--limit", "1.0", "@DEFAULT_AUDIO_SINK@", "10%-"])
finally:
redirect('/actions')


@route('/audio/<profile>')
@authenticate
def audio(profile):
try:
subprocess.call(["ponymix", "set-profile", profile])
finally:
redirect('/')


@route('/actions/power/tdp_down')
@authenticate
def tdp_down():
Expand Down
6 changes: 0 additions & 6 deletions tests/test_unauthorized_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,3 @@ def test_volume_down(unauthorized_app):
resp = unauthorized_app.get('/actions/audio/volume_down')
assert(resp.status_code == 302)
assert(resp.headers['Location'] == 'http://localhost:80/login')


def test_audio_profile(unauthorized_app):
resp = unauthorized_app.get('/audio/profile')
assert(resp.status_code == 302)
assert(resp.headers['Location'] == 'http://localhost:80/login')
4 changes: 2 additions & 2 deletions views/actions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
-
</a>
% if get('audio')['muted']:
<a class="volume" style="color : lightgreen" href="/actions/audio/toggle_mute"><i class="ri-volume-up-fill"></i> {{get('audio')['volume']}}</a>
% else:
<a class="volume" style="color : crimson" href="/actions/audio/toggle_mute"><i class="ri-volume-mute-fill"></i> {{get('audio')['volume']}}</a>
% else:
<a class="volume" style="color : lightgreen" href="/actions/audio/toggle_mute"><i class="ri-volume-up-fill"></i> {{get('audio')['volume']}}</a>
% end
<a class="volume-up" href="/actions/audio/volume_up">
+
Expand Down

0 comments on commit 4e39f2e

Please sign in to comment.