Browse Source

Open changelog in browser if UpdateItem is clicked in the plugin menubar.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
9d6ee7c070
3 changed files with 25 additions and 7 deletions
  1. +1
    -0
      include/plugin.hpp
  2. +14
    -3
      src/app/MenuBar.cpp
  3. +10
    -4
      src/plugin.cpp

+ 1
- 0
include/plugin.hpp View File

@@ -17,6 +17,7 @@ namespace plugin {
struct Update { struct Update {
std::string pluginSlug; std::string pluginSlug;
std::string version; std::string version;
std::string changelogUrl;
}; };






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

@@ -487,6 +487,16 @@ struct SyncItem : ui::MenuItem {
} }
}; };


struct UpdateItem : ui::MenuItem {
std::string changelogUrl;
void onAction(const event::Action &e) override {
std::thread t([=]() {
system::openBrowser(changelogUrl);
});
t.detach();
}
};

#if 0 #if 0
struct SyncButton : ui::Button { struct SyncButton : ui::Button {
bool checked = false; bool checked = false;
@@ -579,18 +589,19 @@ struct PluginsMenu : ui::Menu {
addChild(new ui::MenuEntry); addChild(new ui::MenuEntry);


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


for (plugin::Update &update : plugin::updates) { for (plugin::Update &update : plugin::updates) {
ui::MenuItem *updateItem = new ui::MenuItem;
updateItem->disabled = true;
UpdateItem *updateItem = new UpdateItem;
updateItem->text = update.pluginSlug; updateItem->text = update.pluginSlug;
plugin::Plugin *p = plugin::getPlugin(update.pluginSlug); plugin::Plugin *p = plugin::getPlugin(update.pluginSlug);
if (p) { if (p) {
updateItem->rightText += "v" + p->version + " → "; updateItem->rightText += "v" + p->version + " → ";
} }
updateItem->rightText += "v" + update.version; updateItem->rightText += "v" + update.version;
updateItem->changelogUrl = update.changelogUrl;
updateItem->disabled = update.changelogUrl.empty();
addChild(updateItem); addChild(updateItem);
} }
} }


+ 10
- 4
src/plugin.cpp View File

@@ -496,6 +496,11 @@ void queryUpdates() {
} }
update.version = json_string_value(versionJ); update.version = json_string_value(versionJ);


// Check if update is needed
Plugin *p = getPlugin(update.pluginSlug);
if (p && p->version == update.version)
continue;

// Check status // Check status
json_t *statusJ = json_object_get(manifestJ, "status"); json_t *statusJ = json_object_get(manifestJ, "status");
if (!statusJ) if (!statusJ)
@@ -504,10 +509,11 @@ void queryUpdates() {
if (status != "available") if (status != "available")
continue; continue;


// Check if update is needed
Plugin *p = getPlugin(update.pluginSlug);
if (p && p->version == update.version)
continue;
// Get changelog URL
json_t *changelogUrlJ = json_object_get(manifestJ, "changelogUrl");
if (changelogUrlJ) {
update.changelogUrl = json_string_value(changelogUrlJ);
}


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


Loading…
Cancel
Save