-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spliced code into modules, added displayswitch clone option, big cleanup
* removed unused function * fixed desktop video box not loading, changed parsing to monitors list instead of cfg * cleanup * created separated modules for audio, monitor, shortcut, mode. reverted to displayswitch with clone option on unsuported hardware * moved window detection to window_monitor * removed unused variable in setup.py * readme and screenshot
- Loading branch information
Showing
12 changed files
with
349 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import subprocess | ||
import re | ||
import time | ||
|
||
|
||
def get_audio_devices(): | ||
cmd = "powershell Get-AudioDevice -list" | ||
output = subprocess.check_output(cmd, shell=True, text=True) | ||
devices = re.findall(r"Index\s+:\s+(\d+)\s+.*?Name\s+:\s+(.*?)\s+ID\s+:\s+{(.*?)}", output, re.DOTALL) | ||
return devices | ||
|
||
|
||
def set_audio_device(device_name, devices): | ||
device_words = device_name.lower().split() | ||
for index, name, _ in devices: | ||
if all(word in name.lower() for word in device_words): | ||
cmd = f"powershell set-audiodevice -index {index}" | ||
result = subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | ||
return result.returncode == 0 | ||
return False | ||
|
||
|
||
def switch_audio(audio_output): | ||
devices = get_audio_devices() | ||
success = set_audio_device(audio_output, devices) | ||
retries = 0 | ||
while not success and retries < 10: | ||
print("Failed to switch audio, retrying...") | ||
time.sleep(1) | ||
success = set_audio_device(audio_output, devices) | ||
retries += 1 | ||
if not success: | ||
print("Failed to switch audio after 10 attempts.") | ||
|
||
|
||
def is_audio_device_cmdlets_installed(): | ||
cmd = 'powershell "Get-Module -ListAvailable -Name AudioDeviceCmdlets"' | ||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True) | ||
if "AudioDeviceCmdlets" in result.stdout: | ||
return True | ||
else: | ||
return False |
Oops, something went wrong.