Integrated update check into SettingsLayout.

This commit is contained in:
Casey Langen 2017-06-28 02:24:21 -07:00
parent bdb62b405a
commit 8a2acda512
7 changed files with 91 additions and 24 deletions

View File

@ -62,6 +62,7 @@ set (musikbox_LINK_LIBS
${linux_LINK_LIBS}
${BOOST_LINK_LIBS}
dl
curl
)
include_directories (

View File

@ -293,27 +293,7 @@ void MainLayout::OnIndexerFinished(int count) {
void MainLayout::RunUpdateCheck() {
updateCheck.Run([this](bool updateRequired, std::string version, std::string url) {
if (updateRequired) {
std::string prefKey = prefs::keys::LastAcknowledgedUpdateVersion;
std::string acknowledged = this->prefs->GetString(prefKey);
if (acknowledged != version) {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
std::string message = boost::str(boost::format(
_TSTR("update_check_dialog_message")) % version % url);
(*dialog)
.SetTitle(_TSTR("update_check_dialog_title"))
.SetMessage(message)
.AddButton(
"KEY_ENTER", "ENTER", _TSTR("button_dont_remind_me"),
[this, prefKey, version](std::string key) {
this->prefs->SetString(prefKey.c_str(), version.c_str());
this->prefs->Save();
})
.AddButton("^[", "ESC", _TSTR("button_remind_me_later"));
App::Overlays().Push(dialog);
}
UpdateCheck::ShowUpgradeAvailableOverlay(version, url);
}
});
}

View File

@ -48,6 +48,7 @@
#include <app/util/Hotkeys.h>
#include <app/util/PreferenceKeys.h>
#include <app/util/UpdateCheck.h>
#include <app/overlay/ColorThemeOverlay.h>
#include <app/overlay/LocaleOverlay.h>
#include <app/overlay/PlaybackOverlays.h>
@ -95,6 +96,8 @@ using EntryPtr = IScrollAdapter::EntryPtr;
static const std::string arrow = "\xe2\x96\xba ";
static bool showDotfiles = false;
static UpdateCheck updateCheck;
SettingsLayout::SettingsLayout(
cursespp::App& app,
musik::core::ILibraryPtr library,
@ -115,6 +118,7 @@ SettingsLayout::SettingsLayout(
}
SettingsLayout::~SettingsLayout() {
updateCheck.Cancel();
}
void SettingsLayout::OnCheckboxChanged(cursespp::Checkbox* cb, bool checked) {
@ -207,6 +211,17 @@ void SettingsLayout::OnServerDropdownActivate(cursespp::TextLabel* label) {
ServerOverlay::Show([this]() { /* nothing, for now */ });
}
void SettingsLayout::OnUpdateDropdownActivate(cursespp::TextLabel* label) {
updateCheck.Run([this](bool updateRequired, std::string version, std::string url) {
if (updateRequired) {
UpdateCheck::ShowUpgradeAvailableOverlay(version, url, false);
}
else {
UpdateCheck::ShowNoUpgradeFoundOverlay();
}
});
}
void SettingsLayout::OnThemeDropdownActivate(cursespp::TextLabel* label) {
ColorThemeOverlay::Show([this]() { this->LoadPreferences(); });
}
@ -260,6 +275,9 @@ void SettingsLayout::OnLayout() {
this->minimizeToTrayCheckbox->MoveAndResize(column2, y++, columnCx, LABEL_HEIGHT);
this->startMinimizedCheckbox->MoveAndResize(column2, y++, columnCx, LABEL_HEIGHT);
#endif
++y;
this->updateDropdown->MoveAndResize(column2, y++, columnCx, LABEL_HEIGHT);
}
void SettingsLayout::RefreshAddedPaths() {
@ -358,6 +376,10 @@ void SettingsLayout::InitializeWindows() {
CREATE_CHECKBOX(this->startMinimizedCheckbox, _TSTR("settings_start_minimized"));
#endif
this->updateDropdown.reset(new TextLabel());
this->updateDropdown->SetText(arrow + _TSTR("settings_check_for_updates"));
this->updateDropdown->Activated.connect(this, &SettingsLayout::OnUpdateDropdownActivate);
int order = 0;
this->browseList->SetFocusOrder(order++);
this->addedPathsList->SetFocusOrder(order++);
@ -383,6 +405,7 @@ void SettingsLayout::InitializeWindows() {
this->minimizeToTrayCheckbox->SetFocusOrder(order++);
this->startMinimizedCheckbox->SetFocusOrder(order++);
#endif
this->updateDropdown->SetFocusOrder(order++);
this->AddWindow(this->browseLabel);
this->AddWindow(this->addedPathsLabel);
@ -410,6 +433,7 @@ void SettingsLayout::InitializeWindows() {
this->AddWindow(this->minimizeToTrayCheckbox);
this->AddWindow(this->startMinimizedCheckbox);
#endif
this->AddWindow(updateDropdown);
}
void SettingsLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) {

View File

@ -105,6 +105,7 @@ namespace musik {
void OnThemeDropdownActivate(cursespp::TextLabel* label);
void OnLocaleDropdownActivate(cursespp::TextLabel* label);
void OnServerDropdownActivate(cursespp::TextLabel* label);
void OnUpdateDropdownActivate(cursespp::TextLabel* label);
int64_t ListItemDecorator(
cursespp::ScrollableWindow* w,
@ -126,6 +127,7 @@ namespace musik {
std::shared_ptr<cursespp::TextLabel> pluginsDropdown;
std::shared_ptr<cursespp::TextLabel> hotkeyDropdown;
std::shared_ptr<cursespp::TextLabel> serverDropdown;
std::shared_ptr<cursespp::TextLabel> updateDropdown;
std::shared_ptr<cursespp::TextLabel> themeDropdown;
std::shared_ptr<cursespp::Checkbox> paletteCheckbox;

View File

@ -36,14 +36,21 @@
#include "UpdateCheck.h"
#include <json.hpp>
#include <cursespp/App.h>
#include <cursespp/Window.h>
#include <app/util/Messages.h>
#include <app/util/Version.h>
#include <cursespp/DialogOverlay.h>
#include <core/runtime/Message.h>
#include <app/util/Messages.h>
#include <app/util/PreferenceKeys.h>
#include <app/util/Version.h>
using namespace nlohmann;
using namespace musik::box;
using namespace musik::core;
using namespace musik::core::runtime;
using namespace cursespp;
static const std::string UPDATE_CHECK_URL = "https://musikcube.com/version";
static const std::string LATEST = "latest";
@ -189,4 +196,49 @@ void UpdateCheck::ProcessMessage(IMessage &message) {
callback(updateRequired, this->latestVersion, this->updateUrl);
}
}
}
void UpdateCheck::ShowUpgradeAvailableOverlay(
const std::string& version, const std::string& url, bool silent)
{
auto prefs = Preferences::ForComponent("settings");
std::string prefKey = prefs::keys::LastAcknowledgedUpdateVersion;
std::string acknowledged = prefs->GetString(prefKey);
if (!silent || acknowledged != version) {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
std::string message = boost::str(boost::format(
_TSTR("update_check_dialog_message")) % version % url);
(*dialog)
.SetTitle(_TSTR("update_check_dialog_title"))
.SetMessage(message);
if (silent) {
dialog->AddButton(
"KEY_ENTER", "ENTER", _TSTR("button_dont_remind_me"),
[prefs, prefKey, version](std::string key) {
prefs->SetString(prefKey.c_str(), version.c_str());
prefs->Save();
});
dialog->AddButton("^[", "ESC", _TSTR("button_remind_me_later"));
}
else {
dialog->AddButton("KEY_ENTER", "ENTER", _TSTR("ok"));
}
App::Overlays().Push(dialog);
}
}
void UpdateCheck::ShowNoUpgradeFoundOverlay() {
std::shared_ptr<DialogOverlay> dialog(new DialogOverlay());
(*dialog)
.SetTitle(_TSTR("update_check_no_updates_title"))
.SetMessage(_TSTR("update_check_no_updates_message"))
.AddButton("KEY_ENTER", "ENTER", _TSTR("button_close"));
App::Overlays().Push(dialog);
}

View File

@ -43,6 +43,11 @@ namespace musik { namespace box {
/* args = updateRequired, version, url */
using Callback = std::function<void(bool, std::string, std::string)>;
static void ShowUpgradeAvailableOverlay(
const std::string& version, const std::string& url, bool silent = true);
static void ShowNoUpgradeFoundOverlay();
UpdateCheck();
bool Run(Callback callback);
void Cancel();

View File

@ -44,6 +44,7 @@
"settings_minimize_to_tray": "minimize to tray",
"settings_start_minimized": "start minimized",
"settings_server_setup": "server setup",
"settings_check_for_updates": "check for updates",
"settings_server_enable_websockets": "metadata server enabled",
"settings_server_enable_http": "audio streaming enabled",
@ -124,7 +125,9 @@
"main_syncing_banner": "syncing metadata (%d tracks processed)",
"update_check_dialog_title": "new version available!",
"update_check_dialog_message": "musikbox version '%s' is now available for download. a changelog and binaries are available at:\n\n%s"
"update_check_dialog_message": "musikbox version '%s' is now available for download. a changelog and binaries are available at:\n\n%s",
"update_check_no_updates_title": "update check",
"update_check_no_updates_message": "no updates found at this time."
},
"dimensions": {