main.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import sys
  2. import os
  3. import asyncio
  4. import logging
  5. from pathlib import Path
  6. from PySide6.QtCore import QUrl
  7. from PySide6.QtGui import QGuiApplication
  8. from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
  9. from qasync import QEventLoop
  10. from backend import Backend
  11. from models.pattern_model import PatternModel
  12. from models.playlist_model import PlaylistModel
  13. from png_cache_manager import ensure_png_cache_startup
  14. # Configure logging
  15. logging.basicConfig(
  16. level=logging.INFO,
  17. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
  18. )
  19. logger = logging.getLogger(__name__)
  20. async def startup_tasks():
  21. """Run async startup tasks"""
  22. logger.info("🚀 Starting dune-weaver-touch async initialization...")
  23. # Ensure PNG cache is available for all WebP previews
  24. try:
  25. logger.info("🎨 Checking PNG preview cache...")
  26. png_cache_success = await ensure_png_cache_startup()
  27. if png_cache_success:
  28. logger.info("✅ PNG cache check completed successfully")
  29. else:
  30. logger.warning("⚠️ PNG cache check completed with warnings")
  31. except Exception as e:
  32. logger.error(f"❌ PNG cache check failed: {e}")
  33. logger.info("✨ dune-weaver-touch startup tasks completed")
  34. def main():
  35. # Enable virtual keyboard
  36. os.environ['QT_IM_MODULE'] = 'qtvirtualkeyboard'
  37. app = QGuiApplication(sys.argv)
  38. # Setup async event loop
  39. loop = QEventLoop(app)
  40. asyncio.set_event_loop(loop)
  41. # Register types
  42. qmlRegisterType(Backend, "DuneWeaver", 1, 0, "Backend")
  43. qmlRegisterType(PatternModel, "DuneWeaver", 1, 0, "PatternModel")
  44. qmlRegisterType(PlaylistModel, "DuneWeaver", 1, 0, "PlaylistModel")
  45. # Run startup tasks in background
  46. asyncio.create_task(startup_tasks())
  47. # Load QML
  48. engine = QQmlApplicationEngine()
  49. qml_file = Path(__file__).parent / "qml" / "main.qml"
  50. engine.load(QUrl.fromLocalFile(str(qml_file)))
  51. if not engine.rootObjects():
  52. return -1
  53. with loop:
  54. loop.run_forever()
  55. return 0
  56. if __name__ == "__main__":
  57. sys.exit(main())