Browse Source

Check library updates when Library menu is opened or user logs in.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
1dfd3b6535
3 changed files with 24 additions and 36 deletions
  1. +4
    -2
      include/library.hpp
  2. +11
    -28
      src/app/MenuBar.cpp
  3. +9
    -6
      src/library.cpp

+ 4
- 2
include/library.hpp View File

@@ -24,11 +24,11 @@ void checkAppUpdate();
bool isAppUpdateAvailable();

bool isLoggedIn();
void logIn(const std::string& email, const std::string& password);
void logIn(std::string email, std::string password);
void logOut();
void checkUpdates();
bool hasUpdates();
void syncUpdate(const std::string& slug);
void syncUpdate(std::string slug);
void syncUpdates();


@@ -46,6 +46,8 @@ extern float updateProgress;
extern bool isSyncing;
/** Whether the UI should ask the user to restart after updating plugins. */
extern bool restartRequested;
/** Whether the UI should refresh the plugin updates menu. */
extern bool refreshRequested;


} // namespace library


+ 11
- 28
src/app/MenuBar.cpp View File

@@ -541,9 +541,6 @@ struct EngineButton : MenuButton {
////////////////////


static bool isLoggingIn = false;


struct AccountPasswordField : ui::PasswordField {
ui::MenuItem* logInItem;
void onAction(const ActionEvent& e) override {
@@ -557,19 +554,17 @@ struct LogInItem : ui::MenuItem {
ui::TextField* passwordField;

void onAction(const ActionEvent& e) override {
isLoggingIn = true;
std::string email = emailField->text;
std::string password = passwordField->text;
std::thread t([=] {
library::logIn(email, password);
isLoggingIn = false;
library::checkUpdates();
});
t.detach();
e.unconsume();
}

void step() override {
disabled = isLoggingIn;
text = "Log in";
rightText = library::loginStatus;
MenuItem::step();
@@ -677,16 +672,16 @@ struct SyncUpdateItem : ui::MenuItem {


struct LibraryMenu : ui::Menu {
bool loggedIn = false;

LibraryMenu() {
refresh();
}

void step() override {
// Refresh menu when appropriate
if (!loggedIn && library::isLoggedIn())
if (library::refreshRequested) {
library::refreshRequested = false;
refresh();
}
Menu::step();
}

@@ -721,8 +716,6 @@ struct LibraryMenu : ui::Menu {
addChild(logInItem);
}
else {
loggedIn = true;

addChild(createMenuItem("Log out", "", [=]() {
library::logOut();
}));
@@ -737,10 +730,7 @@ struct LibraryMenu : ui::Menu {

if (!library::updateInfos.empty()) {
addChild(new ui::MenuSeparator);

ui::MenuLabel* updatesLabel = new ui::MenuLabel;
updatesLabel->text = "Updates";
addChild(updatesLabel);
addChild(createMenuLabel("Updates"));

for (auto& pair : library::updateInfos) {
SyncUpdateItem* updateItem = new SyncUpdateItem;
@@ -748,19 +738,6 @@ struct LibraryMenu : ui::Menu {
addChild(updateItem);
}
}
else if (!settings::autoCheckUpdates) {
struct CheckUpdatesItem : ui::MenuItem {
void onAction(const ActionEvent& e) override {
std::thread t([&] {
library::checkUpdates();
});
t.detach();
}
};
CheckUpdatesItem* checkUpdatesItem = new CheckUpdatesItem;
checkUpdatesItem->text = "Check for updates";
addChild(checkUpdatesItem);
}
}
}
};
@@ -778,6 +755,12 @@ struct LibraryButton : MenuButton {
ui::Menu* menu = createMenu<LibraryMenu>();
menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
// Check for updates when menu is opened
std::thread t([&]() {
system::setThreadName("Library");
library::checkUpdates();
});
t.detach();
}

void step() override {


+ 9
- 6
src/library.cpp View File

@@ -25,6 +25,7 @@ static std::mutex updateMutex;
void init() {
if (settings::autoCheckUpdates && !settings::devMode) {
std::thread t([&]() {
system::setThreadName("Library");
// checkAppUpdate();
checkUpdates();
});
@@ -88,7 +89,7 @@ bool isLoggedIn() {
}


void logIn(const std::string& email, const std::string& password) {
void logIn(std::string email, std::string password) {
if (!updateMutex.try_lock())
return;
DEFER({updateMutex.unlock();});
@@ -123,7 +124,7 @@ void logIn(const std::string& email, const std::string& password) {
const char* tokenStr = json_string_value(tokenJ);
settings::token = tokenStr;
loginStatus = "";
checkUpdates();
refreshRequested = true;
}


@@ -218,9 +219,9 @@ void checkUpdates() {
}
update.version = json_string_value(versionJ);
// Reject plugins with ABI mismatch
if (!string::startsWith(update.version, APP_VERSION_MAJOR + ".")) {
continue;
}
// if (!string::startsWith(update.version, APP_VERSION_MAJOR + ".")) {
// continue;
// }

// Check if update is needed
plugin::Plugin* p = plugin::getPlugin(slug);
@@ -274,6 +275,7 @@ void checkUpdates() {
// }

updateStatus = "";
refreshRequested = true;
}


@@ -286,7 +288,7 @@ bool hasUpdates() {
}


void syncUpdate(const std::string& slug) {
void syncUpdate(std::string slug) {
if (!updateMutex.try_lock())
return;
DEFER({updateMutex.unlock();});
@@ -360,6 +362,7 @@ std::string updateSlug;
float updateProgress = 0.f;
bool isSyncing = false;
bool restartRequested = false;
bool refreshRequested = false;


} // namespace library


Loading…
Cancel
Save