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.

217 lines
5.1KB

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