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.

222 lines
5.2KB

  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([&]() {
  57. systemOpenBrowser("https://vcvrack.com/");
  58. });
  59. t.detach();
  60. }
  61. };
  62. Button *registerButton = new RegisterButton();
  63. registerButton->box.pos = pos;
  64. registerButton->box.size.x = 75;
  65. registerButton->text = "Register";
  66. loginWidget->addChild(registerButton);
  67. pos.x += registerButton->box.size.x;
  68. pos.x += margin;
  69. TextField *emailField = new TextField();
  70. emailField->box.pos = pos;
  71. emailField->box.size.x = 175;
  72. emailField->placeholder = "Email";
  73. loginWidget->addChild(emailField);
  74. pos.x += emailField->box.size.x;
  75. pos.x += margin;
  76. PasswordField *passwordField = new PasswordField();
  77. passwordField->box.pos = pos;
  78. passwordField->box.size.x = 175;
  79. passwordField->placeholder = "Password";
  80. loginWidget->addChild(passwordField);
  81. pos.x += passwordField->box.size.x;
  82. struct LogInButton : Button {
  83. TextField *emailField;
  84. TextField *passwordField;
  85. void onAction(EventAction &e) override {
  86. std::thread t(pluginLogIn, emailField->text, passwordField->text);
  87. t.detach();
  88. passwordField->text = "";
  89. }
  90. };
  91. pos.x += margin;
  92. LogInButton *logInButton = new LogInButton();
  93. logInButton->box.pos = pos;
  94. logInButton->box.size.x = 100;
  95. logInButton->text = "Log in";
  96. logInButton->emailField = emailField;
  97. logInButton->passwordField = passwordField;
  98. loginWidget->addChild(logInButton);
  99. pos.x += logInButton->box.size.x;
  100. struct StatusLabel : Label {
  101. void step() override {
  102. text = pluginGetLoginStatus();
  103. }
  104. };
  105. Label *label = new StatusLabel();
  106. label->box.pos = pos;
  107. loginWidget->addChild(label);
  108. addChild(loginWidget);
  109. }
  110. {
  111. manageWidget = new Widget();
  112. Vec pos = Vec(0, 0);
  113. struct ManageButton : Button {
  114. void onAction(EventAction &e) override {
  115. std::thread t([&]() {
  116. systemOpenBrowser("https://vcvrack.com/");
  117. });
  118. t.detach();
  119. }
  120. };
  121. Button *manageButton = new ManageButton();
  122. manageButton->box.pos = pos;
  123. manageButton->box.size.x = 125;
  124. manageButton->text = "Manage plugins";
  125. manageWidget->addChild(manageButton);
  126. pos.x += manageButton->box.size.x;
  127. pos.x += margin;
  128. Button *syncButton = new SyncButton();
  129. syncButton->box.pos = pos;
  130. syncButton->box.size.x = 125;
  131. syncButton->text = "Update plugins";
  132. manageWidget->addChild(syncButton);
  133. pos.x += syncButton->box.size.x;
  134. struct LogOutButton : Button {
  135. void onAction(EventAction &e) override {
  136. pluginLogOut();
  137. }
  138. };
  139. pos.x += margin;
  140. Button *logOutButton = new LogOutButton();
  141. logOutButton->box.pos = pos;
  142. logOutButton->box.size.x = 100;
  143. logOutButton->text = "Log out";
  144. manageWidget->addChild(logOutButton);
  145. addChild(manageWidget);
  146. }
  147. {
  148. downloadWidget = new Widget();
  149. Vec pos = Vec(0, 0);
  150. struct DownloadProgressBar : ProgressBar {
  151. void step() override {
  152. label = "Downloading";
  153. std::string name = pluginGetDownloadName();
  154. if (name != "")
  155. label += " " + name;
  156. setValue(100.0 * pluginGetDownloadProgress());
  157. }
  158. };
  159. ProgressBar *downloadProgress = new DownloadProgressBar();
  160. downloadProgress->box.pos = pos;
  161. downloadProgress->box.size.x = 300;
  162. downloadProgress->setLimits(0, 100);
  163. downloadProgress->unit = "%";
  164. downloadWidget->addChild(downloadProgress);
  165. pos.x += downloadProgress->box.size.x;
  166. // struct CancelButton : Button {
  167. // void onAction(EventAction &e) override {
  168. // pluginCancelDownload();
  169. // }
  170. // };
  171. // pos.x += margin;
  172. // Button *logOutButton = new CancelButton();
  173. // logOutButton->box.pos = pos;
  174. // logOutButton->box.size.x = 100;
  175. // logOutButton->text = "Cancel";
  176. // downloadWidget->addChild(logOutButton);
  177. addChild(downloadWidget);
  178. }
  179. }
  180. void PluginManagerWidget::step() {
  181. loginWidget->visible = false;
  182. manageWidget->visible = false;
  183. downloadWidget->visible = false;
  184. if (pluginIsDownloading())
  185. downloadWidget->visible = true;
  186. else if (pluginIsLoggedIn())
  187. manageWidget->visible = true;
  188. else
  189. loginWidget->visible = true;
  190. Widget::step();
  191. }
  192. } // namespace rack