diff --git a/chimera_app/server.py b/chimera_app/server.py index 7e89153..72cce93 100644 --- a/chimera_app/server.py +++ b/chimera_app/server.py @@ -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 @@ -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') @@ -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') @@ -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/') -@authenticate -def audio(profile): - try: - subprocess.call(["ponymix", "set-profile", profile]) - finally: - redirect('/') - - @route('/actions/power/tdp_down') @authenticate def tdp_down(): diff --git a/tests/test_unauthorized_access.py b/tests/test_unauthorized_access.py index 49033ba..88af0c6 100644 --- a/tests/test_unauthorized_access.py +++ b/tests/test_unauthorized_access.py @@ -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') diff --git a/views/actions.tpl b/views/actions.tpl index 7d9ea9d..d2c2c9c 100644 --- a/views/actions.tpl +++ b/views/actions.tpl @@ -8,9 +8,9 @@ - % if get('audio')['muted']: - {{get('audio')['volume']}} - % else: {{get('audio')['volume']}} + % else: + {{get('audio')['volume']}} % end +