* @brief Activates a license key against the Lemon Squeezy API and exits. */
| 717 | * @brief Activates a license key against the Lemon Squeezy API and exits. |
| 718 | */ |
| 719 | int CLI::activateLicense(QApplication& app, const QString& licenseKey) |
| 720 | { |
| 721 | auto& ls = Licensing::LemonSqueezy::instance(); |
| 722 | |
| 723 | ls.setLicense(licenseKey); |
| 724 | if (!ls.canActivate()) { |
| 725 | qCritical() << "Invalid license key format:" << licenseKey; |
| 726 | return EXIT_FAILURE; |
| 727 | } |
| 728 | |
| 729 | int result = EXIT_FAILURE; |
| 730 | |
| 731 | QTimer timeout; |
| 732 | timeout.setSingleShot(true); |
| 733 | timeout.setInterval(30'000); |
| 734 | |
| 735 | QObject::connect(&ls, &Licensing::LemonSqueezy::activatedChanged, &app, [&] { |
| 736 | result = ls.isActivated() ? EXIT_SUCCESS : EXIT_FAILURE; |
| 737 | if (ls.isActivated()) |
| 738 | qInfo() << "License activated successfully."; |
| 739 | else |
| 740 | qCritical() << "License activation failed."; |
| 741 | |
| 742 | app.quit(); |
| 743 | }); |
| 744 | |
| 745 | QObject::connect(&timeout, &QTimer::timeout, &app, [&] { |
| 746 | qCritical() << "License activation timed out."; |
| 747 | app.quit(); |
| 748 | }); |
| 749 | |
| 750 | QTimer::singleShot(0, &ls, &Licensing::LemonSqueezy::activate); |
| 751 | timeout.start(); |
| 752 | |
| 753 | app.exec(); |
| 754 | return result; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * @brief Deactivates the stored license instance on this machine and exits. |
nothing calls this directly
no test coverage detected