Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.4.3] Added image and actions to musesound update spec #24974

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ if (OS_IS_WIN)

elseif(OS_IS_LIN)

# add ssl support on local linux machine
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L /usr/local/lib -lcrypto -lssl")

if (MUSE_APP_INSTALL_SUFFIX)
set(MSCORE_OUTPUT_NAME "${EXECUTABLE_NAME}${MUSE_APP_INSTALL_SUFFIX}")
endif(MUSE_APP_INSTALL_SUFFIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ Progress MuseSoundsCheckUpdateServiceStub::updateProgress()
{
return Progress();
}

void MuseSoundsCheckUpdateServiceStub::openMuseHub()
{
}
2 changes: 0 additions & 2 deletions src/framework/stubs/update/musesoundscheckupdateservicestub.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class MuseSoundsCheckUpdateServiceStub : public IMuseSoundsCheckUpdateService
RetVal<ReleaseInfo> lastCheckResult() override;

Progress updateProgress() override;

void openMuseHub() override;
};
}

Expand Down
3 changes: 0 additions & 3 deletions src/framework/update/imusesoundscheckupdateservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define MUSE_UPDATE_IMUSESOUNDSCHECKUPDATESERVICE_H

#include "types/retval.h"
#include "io/path.h"
#include "progress.h"

#include "updatetypes.h"
Expand All @@ -44,8 +43,6 @@ class IMuseSoundsCheckUpdateService : MODULE_EXPORT_INTERFACE
virtual RetVal<ReleaseInfo> lastCheckResult() = 0;

virtual Progress updateProgress() = 0;

virtual void openMuseHub() = 0;
};
}

Expand Down
45 changes: 41 additions & 4 deletions src/framework/update/internal/musesoundscheckupdatescenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@
#include "musesoundscheckupdatescenario.h"

#include "global/concurrency/concurrent.h"
#include "global/defer.h"
#include "global/containers.h"
#include "global/stringutils.h"
#include "global/types/val.h"
#include "global/types/translatablestring.h"

#include "updateerrors.h"

#include "types/val.h"

#include "defer.h"
#include "log.h"

using namespace muse;
using namespace muse::update;
using namespace muse::actions;

static const char* DEFAULT_IMAGE_URL = "qrc:/qml/Muse/Update/resources/muse_sounds_promo.png";
static const TranslatableString DEFAULT_ACTION_TITLE("update", "Take me to Muse Hub");

void MuseSoundsCheckUpdateScenario::delayedInit()
{
if (service()->needCheckForUpdate() && multiInstancesProvider()->instances().size() == 1) {
Expand Down Expand Up @@ -141,6 +146,18 @@ void MuseSoundsCheckUpdateScenario::showReleaseInfo(const ReleaseInfo& info)
query.addParam("notes", Val(info.notes));
query.addParam("features", Val(info.additionInfo.at("features")));

if (info.actionTitle.empty()) {
query.addParam("actionTitle", Val(DEFAULT_ACTION_TITLE.qTranslated()));
} else {
query.addParam("actionTitle", Val(QString::fromStdString(info.actionTitle)));
}

if (info.imageUrl.empty()) {
query.addParam("imageUrl", Val(QString(DEFAULT_IMAGE_URL)));
} else {
query.addParam("imageUrl", Val(QString::fromStdString(info.imageUrl)));
}

RetVal<Val> rv = interactive()->open(query);
if (!rv.ret) {
LOGD() << rv.ret.toString();
Expand All @@ -150,6 +167,26 @@ void MuseSoundsCheckUpdateScenario::showReleaseInfo(const ReleaseInfo& info)
QString actionCode = rv.val.toQString();

if (actionCode == "openMuseHub") {
service()->openMuseHub();
tryOpenMuseHub(info.actions);
}
}

void MuseSoundsCheckUpdateScenario::tryOpenMuseHub(ValList actions) const
{
if (actions.empty()) {
LOGE() << "not actions to open Muse Hub";
return;
}

std::string action = muse::takeFirst(actions).toString();
LOGI() << "try open: " << action;

if (muse::strings::startsWith(action, "http")) { // or https
interactive()->openUrl(action);
return;
}

interactive()->openApp(muse::Uri(action)).onReject(this, [this, actions](int, const std::string&) {
tryOpenMuseHub(actions);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MuseSoundsCheckUpdateScenario : public IMuseSoundsCheckUpdateScenario, pub
void th_checkForUpdate();

void showReleaseInfo(const ReleaseInfo& info);
void tryOpenMuseHub(ValList actions) const;

bool m_checkProgress = false;
ProgressPtr m_checkProgressChannel = nullptr;
Expand Down
98 changes: 69 additions & 29 deletions src/framework/update/internal/musesoundscheckupdateservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@

#include "musesoundscheckupdateservice.h"

#include <QSslSocket>

#include <QBuffer>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonDocument>

#include "global/types/version.h"

#include "../updateerrors.h"
#include "types/version.h"

#include "defer.h"
#include "log.h"

static const muse::Uri MUSEHUB_APP_URI("musehub://?from=musescore");
static const muse::Uri MUSEHUB_APP_V1_URI("muse-hub://?from=musescore");
static const std::string MUSEHUB_WEB_URL = "https://www.musehub.com/";

using namespace muse::update;
using namespace muse::network;
Expand Down Expand Up @@ -118,42 +122,40 @@ muse::Progress MuseSoundsCheckUpdateService::updateProgress()
return m_updateProgress;
}

void MuseSoundsCheckUpdateService::openMuseHub()
{
auto openMuseHubWebsite = [this]() {
static const std::string MUSEHUB_URL = "https://www.musehub.com/";
interactive()->openUrl(MUSEHUB_URL);
};

#ifdef Q_OS_WIN
interactive()->openApp(MUSEHUB_APP_URI).onReject(this, [=](int, const std::string&) {
static const muse::Uri MUSEHUB_APP_V1_URI("muse-hub://?from=musescore");
interactive()->openApp(MUSEHUB_APP_V1_URI).onReject(this, [=](int, const std::string&) {
openMuseHubWebsite();
});
});
return;
#elif defined(Q_OS_MAC)
interactive()->openApp(MUSEHUB_APP_URI).onReject(this, [=](int, const std::string&) {
openMuseHubWebsite();
});
return;
#else
openMuseHubWebsite();
#endif
}

muse::RetVal<ReleaseInfo> MuseSoundsCheckUpdateService::parseRelease(const QByteArray& json) const
{
RetVal<ReleaseInfo> result;

QJsonParseError err;
QJsonDocument jsonDoc = QJsonDocument::fromJson(json, &err);
if (err.error != QJsonParseError::NoError || !jsonDoc.isObject()) {
LOGE() << "parse error: " << err.errorString();
result.ret = make_ret(Err::NoUpdate);
return result;
}

/*
{
"version": String,
"image_url": String, // it can be base64 data, like "data:image/png;base64,iVBORw0KGgoA......"
"content": {
"locale_code": {
"notes": String,
"features": [String]
"action_title": String // title of action button
}
},

// open app or web page url, try in order,
// like this ["musehub://?from=musescore", "muse-hub://?from=musescore", "https://www.musehub.com"]
"actions": {
"windows": [String],
"macos": [String],
"linux": [String]
}
}
*/

QJsonObject releaseObj = jsonDoc.object();

if (releaseObj.empty()) {
Expand Down Expand Up @@ -182,17 +184,55 @@ muse::RetVal<ReleaseInfo> MuseSoundsCheckUpdateService::parseRelease(const QByte
result.ret = make_ok();

result.val.version = releaseObj.value("version").toString().toStdString();
result.val.imageUrl = releaseObj.value("image_url").toString().toStdString();

result.val.notes = contentLocaleObj.value("notes").toString().toStdString();

ValList featuresList;
QJsonArray features = contentLocaleObj.value("features").toArray();
for (const QJsonValue& feature : features) {
featuresList.push_back(Val(feature.toString().toStdString()));
}

result.val.additionInfo.insert({ "features", Val(featuresList) });

result.val.actionTitle = contentLocaleObj.value("action_title").toString().toStdString();
QJsonObject actionsObj = releaseObj.value("actions").toObject();

#ifdef Q_OS_WIN
QJsonArray actionsArr = actionsObj.value("windows").toArray();
for (const QJsonValue& a : actionsArr) {
result.val.actions.push_back(Val(a.toString().toStdString()));
}

// def
if (result.val.actions.empty()) {
result.val.actions.push_back(Val(MUSEHUB_APP_URI.toString()));
result.val.actions.push_back(Val(MUSEHUB_APP_V1_URI.toString()));
result.val.actions.push_back(Val(MUSEHUB_WEB_URL));
}

#elif defined(Q_OS_MAC)
QJsonArray actionsArr = actionsObj.value("macos").toArray();
for (const QJsonValue& a : actionsArr) {
result.val.actions.push_back(Val(a.toString().toStdString()));
}

// def
if (result.val.actions.empty()) {
result.val.actions.push_back(Val(MUSEHUB_APP_URI.toString()));
result.val.actions.push_back(Val(MUSEHUB_WEB_URL));
}
#else
QJsonArray actionsArr = actionsObj.value("linux").toArray();
for (const QJsonValue& a : actionsArr) {
result.val.actions.push_back(Val(a.toString().toStdString()));
}

// def
if (result.val.actions.empty()) {
result.val.actions.push_back(Val(MUSEHUB_WEB_URL));
}
#endif

return result;
}

Expand Down
2 changes: 0 additions & 2 deletions src/framework/update/internal/musesoundscheckupdateservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class MuseSoundsCheckUpdateService : public IMuseSoundsCheckUpdateService, publi

Progress updateProgress() override;

void openMuseHub() override;

private:
RetVal<ReleaseInfo> parseRelease(const QByteArray& json) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ StyledDialogView {

property alias notes: view.notes
property alias features: featuresViewRepeater.model
property alias imageUrl: image.source
property alias actionTitle: buttons.defaultButtonName

contentWidth: 530
contentHeight: 510
Expand Down Expand Up @@ -77,8 +79,6 @@ StyledDialogView {

Layout.fillWidth: true
Layout.preferredHeight: 186

source: "qrc:/qml/Muse/Update/resources/muse_sounds_promo.png"
}

Item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Muse.UiComponents 1.0
RowLayout {
id: root

property string defaultButtonName: openMuseHubButton.text
property alias defaultButtonName: openMuseHubButton.text

property NavigationPanel navigationPanel: NavigationPanel {
name: "UpdateBottomPanel"
Expand Down Expand Up @@ -65,8 +65,6 @@ RowLayout {
Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: (root.width - root.spacing) / 2

text: qsTrc("update", "Take me to Muse Hub")

accentButton: true

navigation.name: "OpenMuseHubButton"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/framework/update/updatetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ struct ReleaseInfo {
std::string fileName;
std::string fileUrl;

std::string imageUrl; // it can be base64 data, like "data:image/png;base64,iVBORw0KGgoA......"
std::string notes;
PrevReleasesNotesList previousReleasesNotes;

ValMap additionInfo;

std::string actionTitle; // title of action button
ValList actions; // open app or web page url, try in order

bool isValid() const
{
return !version.empty();
Expand Down Expand Up @@ -92,7 +96,10 @@ static inline ValMap releaseInfoToValMap(const ReleaseInfo& info)
{ "fileUrl", Val(info.fileUrl) },
{ "notes", Val(info.notes) },
{ "previousReleasesNotes", Val(releasesNotesToValList(info.previousReleasesNotes)) },
{ "additionalInfo", Val(info.additionInfo) }
{ "additionalInfo", Val(info.additionInfo) },
{ "imageUrl", Val(info.imageUrl) },
{ "actionTitle", Val(info.actionTitle) },
{ "actions", Val(info.actions) },
};
}

Expand All @@ -105,6 +112,9 @@ static inline ReleaseInfo releaseInfoFromValMap(const ValMap& map)
info.notes = map.at("notes").toString();
info.previousReleasesNotes = releasesNotesFromValList(map.at("previousReleasesNotes").toList());
info.additionInfo = map.at("additionalInfo").toMap();
info.imageUrl = map.at("imageUrl").toString();
info.actionTitle = map.at("actionTitle").toString();
info.actions = map.at("actions").toList();

return info;
}
Expand Down