main.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <QApplication>
  2. #include <QObject>
  3. #include <QQmlApplicationEngine>
  4. #include <QQmlComponent>
  5. #include <QQmlContext>
  6. #include <csignal>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <sys/prctl.h>
  12. #include <sys/wait.h>
  13. #include <thread>
  14. #include <unistd.h>
  15. #include "../include/climanager.h"
  16. #include "../include/cmdmanager.h"
  17. #include "../include/jsonhandler.h"
  18. #include "../include/qmlhandler.h"
  19. using namespace std;
  20. int main(int argc, char *argv[]) {
  21. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  22. QCoreApplication::setOrganizationName("CCats");
  23. QApplication app(argc, argv);
  24. QQmlApplicationEngine engine;
  25. QMLHandler qmlHandler;
  26. qmlHandler.setConfigExists(Config::loadFile());
  27. CmdManager::setQmlHandler(&qmlHandler);
  28. CmdManager::init();
  29. CliManager::setQmlHandler(&qmlHandler);
  30. JsonHandler::setQmlHandler(&qmlHandler);
  31. // Set the context for the window, so that the qml files can be connected to the qmlHandler
  32. engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
  33. // Load the main window
  34. QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/Forms/Main/main.qml")));
  35. QObject *object = component.create();
  36. // Run the main window and save the return of the application in an integer ret
  37. // This is blocking, which means it will block the main program until the window is closed
  38. int ret = app.exec();
  39. // If we land here, the window has been closed. Properly disconnect from the server now
  40. CliManager::onExit();
  41. // Restart this application if the _RESTART variable is set (for example when the user deletes their account)
  42. if (_RESTART) {
  43. pid_t pid = 0;
  44. pid = fork();
  45. if (pid == 0) {
  46. execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
  47. exit(1);
  48. }
  49. }
  50. delete object;
  51. return ret;
  52. }