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 isAppUpdateAvailable();


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




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




} // namespace library } // 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 { struct AccountPasswordField : ui::PasswordField {
ui::MenuItem* logInItem; ui::MenuItem* logInItem;
void onAction(const ActionEvent& e) override { void onAction(const ActionEvent& e) override {
@@ -557,19 +554,17 @@ struct LogInItem : ui::MenuItem {
ui::TextField* passwordField; ui::TextField* passwordField;


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


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




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

LibraryMenu() { LibraryMenu() {
refresh(); refresh();
} }


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


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

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


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

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


for (auto& pair : library::updateInfos) { for (auto& pair : library::updateInfos) {
SyncUpdateItem* updateItem = new SyncUpdateItem; SyncUpdateItem* updateItem = new SyncUpdateItem;
@@ -748,19 +738,6 @@ struct LibraryMenu : ui::Menu {
addChild(updateItem); 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>(); ui::Menu* menu = createMenu<LibraryMenu>();
menu->cornerFlags = BND_CORNER_TOP; menu->cornerFlags = BND_CORNER_TOP;
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); 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 { void step() override {


+ 9
- 6
src/library.cpp View File

@@ -25,6 +25,7 @@ static std::mutex updateMutex;
void init() { void init() {
if (settings::autoCheckUpdates && !settings::devMode) { if (settings::autoCheckUpdates && !settings::devMode) {
std::thread t([&]() { std::thread t([&]() {
system::setThreadName("Library");
// checkAppUpdate(); // checkAppUpdate();
checkUpdates(); 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()) if (!updateMutex.try_lock())
return; return;
DEFER({updateMutex.unlock();}); DEFER({updateMutex.unlock();});
@@ -123,7 +124,7 @@ void logIn(const std::string& email, const std::string& password) {
const char* tokenStr = json_string_value(tokenJ); const char* tokenStr = json_string_value(tokenJ);
settings::token = tokenStr; settings::token = tokenStr;
loginStatus = ""; loginStatus = "";
checkUpdates();
refreshRequested = true;
} }




@@ -218,9 +219,9 @@ void checkUpdates() {
} }
update.version = json_string_value(versionJ); update.version = json_string_value(versionJ);
// Reject plugins with ABI mismatch // 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 // Check if update is needed
plugin::Plugin* p = plugin::getPlugin(slug); plugin::Plugin* p = plugin::getPlugin(slug);
@@ -274,6 +275,7 @@ void checkUpdates() {
// } // }


updateStatus = ""; updateStatus = "";
refreshRequested = true;
} }




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




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




} // namespace library } // namespace library


Loading…
Cancel
Save