mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-05 21:55:24 +00:00
Propagate server version back to the user when remote library connection fails due to incompatible versions.
This commit is contained in:
parent
c44343712d
commit
ad09b30b18
@ -138,8 +138,8 @@ WebSocketClient::WebSocketClient(IMessageQueue* messageQueue, Listener* listener
|
||||
auto ignoreVersionMismatch = prefs->GetInt(
|
||||
core::prefs::keys::RemoteLibraryIgnoreVersionMismatch, false);
|
||||
|
||||
auto appVersion = responseJson["options"]["environment"]["app_version"];
|
||||
if (!ignoreVersionMismatch && (!appVersion.is_string() || appVersion.get<std::string>() != VERSION)) {
|
||||
this->serverVersion = responseJson["options"]["environment"]["app_version"].get<std::string>();
|
||||
if (!ignoreVersionMismatch && this->serverVersion != VERSION) {
|
||||
this->SetDisconnected(ConnectionError::IncompatibleVersion);
|
||||
}
|
||||
else {
|
||||
@ -198,6 +198,11 @@ WebSocketClient::ConnectionError WebSocketClient::LastConnectionError() const {
|
||||
return this->connectionError;
|
||||
}
|
||||
|
||||
std::string WebSocketClient::LastServerVersion() const {
|
||||
std::unique_lock<decltype(this->mutex)> lock(this->mutex);
|
||||
return this->serverVersion;
|
||||
}
|
||||
|
||||
WebSocketClient::State WebSocketClient::ConnectionState() const {
|
||||
std::unique_lock<decltype(this->mutex)> lock(this->mutex);
|
||||
return this->state;
|
||||
@ -257,6 +262,7 @@ void WebSocketClient::Connect(
|
||||
|
||||
void WebSocketClient::Reconnect() {
|
||||
std::unique_lock<decltype(this->mutex)> lock(this->mutex);
|
||||
this->serverVersion = "";
|
||||
|
||||
this->Disconnect();
|
||||
|
||||
|
@ -104,6 +104,7 @@ namespace musik { namespace core { namespace net {
|
||||
|
||||
State ConnectionState() const;
|
||||
ConnectionError LastConnectionError() const;
|
||||
std::string LastServerVersion() const;
|
||||
std::string Uri() const;
|
||||
|
||||
std::string EnqueueQuery(Query query);
|
||||
@ -129,6 +130,7 @@ namespace musik { namespace core { namespace net {
|
||||
std::unordered_map<std::string, Query> messageIdToQuery;
|
||||
std::atomic<bool> quit{ false };
|
||||
ConnectionError connectionError{ ConnectionError::None };
|
||||
std::string serverVersion;
|
||||
State state{ State::Disconnected };
|
||||
Listener* listener{ nullptr };
|
||||
musik::core::runtime::IMessageQueue* messageQueue;
|
||||
|
@ -65,7 +65,11 @@ static inline std::string resolveErrorMessage(MasterLibraryPtr library) {
|
||||
auto error = remoteLibrary->WebSocketClient().LastConnectionError();
|
||||
auto it = kStateToErrorString.find(error);
|
||||
if (it != kStateToErrorString.end()) {
|
||||
return _TSTR(it->second);
|
||||
std::string value = _TSTR(it->second);
|
||||
if (error == WebSocketClient::ConnectionError::IncompatibleVersion) {
|
||||
value += " (" + remoteLibrary->WebSocketClient().LastServerVersion() + ")";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
return _TSTR("library_error_connection_failed");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user