95 lines
3.0 KiB
Python
95 lines
3.0 KiB
Python
"""
|
|
AutoBackups System Tray Launcher
|
|
Lanza la aplicación AutoBackups con icono en el system tray
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
import threading
|
|
import time
|
|
import logging
|
|
|
|
# Agregar el directorio src al path para imports
|
|
current_dir = Path(__file__).parent
|
|
src_dir = current_dir / "src"
|
|
sys.path.insert(0, str(src_dir))
|
|
|
|
# Imports de la aplicación
|
|
from src.app import AutoBackupsFlaskApp, app
|
|
|
|
|
|
def run_flask_app(autobackups_app, host, port, debug=False):
|
|
"""Ejecuta la aplicación Flask en un hilo separado"""
|
|
try:
|
|
app.run(host=host, port=port, debug=debug, use_reloader=False)
|
|
except Exception as e:
|
|
logging.error(f"Error ejecutando Flask app: {e}")
|
|
|
|
|
|
def main():
|
|
"""Función principal para el launcher del system tray"""
|
|
try:
|
|
print("AutoBackups - System Tray Mode")
|
|
print("=" * 30)
|
|
|
|
# Crear y configurar aplicación Flask
|
|
autobackups_app = AutoBackupsFlaskApp()
|
|
|
|
# Verificar requerimientos del sistema
|
|
if not autobackups_app.check_system_requirements():
|
|
print("Error en la verificación de requerimientos del sistema.")
|
|
sys.exit(1)
|
|
|
|
# Ejecutar descubrimiento inicial de proyectos
|
|
projects_found = autobackups_app.discover_projects()
|
|
msg = f"Descubrimiento inicial: {projects_found} proyectos encontrados"
|
|
print(msg)
|
|
|
|
# Configurar Flask
|
|
host = autobackups_app.config.web_interface.get("host", "127.0.0.1")
|
|
port = autobackups_app.config.web_interface.get("port", 5000)
|
|
debug = autobackups_app.config.web_interface.get("debug", False)
|
|
|
|
print(f"Servidor web iniciando en http://{host}:{port}")
|
|
|
|
# Iniciar system tray
|
|
if autobackups_app.start_system_tray():
|
|
print("✓ System tray iniciado correctamente")
|
|
else:
|
|
print("⚠ System tray no disponible, continuando...")
|
|
|
|
# Ejecutar Flask en un hilo separado
|
|
flask_thread = threading.Thread(
|
|
target=run_flask_app, args=(autobackups_app, host, port, debug), daemon=True
|
|
)
|
|
flask_thread.start()
|
|
|
|
print("✓ Aplicación iniciada")
|
|
print("• Accede desde el icono del system tray")
|
|
print("• Usa Ctrl+C para salir desde la consola")
|
|
print("• O usa 'Exit' desde el menú del system tray")
|
|
|
|
# Mantener el programa corriendo
|
|
try:
|
|
while True:
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
print("\nCerrando aplicación...")
|
|
|
|
except KeyboardInterrupt:
|
|
print("\nAplicación interrumpida por el usuario")
|
|
except Exception as e:
|
|
print(f"Error inesperado: {e}")
|
|
sys.exit(1)
|
|
finally:
|
|
# Limpieza
|
|
if "autobackups_app" in locals():
|
|
if autobackups_app.scheduler:
|
|
autobackups_app.scheduler.shutdown()
|
|
if autobackups_app.system_tray:
|
|
autobackups_app.system_tray.stop_tray()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|