You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
4.8KB

  1. #include <thread>
  2. #include "app.hpp"
  3. #include "plugin.hpp"
  4. #include "window.hpp"
  5. #include "osdialog.h"
  6. namespace rack {
  7. struct RegisterButton : Button {
  8. void onAction(EventAction &e) override {
  9. std::thread t([&]() {
  10. systemOpenBrowser("https://vcvrack.com/");
  11. });
  12. t.detach();
  13. }
  14. };
  15. struct LogInButton : Button {
  16. TextField *emailField;
  17. TextField *passwordField;
  18. void onAction(EventAction &e) override {
  19. std::thread t(pluginLogIn, emailField->text, passwordField->text);
  20. t.detach();
  21. passwordField->text = "";
  22. }
  23. };
  24. struct StatusLabel : Label {
  25. void step() override {
  26. text = pluginGetLoginStatus();
  27. }
  28. };
  29. struct ManageButton : Button {
  30. void onAction(EventAction &e) override {
  31. std::thread t([&]() {
  32. systemOpenBrowser("https://vcvrack.com/");
  33. });
  34. t.detach();
  35. }
  36. };
  37. struct SyncButton : Button {
  38. bool checked = false;
  39. /** Updates are available */
  40. bool available = false;
  41. /** Plugins have been updated */
  42. bool completed = false;
  43. void step() override {
  44. // Check for plugin update on first step()
  45. if (!checked) {
  46. std::thread t([this]() {
  47. if (pluginSync(true))
  48. available = true;
  49. });
  50. t.detach();
  51. checked = true;
  52. }
  53. // Display message if we've completed updates
  54. if (completed) {
  55. if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "All plugins have been updated. Close Rack and re-launch it to load new updates.")) {
  56. windowClose();
  57. }
  58. completed = false;
  59. }
  60. }
  61. void draw(NVGcontext *vg) override {
  62. Button::draw(vg);
  63. if (available) {
  64. // Notification circle
  65. nvgBeginPath(vg);
  66. nvgCircle(vg, 3, 3, 4.0);
  67. nvgFillColor(vg, nvgRGBf(1.0, 0.0, 0.0));
  68. nvgFill(vg);
  69. nvgStrokeColor(vg, nvgRGBf(0.5, 0.0, 0.0));
  70. nvgStroke(vg);
  71. }
  72. }
  73. void onAction(EventAction &e) override {
  74. available = false;
  75. std::thread t([this]() {
  76. if (pluginSync(false))
  77. completed = true;
  78. });
  79. t.detach();
  80. }
  81. };
  82. struct LogOutButton : Button {
  83. void onAction(EventAction &e) override {
  84. pluginLogOut();
  85. }
  86. };
  87. struct DownloadProgressBar : ProgressBar {
  88. void step() override {
  89. label = "Downloading";
  90. std::string name = pluginGetDownloadName();
  91. if (name != "")
  92. label += " " + name;
  93. setValue(100.0 * pluginGetDownloadProgress());
  94. }
  95. };
  96. struct CancelButton : Button {
  97. void onAction(EventAction &e) override {
  98. pluginCancelDownload();
  99. }
  100. };
  101. PluginManagerWidget::PluginManagerWidget() {
  102. box.size.y = BND_WIDGET_HEIGHT;
  103. {
  104. SequentialLayout *layout = Widget::create<SequentialLayout>(Vec(0, 0));
  105. layout->spacing = 5;
  106. loginWidget = layout;
  107. Button *registerButton = new RegisterButton();
  108. registerButton->box.size.x = 75;
  109. registerButton->text = "Register";
  110. loginWidget->addChild(registerButton);
  111. TextField *emailField = new TextField();
  112. emailField->box.size.x = 175;
  113. emailField->placeholder = "Email";
  114. loginWidget->addChild(emailField);
  115. PasswordField *passwordField = new PasswordField();
  116. passwordField->box.size.x = 175;
  117. passwordField->placeholder = "Password";
  118. loginWidget->addChild(passwordField);
  119. LogInButton *logInButton = new LogInButton();
  120. logInButton->box.size.x = 100;
  121. logInButton->text = "Log in";
  122. logInButton->emailField = emailField;
  123. logInButton->passwordField = passwordField;
  124. loginWidget->addChild(logInButton);
  125. Label *label = new StatusLabel();
  126. loginWidget->addChild(label);
  127. addChild(loginWidget);
  128. }
  129. {
  130. SequentialLayout *layout = Widget::create<SequentialLayout>(Vec(0, 0));
  131. layout->spacing = 5;
  132. manageWidget = layout;
  133. Button *manageButton = new ManageButton();
  134. manageButton->box.size.x = 125;
  135. manageButton->text = "Manage plugins";
  136. manageWidget->addChild(manageButton);
  137. Button *syncButton = new SyncButton();
  138. syncButton->box.size.x = 125;
  139. syncButton->text = "Update plugins";
  140. manageWidget->addChild(syncButton);
  141. Button *logOutButton = new LogOutButton();
  142. logOutButton->box.size.x = 100;
  143. logOutButton->text = "Log out";
  144. manageWidget->addChild(logOutButton);
  145. addChild(manageWidget);
  146. }
  147. {
  148. SequentialLayout *layout = Widget::create<SequentialLayout>(Vec(0, 0));
  149. layout->spacing = 5;
  150. downloadWidget = layout;
  151. ProgressBar *downloadProgress = new DownloadProgressBar();
  152. downloadProgress->box.size.x = 300;
  153. downloadProgress->setLimits(0, 100);
  154. downloadProgress->unit = "%";
  155. downloadWidget->addChild(downloadProgress);
  156. // Button *cancelButton = new CancelButton();
  157. // cancelButton->box.size.x = 100;
  158. // cancelButton->text = "Cancel";
  159. // downloadWidget->addChild(cancelButton);
  160. addChild(downloadWidget);
  161. }
  162. }
  163. void PluginManagerWidget::step() {
  164. loginWidget->visible = false;
  165. manageWidget->visible = false;
  166. downloadWidget->visible = false;
  167. if (pluginIsDownloading())
  168. downloadWidget->visible = true;
  169. else if (pluginIsLoggedIn())
  170. manageWidget->visible = true;
  171. else
  172. loginWidget->visible = true;
  173. Widget::step();
  174. }
  175. } // namespace rack