Browse Source

Improve behavior of "Update all" button.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
68fbec5d6c
3 changed files with 28 additions and 6 deletions
  1. +2
    -1
      include/plugin.hpp
  2. +16
    -3
      src/app/MenuBar.cpp
  3. +10
    -2
      src/plugin.cpp

+ 2
- 1
include/plugin.hpp View File

@@ -47,7 +47,8 @@ extern std::vector<Plugin*> plugins;


extern std::string loginStatus; extern std::string loginStatus;
extern std::vector<Update> updates; extern std::vector<Update> updates;
extern bool updatesFinished;
extern std::string updateStatus;
extern bool restartRequested;




} // namespace plugin } // namespace plugin


+ 16
- 3
src/app/MenuBar.cpp View File

@@ -497,7 +497,20 @@ struct LogInItem : ui::MenuItem {


struct SyncItem : ui::MenuItem { struct SyncItem : ui::MenuItem {
void step() override { void step() override {
disabled = !plugin::hasUpdates() || plugin::isSyncing();
disabled = true;
if (plugin::updateStatus != "") {
text = plugin::updateStatus;
}
else if (plugin::isSyncing()) {
text = "Updating...";
}
else if (!plugin::hasUpdates()) {
text = "No updates";
}
else {
text = "Update all";
disabled = false;
}
MenuItem::step(); MenuItem::step();
} }


@@ -661,8 +674,8 @@ struct LibraryButton : MenuButton {
notification->visible = plugin::hasUpdates(); notification->visible = plugin::hasUpdates();


// Popup when updates finish downloading // Popup when updates finish downloading
if (plugin::updatesFinished) {
plugin::updatesFinished = false;
if (plugin::restartRequested) {
plugin::restartRequested = false;
if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "All plugins have been downloaded. Close and re-launch Rack to load new updates.")) { if (osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "All plugins have been downloaded. Close and re-launch Rack to load new updates.")) {
APP->window->close(); APP->window->close();
} }


+ 10
- 2
src/plugin.cpp View File

@@ -351,7 +351,9 @@ bool isLoggedIn() {
void queryUpdates() { void queryUpdates() {
if (settings::token.empty()) if (settings::token.empty())
return; return;

updates.clear(); updates.clear();
updateStatus = "Querying for updates...";


// Get user's plugins list // Get user's plugins list
std::string pluginsUrl = app::API_URL + "/plugins"; std::string pluginsUrl = app::API_URL + "/plugins";
@@ -361,6 +363,7 @@ void queryUpdates() {
json_decref(pluginsReqJ); json_decref(pluginsReqJ);
if (!pluginsResJ) { if (!pluginsResJ) {
WARN("Request for user's plugins failed"); WARN("Request for user's plugins failed");
updateStatus = "Could not query updates";
return; return;
} }
DEFER({ DEFER({
@@ -370,6 +373,7 @@ void queryUpdates() {
json_t *errorJ = json_object_get(pluginsResJ, "error"); json_t *errorJ = json_object_get(pluginsResJ, "error");
if (errorJ) { if (errorJ) {
WARN("Request for user's plugins returned an error: %s", json_string_value(errorJ)); WARN("Request for user's plugins returned an error: %s", json_string_value(errorJ));
updateStatus = "Could not query updates";
return; return;
} }


@@ -381,6 +385,7 @@ void queryUpdates() {
json_decref(manifestsReq); json_decref(manifestsReq);
if (!manifestsResJ) { if (!manifestsResJ) {
WARN("Request for library manifests failed"); WARN("Request for library manifests failed");
updateStatus = "Could not query updates";
return; return;
} }
DEFER({ DEFER({
@@ -436,6 +441,8 @@ void queryUpdates() {


updates.push_back(update); updates.push_back(update);
} }

updateStatus = "";
} }


bool hasUpdates() { bool hasUpdates() {
@@ -492,7 +499,7 @@ void syncUpdates() {
if (update.progress < 1.f) if (update.progress < 1.f)
syncUpdate(&update); syncUpdate(&update);
} }
updatesFinished = true;
restartRequested = true;
} }


bool isSyncing() { bool isSyncing() {
@@ -641,7 +648,8 @@ std::vector<Plugin*> plugins;


std::string loginStatus; std::string loginStatus;
std::vector<Update> updates; std::vector<Update> updates;
bool updatesFinished = false;
std::string updateStatus;
bool restartRequested = false;




} // namespace plugin } // namespace plugin


Loading…
Cancel
Save