Browse Source

Clean up `library::` app updater a bit.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
a77f47dc52
4 changed files with 53 additions and 98 deletions
  1. +8
    -9
      include/library.hpp
  2. +13
    -22
      src/app/MenuBar.cpp
  3. +31
    -67
      src/library.cpp
  4. +1
    -0
      standalone/main.cpp

+ 8
- 9
include/library.hpp View File

@@ -21,26 +21,25 @@ struct Update {
};


extern std::string version;
extern std::string changelogUrl;
extern float progress;

void init();
void destroy();

bool isAppUpdateAvailable();

bool isLoggedIn();
void logIn(const std::string& email, const std::string& password);
void logOut();
bool isUpdateAvailable();
void queryUpdates();
bool hasUpdates();
void syncUpdate(Update* update);
void syncUpdates();
bool isSyncing();
/** Updates Rack automatically or opens the browser to the URL.
Blocking. Call on a detached thread.
*/
void update();


extern std::string appVersion;
extern std::string appDownloadUrl;
extern std::string appChangelogUrl;

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


+ 13
- 22
src/app/MenuBar.cpp View File

@@ -817,30 +817,21 @@ struct LibraryButton : MenuButton {
// Help
////////////////////

struct UpdateItem : ui::MenuItem {
struct AppUpdateItem : ui::MenuItem {
ui::Menu* createChildMenu() override {
ui::Menu* menu = new ui::Menu;

UrlItem* changelogUrl = new UrlItem;
changelogUrl->text = "Changelog";
changelogUrl->url = library::changelogUrl;
menu->addChild(changelogUrl);
UrlItem* changelogItem = new UrlItem;
changelogItem->text = "Changelog";
changelogItem->url = library::appChangelogUrl;
menu->addChild(changelogItem);

return menu;
}

void step() override {
if (library::progress > 0) {
rightText = string::f("%.0f%%", library::progress * 100.f);
}
MenuItem::step();
}

void onAction(const event::Action& e) override {
std::thread t([ = ] {
library::update();
});
t.detach();
system::openBrowser(library::appDownloadUrl);
APP->window->close();
e.consume(NULL);
}
};
@@ -859,11 +850,11 @@ struct HelpButton : MenuButton {
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;

if (library::isUpdateAvailable()) {
UpdateItem* updateItem = new UpdateItem;
updateItem->text = "Update " + APP_NAME;
updateItem->rightText = APP_VERSION + " → " + library::version;
menu->addChild(updateItem);
if (library::isAppUpdateAvailable()) {
AppUpdateItem* appUpdateItem = new AppUpdateItem;
appUpdateItem->text = "Update " + APP_NAME;
appUpdateItem->rightText = APP_VERSION + " → " + library::appVersion;
menu->addChild(appUpdateItem);
}

UrlItem* manualItem = new UrlItem;
@@ -885,7 +876,7 @@ struct HelpButton : MenuButton {

void step() override {
notification->box.pos = math::Vec(0, 0);
notification->visible = library::isUpdateAvailable();
notification->visible = library::isAppUpdateAvailable();
MenuButton::step();
}
};


+ 31
- 67
src/library.cpp View File

@@ -16,13 +16,30 @@ namespace rack {
namespace library {


std::string version;
std::string changelogUrl;
float progress = 0.f;
static std::string downloadUrl;
static void queryAppUpdate();


static void checkVersion() {
void init() {
if (settings::devMode)
return;

std::thread t([&]() {
queryAppUpdate();
});
t.detach();

std::thread t2([&] {
queryUpdates();
});
t2.detach();
}


void destroy() {
}


static void queryAppUpdate() {
std::string versionUrl = API_URL + "/version";
json_t* resJ = network::requestJson(network::METHOD_GET, versionUrl, NULL);
if (!resJ) {
@@ -33,37 +50,23 @@ static void checkVersion() {

json_t* versionJ = json_object_get(resJ, "version");
if (versionJ)
version = json_string_value(versionJ);
appVersion = json_string_value(versionJ);

json_t* changelogUrlJ = json_object_get(resJ, "changelogUrl");
if (changelogUrlJ)
changelogUrl = json_string_value(changelogUrlJ);
appChangelogUrl = json_string_value(changelogUrlJ);

json_t* downloadUrlsJ = json_object_get(resJ, "downloadUrls");
if (downloadUrlsJ) {
json_t* downloadUrlJ = json_object_get(downloadUrlsJ, APP_ARCH.c_str());
if (downloadUrlJ)
downloadUrl = json_string_value(downloadUrlJ);
appDownloadUrl = json_string_value(downloadUrlJ);
}
}


void init() {
if (settings::devMode)
return;

std::thread t([]() {
checkVersion();
});
t.detach();

// Sync in a detached thread
if (!settings::devMode) {
std::thread t([] {
queryUpdates();
});
t.detach();
}
bool isAppUpdateAvailable() {
return (appVersion != "") && (appVersion != APP_VERSION);
}


@@ -115,49 +118,6 @@ void logOut() {
}


void update() {
if (downloadUrl == "")
return;

// Download update
// HACK getFilename is only supposed to be used for filesystem paths, not URLs.
std::string filename = system::getFilename(network::urlPath(downloadUrl));
std::string path = asset::user(filename);
INFO("Downloading update %s to %s", downloadUrl.c_str(), path.c_str());
network::requestDownload(downloadUrl, path, &progress);

#if defined ARCH_WIN
// Launch the installer
INFO("Launching update %s", path.c_str());
system::runProcessDetached(path);
#elif defined ARCH_MAC
std::string cmd;
// std::string appPath = system::join(asset::userDir, "Rack.app");
// cmd = "rm -rf '" + appPath + "'";
// std::system(cmd.c_str());
// // Unzip app using Apple's unzipper, since Rack's unzipper doesn't handle the metadata stuff correctly.
// cmd = "unzip -q '" + path + "' -d '" + asset::userDir + "'";
// std::system(cmd.c_str());
// // Open app in Finder
// cmd = "open -R '" + appPath + "'";
// std::system(cmd.c_str());

// Open Archive Utility
cmd = "open '" + path + "'";
std::system(cmd.c_str());
#elif defined ARCH_LIN
system::openFolder(asset::user(""));
#endif

APP->window->close();
}


bool isUpdateAvailable() {
return (version != "") && (version != APP_VERSION);
}


void queryUpdates() {
if (settings::token.empty())
return;
@@ -354,6 +314,10 @@ std::vector<Update> updates;
std::string updateStatus;
bool restartRequested = false;

std::string appVersion;
std::string appDownloadUrl;
std::string appChangelogUrl;


} // namespace library
} // namespace rack

+ 1
- 0
standalone/main.cpp View File

@@ -245,6 +245,7 @@ int main(int argc, char* argv[]) {
windowDestroy();
ui::destroy();
}
library::destroy();
midi::destroy();
audio::destroy();
plugin::destroy();


Loading…
Cancel
Save