#include "mainwindow.h"

#include <QApplication>
#include <QByteArray>
#include <QIcon>
#include <QLocale>
#include <QSurfaceFormat>
#include <QThread>
#include <QTranslator>
#include "api/proxymanager.h"
#include "components/mpvcontroller.h"
#include "managers/languagemanager.h"
#include "managers/logmanager.h"

int main(int argc, char *argv[]) {
#if defined(Q_OS_LINUX)
  const QByteArray qpaPlatform = qgetenv("QT_QPA_PLATFORM");
  const QByteArray forceXcb = qgetenv("QEMBY_FORCE_XCB").toLower();
  if (qpaPlatform.isEmpty() &&
      (forceXcb == "1" || forceXcb == "true" || forceXcb == "yes")) {
    qputenv("QT_QPA_PLATFORM", "xcb");
  }
#endif

  
  QSurfaceFormat format;
#if !defined(Q_OS_LINUX)
  format.setVersion(3, 3); 
  format.setProfile(QSurfaceFormat::CoreProfile);
#endif
  format.setDepthBufferSize(24);  
  format.setStencilBufferSize(8); 
  format.setSwapInterval(1);      
  format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); 
  QSurfaceFormat::setDefaultFormat(format);

  QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
  QApplication a(argc, argv);
  a.setApplicationName(APP_NAME);
  a.setApplicationVersion(APP_VERSION);
  a.setOrganizationName("AlanHJ");
  a.setOrganizationDomain("github.com/AlanHJ/qEmby");
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
  QGuiApplication::setDesktopFileName(QStringLiteral("qemby"));
  const QIcon appIcon(QStringLiteral(":/svg/qemby_logo.svg"));
  a.setWindowIcon(appIcon);
#endif

  LogManager::instance()->init();
  LanguageManager::instance()->init();

  
  
  ProxyManager::installApplicationFactory();

  MainWindow w;
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
  w.setWindowIcon(appIcon);
#endif
  w.show();

  
  
  
  
  
  
  
  
  
  
  
  
  
  MpvController::warmupOnce();

  int ret = a.exec();
  
  return ret;
}
