|
19 | 19 | connection_thread = None
|
20 | 20 | ble_devices = []
|
21 | 21 | stream_active = False
|
| 22 | +running_apps = {} # Dictionary to track running apps |
22 | 23 |
|
23 | 24 | def run_async(coro):
|
24 | 25 | def wrapper(*args, **kwargs):
|
@@ -87,19 +88,33 @@ def launch_application():
|
87 | 88 | if not app_name:
|
88 | 89 | return jsonify({'status': 'error', 'message': 'No application specified'}), 400
|
89 | 90 |
|
| 91 | + # Check if app is already running |
| 92 | + if app_name in running_apps and running_apps[app_name].poll() is None: |
| 93 | + return jsonify({'status': 'error', 'message': f'{app_name} is already running','code': 'ALREADY_RUNNING'}), 400 |
| 94 | + |
90 | 95 | try:
|
91 |
| - # Here we'll use subprocess to launch the application script |
92 | 96 | import subprocess
|
93 | 97 | import sys
|
94 | 98 |
|
95 |
| - python_exec = sys.executable # Determine the correct Python executable |
96 |
| - subprocess.Popen([python_exec, f"{app_name}.py"]) # Launch the application script in a separate process |
| 99 | + python_exec = sys.executable |
| 100 | + process = subprocess.Popen([python_exec, f"{app_name}.py"]) |
| 101 | + running_apps[app_name] = process |
97 | 102 |
|
98 | 103 | return jsonify({'status': 'success', 'message': f'Launched {app_name}'})
|
99 | 104 | except Exception as e:
|
100 | 105 | logging.error(f"Error launching {app_name}: {str(e)}")
|
101 | 106 | return jsonify({'status': 'error', 'message': str(e)}), 500
|
102 | 107 |
|
| 108 | +@app.route('/check_app_status/<app_name>') |
| 109 | +def check_app_status(app_name): |
| 110 | + if app_name in running_apps: |
| 111 | + if running_apps[app_name].poll() is None: # Still running |
| 112 | + return jsonify({'status': 'running'}) |
| 113 | + else: # Process has terminated |
| 114 | + del running_apps[app_name] |
| 115 | + return jsonify({'status': 'not_running'}) |
| 116 | + return jsonify({'status': 'not_running'}) |
| 117 | + |
103 | 118 | @app.route('/connect', methods=['POST'])
|
104 | 119 | def connect_device():
|
105 | 120 | global connection_manager, connection_thread, stream_active
|
|
0 commit comments