65 Zeilen
2.5 KiB
Python
65 Zeilen
2.5 KiB
Python
"""
|
|
Project Process Tracker
|
|
Tracks running state of projects in memory
|
|
"""
|
|
import subprocess
|
|
|
|
class ProjectProcessTracker:
|
|
"""Simple in-memory tracker for project states"""
|
|
def __init__(self):
|
|
self.running_projects = set()
|
|
self.project_manager = None # Will be set by MainWindow
|
|
|
|
def set_project_manager(self, project_manager):
|
|
"""Set reference to project manager"""
|
|
self.project_manager = project_manager
|
|
|
|
def set_running(self, project_id: str):
|
|
"""Mark a project as running"""
|
|
self.running_projects.add(project_id)
|
|
|
|
def set_stopped(self, project_id: str):
|
|
"""Mark a project as stopped"""
|
|
self.running_projects.discard(project_id)
|
|
|
|
def check_window_exists(self, window_title: str) -> bool:
|
|
"""Check if a window with the given title exists"""
|
|
try:
|
|
# Use PowerShell for faster window checking
|
|
ps_command = f'powershell -Command "(Get-Process | Where-Object {{$_.MainWindowTitle -eq \'{window_title}\'}}).Count -gt 0"'
|
|
|
|
# Hide console window on Windows
|
|
startupinfo = None
|
|
if hasattr(subprocess, 'STARTUPINFO'):
|
|
startupinfo = subprocess.STARTUPINFO()
|
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
startupinfo.wShowWindow = subprocess.SW_HIDE
|
|
|
|
result = subprocess.run(ps_command, capture_output=True, text=True, shell=True,
|
|
timeout=1, startupinfo=startupinfo)
|
|
return result.stdout.strip().lower() == 'true'
|
|
except Exception as e:
|
|
# Fallback to simple check
|
|
return False
|
|
|
|
def is_running(self, project_id: str) -> bool:
|
|
"""Check if a project is running by checking window title"""
|
|
if project_id == "vps-permanent":
|
|
# Check for VPS window
|
|
return self.check_window_exists("Claude VPS Server")
|
|
else:
|
|
# Check for project window by name
|
|
if self.project_manager:
|
|
project = self.project_manager.get_project(project_id)
|
|
if project:
|
|
window_title = f"Claude - {project.name}"
|
|
return self.check_window_exists(window_title)
|
|
return False
|
|
|
|
def stop_all(self):
|
|
"""Clear all running states"""
|
|
self.running_projects.clear()
|
|
|
|
def get_running_projects(self) -> set:
|
|
"""Get all running project IDs"""
|
|
return self.running_projects.copy() |