Skip to content

Commit

Permalink
workaround pycaw crash
Browse files Browse the repository at this point in the history
  • Loading branch information
erivieccio committed Sep 3, 2024
1 parent a6d0b2f commit 874b772
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
14 changes: 11 additions & 3 deletions client-scripts/windows/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

# Paths for installation and files
$installPath = "C:\busylight"
$pythonScriptPath = "$installPath\mic-in-use-windows.py"
$pythonScriptPath = "$installPath\run-mic-in-use-windows.py"
$requirementsPath = "$installPath\requirements.txt"
$taskName = "MicInUseTask"
$taskDescription = "Task to run the mic-in-use-windows.py script at logon."
$taskDescription = "Task to run the run-mic-in-use-windows.py script at logon."

# Create installation folder if it does not exist
if (-not (Test-Path -Path $installPath)) {
Expand All @@ -23,9 +23,17 @@ if (-not (Test-Path -Path $installPath)) {
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition

# Check if the files exist and move them
if (Test-Path "$scriptDirectory\run-mic-in-use-windows.py") {
Write-Output "Moving run-mic-in-use-windows.py to $installPath..."
Move-Item -Path "$scriptDirectory\run-mic-in-use-windows.py" -Destination $pythonScriptPath -Force
} else {
Write-Error "run-mic-in-use-windows.py not found in the script directory."
exit 1
}

if (Test-Path "$scriptDirectory\mic-in-use-windows.py") {
Write-Output "Moving mic-in-use-windows.py to $installPath..."
Move-Item -Path "$scriptDirectory\mic-in-use-windows.py" -Destination $pythonScriptPath -Force
Move-Item -Path "$scriptDirectory\mic-in-use-windows.py" -Destination "$installPath\mic-in-use-windows.py" -Force
} else {
Write-Error "mic-in-use-windows.py not found in the script directory."
exit 1
Expand Down
2 changes: 1 addition & 1 deletion client-scripts/windows/mic-in-use-windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def is_microphone_in_use():
if process_name and process_name not in ignored_processes:
return process_name
except Exception as e:
continue # Continue to the next session instead of halting
print(f"Error checking session: {e}")

return None

Expand Down
51 changes: 51 additions & 0 deletions client-scripts/windows/run-mic-in-use-windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ---------------------------------------------------------------------------------------
# Project: BusyLight Windows Client - Runner Script
# Author: Evaristo R. Rivieccio Vega - SysAdmin
# GitHub: https://github.com/evaristorivi
# LinkedIn: https://www.linkedin.com/in/evaristorivieccio/
# Web: https://www.evaristorivieccio.es/
# ---------------------------------------------------------------------------------------
# Description:
# This Python script is a runner for the BusyLight Windows Client. It is designed to
# ensure that the main script, mic-in-use-windows.py, continues to run indefinitely by
# restarting it if it closes unexpectedly.
#
# The main script monitors the status of audio sessions in real-time and sends signals
# to the BusyLight API to control the LED strip based on whether the microphone is in use
# or not.
#
# The runner script is responsible for:
# - Launching the main script.
# - Detecting if the main script terminates.
# - Restarting the main script if it exits.
#
# Usage:
# Run this script to ensure that the BusyLight client script is always running.
#
# ---------------------------------------------------------------------------------------

import subprocess
import time
import os
import sys

def run_script():
print("The service is running. You can minimise this window.")
script_path = os.path.join(os.path.dirname(__file__), 'mic-in-use-windows.py')

process = subprocess.Popen([sys.executable, script_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
exit_code = process.wait()

# stdout, stderr = process.communicate()
# if stdout:
# print(stdout.decode())
# if stderr:
# print(stderr.decode())

time.sleep(1)
process = subprocess.Popen([sys.executable, script_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if __name__ == "__main__":
run_script()

0 comments on commit 874b772

Please sign in to comment.