Browse Source

Plugin Manager menu progress.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
149f7f0e2b
4 changed files with 107 additions and 95 deletions
  1. +3
    -2
      include/helpers.hpp
  2. +4
    -4
      include/plugin.hpp
  3. +76
    -71
      src/app/MenuBar.cpp
  4. +24
    -18
      src/plugin.cpp

+ 3
- 2
include/helpers.hpp View File

@@ -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 <class TMenu = ui::Menu>
TMenu *createMenu() {
TMenu *o = new TMenu;
o->box.pos = APP->window->mousePos;

ui::MenuOverlay *menuOverlay = new ui::MenuOverlay;


+ 4
- 4
include/plugin.hpp View File

@@ -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<std::string> allowedTags;
extern std::vector<Plugin*> plugins;
extern bool isDownloading;

extern std::string loginStatus;
extern float downloadProgress;
extern std::string downloadName;
extern std::string loginStatus;


} // namespace plugin


+ 76
- 71
src/app/MenuBar.cpp View File

@@ -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<PluginsMenu>();
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


+ 24
- 18
src/plugin.cpp View File

@@ -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<Plugin*> plugins;
bool isDownloading = false;

std::string loginStatus;
float downloadProgress = 0.f;
std::string downloadName;
std::string loginStatus;


} // namespace plugin


Loading…
Cancel
Save