From 149f7f0e2b2664753714ebb31fe6d08ff7a38f70 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 4 May 2019 03:09:37 -0400 Subject: [PATCH] Plugin Manager menu progress. --- include/helpers.hpp | 5 +- include/plugin.hpp | 8 +-- src/app/MenuBar.cpp | 147 +++++++++++++++++++++++--------------------- src/plugin.cpp | 42 +++++++------ 4 files changed, 107 insertions(+), 95 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 6486b960..057695d5 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -139,8 +139,9 @@ TMenuItem *createMenuItem(std::string text, std::string rightText = "") { return o; } -inline ui::Menu *createMenu() { - ui::Menu *o = new ui::Menu; +template +TMenu *createMenu() { + TMenu *o = new TMenu; o->box.pos = APP->window->mousePos; ui::MenuOverlay *menuOverlay = new ui::MenuOverlay; diff --git a/include/plugin.hpp b/include/plugin.hpp index 188b0c6c..e727bc44 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -18,8 +18,8 @@ void init(); void destroy(); void logIn(const std::string &email, const std::string &password); void logOut(); -/** Returns whether a new plugin is available, and downloads it unless doing a dry run */ -bool sync(bool dryRun); +void query(); +void sync(); void cancelDownload(); bool isLoggedIn(); Plugin *getPlugin(const std::string &pluginSlug); @@ -31,10 +31,10 @@ bool isSlugValid(const std::string &slug); extern const std::set allowedTags; extern std::vector plugins; -extern bool isDownloading; + +extern std::string loginStatus; extern float downloadProgress; extern std::string downloadName; -extern std::string loginStatus; } // namespace plugin diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index 3a13eee8..d1205242 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -414,33 +414,7 @@ struct EngineButton : MenuButton { // Plugins //////////////////// -struct PluginsButton : MenuButton { - ui::Menu *menu; - - void onAction(const event::Action &e) override { - menu = createMenu(); - menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); - menu->box.size.x = box.size.x; - - refresh(); - } - - void draw(const DrawArgs &args) override { - MenuButton::draw(args); - - if (0) { - // Notification circle - nvgBeginPath(args.vg); - nvgCircle(args.vg, 4, 2, 4.0); - nvgFillColor(args.vg, nvgRGBf(1.0, 0.0, 0.0)); - nvgFill(args.vg); - nvgStrokeColor(args.vg, nvgRGBf(0.5, 0.0, 0.0)); - nvgStroke(args.vg); - } - } - - void refresh(); -}; +static bool isLoggingIn = false; struct RegisterItem : ui::MenuItem { void onAction(const event::Action &e) override { @@ -481,24 +455,21 @@ struct LogInItem : ui::MenuItem { ui::TextField *emailField; ui::TextField *passwordField; void onAction(const event::Action &e) override { + isLoggingIn = true; std::string email = emailField->text; std::string password = passwordField->text; std::thread t([=]() { plugin::logIn(email, password); + isLoggingIn = false; }); t.detach(); e.consume(NULL); } void step() override { - if (plugin::loginStatus != "") { - text = plugin::loginStatus; - disabled = true; - } - else { - text = "Log in"; - disabled = false; - } + disabled = isLoggingIn; + text = "Log in"; + rightText = plugin::loginStatus; } }; @@ -577,51 +548,85 @@ struct DownloadQuantity : Quantity { std::string getUnit() override {return "%";} }; -void PluginsButton::refresh() { - menu->clearChildren(); +struct PluginsMenu : ui::Menu { + int state = 0; - if (plugin::isDownloading) { - ui::ProgressBar *downloadProgressBar = new ui::ProgressBar; - downloadProgressBar->quantity = new DownloadQuantity; - menu->addChild(downloadProgressBar); + PluginsMenu() { + refresh(); } - else if (plugin::isLoggedIn()) { - ManageItem *manageItem = new ManageItem; - manageItem->text = "Manage plugins"; - menu->addChild(manageItem); - SyncItem *syncItem = new SyncItem; - syncItem->text = "Sync plugins"; - syncItem->disabled = true; - menu->addChild(syncItem); + void step() override { + Menu::step(); + } - LogOutItem *logOutItem = new LogOutItem; - logOutItem->text = "Log out"; - menu->addChild(logOutItem); + void refresh() { + clearChildren(); + + if (0) { + ui::ProgressBar *downloadProgressBar = new ui::ProgressBar; + downloadProgressBar->quantity = new DownloadQuantity; + addChild(downloadProgressBar); + } + else if (plugin::isLoggedIn()) { + ManageItem *manageItem = new ManageItem; + manageItem->text = "Manage"; + addChild(manageItem); + + SyncItem *syncItem = new SyncItem; + syncItem->text = "Update all"; + syncItem->disabled = true; + addChild(syncItem); + + LogOutItem *logOutItem = new LogOutItem; + logOutItem->text = "Log out"; + addChild(logOutItem); + } + else { + RegisterItem *registerItem = new RegisterItem; + registerItem->text = "Register VCV account"; + addChild(registerItem); + + AccountEmailField *emailField = new AccountEmailField; + emailField->placeholder = "Email"; + emailField->box.size.x = 220.0; + addChild(emailField); + + AccountPasswordField *passwordField = new AccountPasswordField; + passwordField->placeholder = "Password"; + passwordField->box.size.x = 220.0; + emailField->passwordField = passwordField; + addChild(passwordField); + + LogInItem *logInItem = new LogInItem; + logInItem->emailField = emailField; + logInItem->passwordField = passwordField; + passwordField->logInItem = logInItem; + addChild(logInItem); + } } - else { - RegisterItem *registerItem = new RegisterItem; - registerItem->text = "Register VCV account"; - menu->addChild(registerItem); +}; - AccountEmailField *emailField = new AccountEmailField; - emailField->placeholder = "Email"; - emailField->box.size.x = 250.0; - menu->addChild(emailField); +struct PluginsButton : MenuButton { + void onAction(const event::Action &e) override { + ui::Menu *menu = createMenu(); + menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); + menu->box.size.x = box.size.x; + } - AccountPasswordField *passwordField = new AccountPasswordField; - passwordField->placeholder = "Password"; - passwordField->box.size.x = 250.0; - emailField->passwordField = passwordField; - menu->addChild(passwordField); + void draw(const DrawArgs &args) override { + MenuButton::draw(args); - LogInItem *logInItem = new LogInItem; - logInItem->emailField = emailField; - logInItem->passwordField = passwordField; - passwordField->logInItem = logInItem; - menu->addChild(logInItem); + if (0) { + // Notification circle + nvgBeginPath(args.vg); + nvgCircle(args.vg, 4, 2, 4.0); + nvgFillColor(args.vg, nvgRGBf(1.0, 0.0, 0.0)); + nvgFill(args.vg); + nvgStrokeColor(args.vg, nvgRGBf(0.5, 0.0, 0.0)); + nvgStroke(args.vg); + } } -} +}; //////////////////// // Help diff --git a/src/plugin.cpp b/src/plugin.cpp index 62f039f8..352cd084 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -420,20 +420,9 @@ void logOut() { settings::token = ""; } -bool sync(bool dryRun) { +void query() { if (settings::token.empty()) - return false; - - bool available = false; - - if (!dryRun) { - isDownloading = true; - downloadProgress = 0.0; - downloadName = "Updating plugins..."; - } - DEFER({ - isDownloading = false; - }); + return; // Get user's plugins list json_t *pluginsReqJ = json_object(); @@ -444,7 +433,7 @@ bool sync(bool dryRun) { json_decref(pluginsReqJ); if (!pluginsResJ) { WARN("Request for user's plugins failed"); - return false; + return; } DEFER({ json_decref(pluginsResJ); @@ -453,7 +442,7 @@ bool sync(bool dryRun) { json_t *errorJ = json_object_get(pluginsResJ, "error"); if (errorJ) { WARN("Request for user's plugins returned an error: %s", json_string_value(errorJ)); - return false; + return; } // Get community manifests @@ -462,12 +451,28 @@ bool sync(bool dryRun) { json_t *manifestsResJ = network::requestJson(network::GET, manifestsUrl, NULL); if (!manifestsResJ) { WARN("Request for community manifests failed"); - return false; + return; } DEFER({ json_decref(manifestsResJ); }); + json_dumpf(pluginsResJ, stderr, JSON_INDENT(2)); + json_dumpf(manifestsResJ, stderr, JSON_INDENT(2)); +} + +void sync() { +#if 0 + if (settings::token.empty()) + return false; + + bool available = false; + + if (!dryRun) { + downloadProgress = 0.0; + downloadName = "Updating plugins..."; + } + // Check each plugin in list of plugin slugs json_t *pluginsJ = json_object_get(pluginsResJ, "plugins"); if (!pluginsJ) { @@ -501,6 +506,7 @@ bool sync(bool dryRun) { } return available; +#endif } void cancelDownload() { @@ -639,10 +645,10 @@ bool isSlugValid(const std::string &slug) { std::vector plugins; -bool isDownloading = false; + +std::string loginStatus; float downloadProgress = 0.f; std::string downloadName; -std::string loginStatus; } // namespace plugin