| 14 | #endif |
| 15 | |
| 16 | int main(int argc, char *argv[]) |
| 17 | { |
| 18 | QGuiApplication app(argc, argv); |
| 19 | app.setOrganizationName("CloudRedirect"); |
| 20 | app.setApplicationName("CloudRedirect"); |
| 21 | app.setApplicationVersion(CR_VERSION); |
| 22 | |
| 23 | // Set window icon: try theme first, fall back to embedded resource |
| 24 | QIcon appIcon = QIcon::fromTheme("org.cloudredirect.CloudRedirect"); |
| 25 | if (appIcon.isNull()) |
| 26 | appIcon = QIcon(":/icons/cloudredirect.png"); |
| 27 | app.setWindowIcon(appIcon); |
| 28 | |
| 29 | // Set desktop filename for Wayland compositor window matching |
| 30 | app.setDesktopFileName("org.cloudredirect.CloudRedirect"); |
| 31 | |
| 32 | // Use Breeze style on KDE, fallback to Fusion |
| 33 | if (QQuickStyle::name().isEmpty()) |
| 34 | QQuickStyle::setStyle("org.kde.desktop"); |
| 35 | |
| 36 | QQmlApplicationEngine engine; |
| 37 | |
| 38 | // Register backend singletons |
| 39 | Backend backend; |
| 40 | Deployer deployer; |
| 41 | OAuthService oauthService; |
| 42 | |
| 43 | engine.rootContext()->setContextProperty("backend", &backend); |
| 44 | engine.rootContext()->setContextProperty("deployer", &deployer); |
| 45 | engine.rootContext()->setContextProperty("oauth", &oauthService); |
| 46 | |
| 47 | // Wire OAuth signals to backend |
| 48 | QObject::connect(&oauthService, &OAuthService::authSucceeded, &backend, &Backend::refreshStatus); |
| 49 | QObject::connect(&oauthService, &OAuthService::authSucceeded, &backend, &Backend::saveConfig); |
| 50 | |
| 51 | // Wire deployer signals to backend so Dashboard updates after deploy/undeploy |
| 52 | QObject::connect(&deployer, &Deployer::checkCompleted, &backend, &Backend::refreshStatus); |
| 53 | |
| 54 | // Load QML from the compiled-in resource |
| 55 | const QUrl url(u"qrc:/CloudRedirect/qml/Main.qml"_s); |
| 56 | QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, |
| 57 | &app, []() { qCritical("QML load failed"); exit(-1); }, |
| 58 | Qt::QueuedConnection); |
| 59 | engine.load(url); |
| 60 | |
| 61 | if (engine.rootObjects().isEmpty()) |
| 62 | return -1; |
| 63 | |
| 64 | return app.exec(); |
| 65 | } |