MacUpdateThread.cpp 2.0 KB

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