MacUpdateThread.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "update-helpers.hpp"
  2. #include "shared-update.hpp"
  3. #include "moc_mac-update.cpp"
  4. #include "obs-app.hpp"
  5. #include <string>
  6. #include <qt-wrappers.hpp>
  7. #include <QMessageBox>
  8. /* ------------------------------------------------------------------------ */
  9. static const char *MAC_BRANCHES_URL = "https://obsproject.com/update_studio/branches.json";
  10. static const char *MAC_DEFAULT_BRANCH = "stable";
  11. /* ------------------------------------------------------------------------ */
  12. bool GetBranch(std::string &selectedBranch)
  13. {
  14. const char *config_branch = config_get_string(App()->GetAppConfig(), "General", "UpdateBranch");
  15. if (!config_branch)
  16. return true;
  17. bool found = false;
  18. for (const UpdateBranch &branch : App()->GetBranches()) {
  19. if (branch.name != config_branch)
  20. continue;
  21. /* A branch that is found but disabled will just silently fall back to
  22. * the default. But if the branch was removed entirely, the user should
  23. * be warned, so leave this false *only* if the branch was removed. */
  24. found = true;
  25. if (branch.is_enabled) {
  26. selectedBranch = branch.name.toStdString();
  27. }
  28. break;
  29. }
  30. return found;
  31. }
  32. /* ------------------------------------------------------------------------ */
  33. void MacUpdateThread::infoMsg(const QString &title, const QString &text)
  34. {
  35. OBSMessageBox::information(App()->GetMainWindow(), title, text);
  36. }
  37. void MacUpdateThread::info(const QString &title, const QString &text)
  38. {
  39. QMetaObject::invokeMethod(this, "infoMsg", Qt::BlockingQueuedConnection, Q_ARG(QString, title),
  40. Q_ARG(QString, text));
  41. }
  42. void MacUpdateThread::run()
  43. try {
  44. std::string text;
  45. std::string branch = MAC_DEFAULT_BRANCH;
  46. /* ----------------------------------- *
  47. * get branches from server */
  48. if (FetchAndVerifyFile("branches", "obs-studio/updates/branches.json", MAC_BRANCHES_URL, &text))
  49. App()->SetBranchData(text);
  50. /* ----------------------------------- *
  51. * Validate branch selection */
  52. if (!GetBranch(branch)) {
  53. config_set_string(App()->GetAppConfig(), "General", "UpdateBranch", MAC_DEFAULT_BRANCH);
  54. info(QTStr("Updater.BranchNotFound.Title"), QTStr("Updater.BranchNotFound.Text"));
  55. }
  56. emit Result(QString::fromStdString(branch), manualUpdate);
  57. } catch (std::string &text) {
  58. blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
  59. }