import os import sys import threading import subprocess import time from waitress import serve from django.core.wsgi import get_wsgi_application # Configuración básica de rutas if getattr(sys, 'frozen', False): BASE_DIR = os.path.dirname(sys.executable) APP_DATA_DIR = os.path.join(os.environ['APPDATA'], 'Intendencia') else: BASE_DIR = os.path.dirname(os.path.abspath(__file__)) APP_DATA_DIR = os.path.join(BASE_DIR, 'data') os.makedirs(APP_DATA_DIR, exist_ok=True) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sistema.settings') def start_server(): """Inicia el servidor WSGI con Waitress""" application = get_wsgi_application() serve(application, host='127.0.0.1', port=8000, threads=4) if __name__ == '__main__': # Iniciar el servidor en un hilo server_thread = threading.Thread(target=start_server, daemon=True) server_thread.start() # Esperar un momento para asegurarse de que el servidor esté listo time.sleep(1) # Ruta por defecto de Chrome en Windows (ajústala si usas otro sistema o instalación personalizada) chrome_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe" url = "http://127.0.0.1:8000" # Abrir Chrome en modo aplicación try: subprocess.Popen([chrome_path, f"--app={url}"]) except FileNotFoundError: print("No se encontró Google Chrome. Abriendo el navegador predeterminado...") import webbrowser webbrowser.open(url) # Mantener la aplicación viva try: while True: time.sleep(1) except KeyboardInterrupt: print("Cerrando la aplicación...") sys.exit(0)