Compare commits
7
Commits
bf1cd8e08d
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bae23b7abc | ||
|
|
88cfb1d443 | ||
|
|
8ef805debd | ||
|
|
2956ef29e9 | ||
|
|
1fc5aaecfe | ||
|
|
2aa44fae9e | ||
|
|
6e789fd83f |
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
name: Independent component release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [v*]
|
||||||
|
schedule:
|
||||||
|
- cron: '17 2 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: echoion-release-serial
|
||||||
|
steps:
|
||||||
|
- name: Check out component
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Check out pinned public release tools
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
repository: Void/Echoion
|
||||||
|
ref: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
path: .echoion-release-tools
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Build, publish, and merge feed transaction
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.COMPONENT_OBJECT_STORAGE_ACCESS_KEY }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.COMPONENT_OBJECT_STORAGE_SECRET_KEY }}
|
||||||
|
AWS_DEFAULT_REGION: ${{ vars.COMPONENT_OBJECT_STORAGE_REGION }}
|
||||||
|
ECHOION_COMPONENT_SSH_KEY: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }}
|
||||||
|
ECHOION_DISTRIBUTION_BACKEND: ${{ vars.ECHOION_DISTRIBUTION_BACKEND }}
|
||||||
|
ECHOION_DISTRIBUTION_BASE_URL: ${{ vars.ECHOION_DISTRIBUTION_BASE_URL }}
|
||||||
|
ECHOION_FEED_BASE_URL: ${{ vars.ECHOION_FEED_BASE_URL }}
|
||||||
|
ECHOION_FEED_COMMIT_SIGNING_KEY: ${{ secrets.RELEASE_FEED_GIT_SIGNING_KEY }}
|
||||||
|
ECHOION_FEED_PRIVATE_KEY: ${{ secrets.RELEASE_FEED_ED25519_PRIVATE_KEY }}
|
||||||
|
ECHOION_FEED_REPOSITORY: ssh://gitea@git.faumaray.ru/Void/Echoion.git
|
||||||
|
ECHOION_FEED_SIGNING_KEY_ID: ${{ vars.ECHOION_FEED_SIGNING_KEY_ID }}
|
||||||
|
ECHOION_OBJECT_STORAGE_BUCKET: ${{ vars.COMPONENT_OBJECT_STORAGE_BUCKET }}
|
||||||
|
ECHOION_OBJECT_STORAGE_ENDPOINT: ${{ vars.COMPONENT_OBJECT_STORAGE_ENDPOINT }}
|
||||||
|
ECHOION_OBJECT_STORAGE_PREFIX: ${{ vars.COMPONENT_OBJECT_STORAGE_PREFIX }}
|
||||||
|
ECHOION_RELEASE_TAG_ALLOWED_SIGNERS: ${{ secrets.RELEASE_TAG_ALLOWED_SIGNERS }}
|
||||||
|
GITEA_API_URL: ${{ gitea.api_url }}
|
||||||
|
GITEA_EVENT_NAME: ${{ gitea.event_name }}
|
||||||
|
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||||
|
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
|
||||||
|
GITEA_SHA: ${{ gitea.sha }}
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
|
||||||
|
RELEASE_TOOLS_REF: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
[[ "$RELEASE_TOOLS_REF" =~ ^[0-9a-f]{40}$ ]]
|
||||||
|
test "$(git -C .echoion-release-tools rev-parse HEAD)" = "$RELEASE_TOOLS_REF"
|
||||||
|
.echoion-release-tools/scripts/release-component.sh component.release.json
|
||||||
+30
-1
@@ -1,5 +1,33 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 4.0.0)
|
||||||
project(EchoionDesktop VERSION 1.0.0 LANGUAGES CXX)
|
if(NOT DEFINED ECHOION_PRODUCT_VERSION)
|
||||||
|
set(ECHOION_PRODUCT_VERSION 0.0.0)
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ECHOION_COMPONENT_VERSION)
|
||||||
|
set(ECHOION_COMPONENT_VERSION "${ECHOION_PRODUCT_VERSION}")
|
||||||
|
endif()
|
||||||
|
project(EchoionDesktop VERSION "${ECHOION_COMPONENT_VERSION}" LANGUAGES CXX)
|
||||||
|
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
file(DOWNLOAD
|
||||||
|
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.8/CPM.cmake
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake"
|
||||||
|
EXPECTED_HASH
|
||||||
|
SHA256=78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791)
|
||||||
|
include("${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME Void
|
||||||
|
GIT_REPOSITORY ssh://gitea@git.faumaray.ru/void/voidlibrary.git
|
||||||
|
GIT_TAG main
|
||||||
|
OPTIONS "VOID_ENABLE_TESTING OFF")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME EchoionApi
|
||||||
|
GIT_REPOSITORY ssh://gitea@git.faumaray.ru/void/echoionapi.git
|
||||||
|
GIT_TAG main)
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME PackageProject.cmake
|
||||||
|
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
|
||||||
|
VERSION 1.11.2)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -25,6 +53,7 @@ target_include_directories(EchoionDesktop PRIVATE
|
|||||||
|
|
||||||
target_link_libraries(EchoionDesktop PRIVATE
|
target_link_libraries(EchoionDesktop PRIVATE
|
||||||
Echoion::Api
|
Echoion::Api
|
||||||
|
Void::Security
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
Qt6::Widgets
|
Qt6::Widgets
|
||||||
Qt6::Network
|
Qt6::Network
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"componentId": "EchoionDesktop",
|
||||||
|
"productCompatibility": ">=2.0.0 <3.0.0",
|
||||||
|
"publishNightly": true,
|
||||||
|
"cmakeOptions": {}
|
||||||
|
}
|
||||||
+153
-46
@@ -3,9 +3,30 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtEndian>
|
#include <QtEndian>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Echoion::Desktop
|
namespace Echoion::Desktop
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// The server double-encodes payloads: RpcResponse.result / .error and
|
||||||
|
// RpcNotification.data are JSON *strings*. Decode such a string value
|
||||||
|
// into its object/array form (pass-through if already structured).
|
||||||
|
QJsonValue decodeEmbedded(const QJsonValue& v)
|
||||||
|
{
|
||||||
|
if (!v.isString()) {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
QJsonDocument d = QJsonDocument::fromJson(v.toString().toUtf8());
|
||||||
|
if (d.isObject()) {
|
||||||
|
return d.object();
|
||||||
|
}
|
||||||
|
if (d.isArray()) {
|
||||||
|
return d.array();
|
||||||
|
}
|
||||||
|
return QJsonValue();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
CoreClient::CoreClient(QObject* parent)
|
CoreClient::CoreClient(QObject* parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
@@ -84,14 +105,16 @@ namespace Echoion::Desktop
|
|||||||
stopReconnectTimer();
|
stopReconnectTimer();
|
||||||
cancelPendingRequests();
|
cancelPendingRequests();
|
||||||
|
|
||||||
if (socket_->state() != QAbstractSocket::UnconnectedState) {
|
if (socket_ &&
|
||||||
|
socket_->state() != QAbstractSocket::UnconnectedState) {
|
||||||
socket_->close();
|
socket_->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoreClient::isConnected() const
|
bool CoreClient::isConnected() const
|
||||||
{
|
{
|
||||||
return socket_->state() == QAbstractSocket::ConnectedState;
|
return socket_ &&
|
||||||
|
socket_->state() == QAbstractSocket::ConnectedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::requestAuthToken(const QString& nickname)
|
void CoreClient::requestAuthToken(const QString& nickname)
|
||||||
@@ -195,8 +218,13 @@ namespace Echoion::Desktop
|
|||||||
{"ManageUsers", 56},
|
{"ManageUsers", 56},
|
||||||
{"GetServerInfo", 57},
|
{"GetServerInfo", 57},
|
||||||
{"RequestLoginToken", 58},
|
{"RequestLoginToken", 58},
|
||||||
{"ValidateLoginToken", 59}};
|
{"ValidateLoginToken", 59},
|
||||||
|
{"ToggleShuffle", 60},
|
||||||
|
{"ToggleRepeat", 61},
|
||||||
|
{"ShuffleQueue", 62}};
|
||||||
|
|
||||||
|
// Values above are only used to reject locally-unknown methods; the wire
|
||||||
|
// contract is the method NAME (Core decodes RpcMethod by name).
|
||||||
return methodMap.value(method, -1);
|
return methodMap.value(method, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +259,12 @@ namespace Echoion::Desktop
|
|||||||
// Core deserializes RpcMethod via Void::Json reflection, which encodes
|
// Core deserializes RpcMethod via Void::Json reflection, which encodes
|
||||||
// enums by name. methodInt above is only used to reject unknown methods.
|
// enums by name. methodInt above is only used to reject unknown methods.
|
||||||
request["method"] = method;
|
request["method"] = method;
|
||||||
request["params"] = params;
|
// RpcRequest.params is a JSON-encoded STRING on the server (handlers
|
||||||
|
// re-parse it via Void::Json::parse). Reflection rejects an object for a
|
||||||
|
// string field, so the params object must be serialized to a string
|
||||||
|
// here — otherwise the whole request fails to decode.
|
||||||
|
request["params"] = QString::fromUtf8(
|
||||||
|
QJsonDocument(params).toJson(QJsonDocument::Compact));
|
||||||
|
|
||||||
if (!authToken_.isEmpty()) {
|
if (!authToken_.isEmpty()) {
|
||||||
request["authToken"] = authToken_;
|
request["authToken"] = authToken_;
|
||||||
@@ -273,40 +306,67 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
pending.retryCount++;
|
pending.retryCount++;
|
||||||
|
|
||||||
// Retry after delay
|
// Owned, cancellable retry timer. A fire-and-forget QTimer::singleShot
|
||||||
QTimer::singleShot(
|
// would still fire after a disconnect and resend on a dead/reconnected
|
||||||
RETRY_DELAY_MS * pending.retryCount, this, [this, requestId]() {
|
// socket; cancelPendingRequests() stops these on teardown.
|
||||||
auto it = pendingRequests_.find(requestId);
|
auto* timer = new QTimer(this);
|
||||||
if (it == pendingRequests_.end()) {
|
timer->setSingleShot(true);
|
||||||
return;
|
pending.retryTimer = timer;
|
||||||
}
|
const int delay = RETRY_DELAY_MS * pending.retryCount;
|
||||||
|
connect(timer, &QTimer::timeout, this, [this, requestId, timer]() {
|
||||||
|
timer->deleteLater();
|
||||||
|
|
||||||
auto& pending = it->second;
|
auto it = pendingRequests_.find(requestId);
|
||||||
|
if (it == pendingRequests_.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
it->second.retryTimer = nullptr; // spent; don't touch in cancel
|
||||||
|
|
||||||
quint64 newRequestId = nextRequestId_++;
|
// The socket may have dropped between scheduling and firing. Never
|
||||||
|
// resend on a closed or reconnecting socket.
|
||||||
|
if (!socket_ ||
|
||||||
|
socket_->state() != QAbstractSocket::ConnectedState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject request;
|
auto& pending = it->second;
|
||||||
request["id"] = static_cast<qint64>(newRequestId);
|
|
||||||
request["method"] = pending.method;
|
|
||||||
request["params"] = pending.params;
|
|
||||||
|
|
||||||
if (!authToken_.isEmpty()) {
|
quint64 newRequestId = nextRequestId_++;
|
||||||
request["authToken"] = authToken_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move callback to new request ID
|
QJsonObject request;
|
||||||
PendingRequest newPending = std::move(pending);
|
request["id"] = static_cast<qint64>(newRequestId);
|
||||||
pendingRequests_.erase(it);
|
request["method"] = pending.method;
|
||||||
pendingRequests_[newRequestId] = std::move(newPending);
|
// Same wire format as sendRequest: the server's
|
||||||
|
// RpcRequest.params is a JSON-encoded STRING; a raw object
|
||||||
|
// here made every retried request fail to decode.
|
||||||
|
request["params"] = QString::fromUtf8(
|
||||||
|
QJsonDocument(pending.params).toJson(QJsonDocument::Compact));
|
||||||
|
|
||||||
QJsonDocument doc(request);
|
if (!authToken_.isEmpty()) {
|
||||||
socket_->sendTextMessage(doc.toJson(QJsonDocument::Compact));
|
request["authToken"] = authToken_;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// Move callback to new request ID
|
||||||
|
PendingRequest newPending = std::move(pending);
|
||||||
|
pendingRequests_.erase(it);
|
||||||
|
pendingRequests_[newRequestId] = std::move(newPending);
|
||||||
|
|
||||||
|
QJsonDocument doc(request);
|
||||||
|
socket_->sendTextMessage(doc.toJson(QJsonDocument::Compact));
|
||||||
|
});
|
||||||
|
timer->start(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::cancelPendingRequests()
|
void CoreClient::cancelPendingRequests()
|
||||||
{
|
{
|
||||||
for (auto& [id, pending] : pendingRequests_) {
|
for (auto& [id, pending] : pendingRequests_) {
|
||||||
|
// Stop any scheduled retry so it can't fire after the connection
|
||||||
|
// is gone and resend on a stale socket.
|
||||||
|
if (pending.retryTimer) {
|
||||||
|
pending.retryTimer->stop();
|
||||||
|
pending.retryTimer->deleteLater();
|
||||||
|
pending.retryTimer = nullptr;
|
||||||
|
}
|
||||||
if (pending.callback) {
|
if (pending.callback) {
|
||||||
QJsonObject error;
|
QJsonObject error;
|
||||||
error["success"] = false;
|
error["success"] = false;
|
||||||
@@ -351,6 +411,10 @@ namespace Echoion::Desktop
|
|||||||
if (autoConnectEnabled_ &&
|
if (autoConnectEnabled_ &&
|
||||||
reconnectAttempts_ < MAX_RECONNECT_ATTEMPTS) {
|
reconnectAttempts_ < MAX_RECONNECT_ATTEMPTS) {
|
||||||
startReconnectTimer();
|
startReconnectTimer();
|
||||||
|
} else if (autoConnectEnabled_) {
|
||||||
|
// Attempts exhausted: hand control back to the user (the UI
|
||||||
|
// shows a manual Reconnect action).
|
||||||
|
emit reconnectExhausted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,30 +459,52 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
if (obj.contains("event")) {
|
if (obj.contains("event")) {
|
||||||
handleEvent(obj);
|
handleEvent(obj);
|
||||||
} else if (obj.contains("id")) {
|
} else if (obj.contains("requestId")) {
|
||||||
handleRpcResponse(obj);
|
handleRpcResponse(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::handleRpcResponse(const QJsonObject& response)
|
void CoreClient::handleRpcResponse(const QJsonObject& response)
|
||||||
{
|
{
|
||||||
quint64 requestId = response["id"].toVariant().toULongLong();
|
quint64 requestId =
|
||||||
|
response["requestId"].toVariant().toULongLong();
|
||||||
|
|
||||||
auto it = pendingRequests_.find(requestId);
|
auto it = pendingRequests_.find(requestId);
|
||||||
if (it != pendingRequests_.end()) {
|
if (it == pendingRequests_.end()) {
|
||||||
auto callback = std::move(it->second.callback);
|
return;
|
||||||
pendingRequests_.erase(it);
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
auto callback = std::move(it->second.callback);
|
||||||
|
pendingRequests_.erase(it);
|
||||||
|
if (!callback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalise into a flat object the callbacks can read directly:
|
||||||
|
// success (bool), data (decoded result payload), error, and a
|
||||||
|
// convenience message pulled from result/error.
|
||||||
|
const bool success = response["success"].toBool();
|
||||||
|
QJsonValue data = decodeEmbedded(response.value("result"));
|
||||||
|
QJsonValue error = decodeEmbedded(response.value("error"));
|
||||||
|
|
||||||
|
QString message;
|
||||||
|
if (data.isObject() && data.toObject().contains("message")) {
|
||||||
|
message = data.toObject()["message"].toString();
|
||||||
|
} else if (error.isObject() && error.toObject().contains("message")) {
|
||||||
|
message = error.toObject()["message"].toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject cb;
|
||||||
|
cb["success"] = success;
|
||||||
|
cb["data"] = data;
|
||||||
|
cb["error"] = error;
|
||||||
|
cb["message"] = message;
|
||||||
|
callback(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::handleEvent(const QJsonObject& event)
|
void CoreClient::handleEvent(const QJsonObject& event)
|
||||||
{
|
{
|
||||||
QString eventName = event["event"].toString();
|
QString eventName = event["event"].toString();
|
||||||
QJsonObject data = event["data"].toObject();
|
QJsonObject data = decodeEmbedded(event.value("data")).toObject();
|
||||||
|
|
||||||
emit eventReceived(eventName, data);
|
emit eventReceived(eventName, data);
|
||||||
|
|
||||||
@@ -470,8 +556,9 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
void CoreClient::setVolume(int volume)
|
void CoreClient::setVolume(int volume)
|
||||||
{
|
{
|
||||||
|
// UI uses 0-100; the server's volume model is normalised 0.0-1.0.
|
||||||
QJsonObject params;
|
QJsonObject params;
|
||||||
params["volume"] = volume;
|
params["volume"] = std::clamp(volume, 0, 100) / 100.0;
|
||||||
call("SetVolume", params);
|
call("SetVolume", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,24 +570,24 @@ namespace Echoion::Desktop
|
|||||||
call("QueueTrack", params);
|
call("QueueTrack", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::removeFromQueue(int position)
|
void CoreClient::removeFromQueue(quint64 queueId)
|
||||||
{
|
{
|
||||||
QJsonObject params;
|
QJsonObject params;
|
||||||
params["position"] = position;
|
params["queueId"] = static_cast<qint64>(queueId);
|
||||||
call("RemoveFromQueue", params);
|
call("RemoveFromQueue", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::clearQueue() { call("ClearQueue"); }
|
void CoreClient::clearQueue() { call("ClearQueue"); }
|
||||||
|
|
||||||
void CoreClient::moveInQueue(int from, int to)
|
void CoreClient::moveInQueue(quint64 queueId, int newPosition)
|
||||||
{
|
{
|
||||||
QJsonObject params;
|
QJsonObject params;
|
||||||
params["from"] = from;
|
params["queueId"] = static_cast<qint64>(queueId);
|
||||||
params["to"] = to;
|
params["newPosition"] = newPosition;
|
||||||
call("MoveInQueue", params);
|
call("MoveInQueue", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreClient::shuffle() { call("Shuffle"); }
|
void CoreClient::shuffle() { call("ShuffleQueue"); }
|
||||||
void CoreClient::toggleRepeat() { call("ToggleRepeat"); }
|
void CoreClient::toggleRepeat() { call("ToggleRepeat"); }
|
||||||
void CoreClient::toggleShuffle() { call("ToggleShuffle"); }
|
void CoreClient::toggleShuffle() { call("ToggleShuffle"); }
|
||||||
|
|
||||||
@@ -509,7 +596,7 @@ namespace Echoion::Desktop
|
|||||||
{
|
{
|
||||||
QJsonObject params;
|
QJsonObject params;
|
||||||
params["query"] = query;
|
params["query"] = query;
|
||||||
call("Search", params);
|
call("SearchTracks", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Playlist management
|
// Playlist management
|
||||||
@@ -529,10 +616,30 @@ namespace Echoion::Desktop
|
|||||||
call("SavePlaylist", params);
|
call("SavePlaylist", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoreClient::deletePlaylist(const QString& playlistId)
|
||||||
|
{
|
||||||
|
QJsonObject params;
|
||||||
|
params["playlistId"] = playlistId;
|
||||||
|
call("DeletePlaylist", params);
|
||||||
|
}
|
||||||
|
|
||||||
void CoreClient::getUserPlaylists() { call("GetPlaylists"); }
|
void CoreClient::getUserPlaylists() { call("GetPlaylists"); }
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
void CoreClient::getConfig() { call("GetConfig"); }
|
||||||
|
|
||||||
|
void CoreClient::setConfig(const QString& configJson)
|
||||||
|
{
|
||||||
|
// configJson is the full config object; forwarded as the params payload.
|
||||||
|
QJsonObject params =
|
||||||
|
QJsonDocument::fromJson(configJson.toUtf8()).object();
|
||||||
|
call("SetConfig", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreClient::reloadConfig() { call("ReloadConfig"); }
|
||||||
|
|
||||||
// Data requests
|
// Data requests
|
||||||
void CoreClient::requestPlaybackState() { call("GetPlaybackState"); }
|
void CoreClient::requestPlaybackState() { call("GetStatus"); }
|
||||||
void CoreClient::requestQueue() { call("GetQueue"); }
|
void CoreClient::requestQueue() { call("GetQueue"); }
|
||||||
void CoreClient::requestCurrentTrack() { call("GetCurrentTrack"); }
|
void CoreClient::requestCurrentTrack() { call("GetCurrentTrack"); }
|
||||||
|
|
||||||
|
|||||||
+17
-5
@@ -3,6 +3,7 @@
|
|||||||
#include "storage/SettingsManager.hpp"
|
#include "storage/SettingsManager.hpp"
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QPointer>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWebSocket>
|
#include <QWebSocket>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -60,11 +61,11 @@ namespace Echoion::Desktop
|
|||||||
void seek(int positionMs);
|
void seek(int positionMs);
|
||||||
void setVolume(int volume);
|
void setVolume(int volume);
|
||||||
|
|
||||||
// Queue management
|
// Queue management (queueId matches GetQueue items + queue events)
|
||||||
void queueTrack(const QString& query);
|
void queueTrack(const QString& query);
|
||||||
void removeFromQueue(int position);
|
void removeFromQueue(quint64 queueId);
|
||||||
void clearQueue();
|
void clearQueue();
|
||||||
void moveInQueue(int from, int to);
|
void moveInQueue(quint64 queueId, int newPosition);
|
||||||
void shuffle();
|
void shuffle();
|
||||||
void toggleRepeat();
|
void toggleRepeat();
|
||||||
void toggleShuffle();
|
void toggleShuffle();
|
||||||
@@ -75,9 +76,16 @@ namespace Echoion::Desktop
|
|||||||
// Playlist management
|
// Playlist management
|
||||||
void loadPlaylist(const QString& playlistId);
|
void loadPlaylist(const QString& playlistId);
|
||||||
void savePlaylist(const QString& name, const QString& description);
|
void savePlaylist(const QString& name, const QString& description);
|
||||||
|
void deletePlaylist(const QString& playlistId);
|
||||||
void getUserPlaylists();
|
void getUserPlaylists();
|
||||||
|
|
||||||
// Data requests (fetch on demand)
|
// Configuration
|
||||||
|
void getConfig();
|
||||||
|
void setConfig(const QString& configJson);
|
||||||
|
void reloadConfig();
|
||||||
|
|
||||||
|
// Data requests (fetch on demand). Data-returning calls may also be
|
||||||
|
// issued via call(method, params, callback) for a one-shot reply.
|
||||||
void requestPlaybackState();
|
void requestPlaybackState();
|
||||||
void requestQueue();
|
void requestQueue();
|
||||||
void requestCurrentTrack();
|
void requestCurrentTrack();
|
||||||
@@ -88,6 +96,8 @@ namespace Echoion::Desktop
|
|||||||
void connected();
|
void connected();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
void reconnecting(int attempt);
|
void reconnecting(int attempt);
|
||||||
|
// All automatic reconnect attempts failed; manual retry needed.
|
||||||
|
void reconnectExhausted();
|
||||||
void connectionError(const QString& error);
|
void connectionError(const QString& error);
|
||||||
void connectionFailed(const QString& reason);
|
void connectionFailed(const QString& reason);
|
||||||
|
|
||||||
@@ -144,7 +154,9 @@ namespace Echoion::Desktop
|
|||||||
[[nodiscard]] int methodToInt(const QString& method) const;
|
[[nodiscard]] int methodToInt(const QString& method) const;
|
||||||
|
|
||||||
SettingsManager settingsManager_;
|
SettingsManager settingsManager_;
|
||||||
QWebSocket* socket_ = nullptr;
|
// QPointer so a stray access after teardown is null-checked rather
|
||||||
|
// than dangling. Qt parent-ownership still frees it.
|
||||||
|
QPointer<QWebSocket> socket_ = nullptr;
|
||||||
QString currentHost_;
|
QString currentHost_;
|
||||||
int currentPort_ = 8765;
|
int currentPort_ = 8765;
|
||||||
QString currentNickname_;
|
QString currentNickname_;
|
||||||
|
|||||||
+815
-153
File diff suppressed because it is too large.
Load diff
+127
-49
@@ -1,13 +1,37 @@
|
|||||||
#include "storage/SecureStorage.hpp"
|
#include "storage/SecureStorage.hpp"
|
||||||
|
|
||||||
|
#include <Void/Security/Security.hpp>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QDataStream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#include <QSaveFile>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QtEndian>
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
namespace Echoion::Desktop
|
namespace Echoion::Desktop
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const QByteArray storageMagic{"ECV2", 4};
|
||||||
|
|
||||||
|
[[nodiscard]] Void::Security::SecretKey
|
||||||
|
toSecretKey(const QByteArray& value)
|
||||||
|
{
|
||||||
|
Void::Security::SecretKey key{};
|
||||||
|
std::copy_n(
|
||||||
|
reinterpret_cast<const unsigned char*>(value.constData()),
|
||||||
|
key.size(), key.begin());
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
SecureStorage::SecureStorage() = default;
|
SecureStorage::SecureStorage() = default;
|
||||||
|
|
||||||
@@ -34,14 +58,53 @@ namespace Echoion::Desktop
|
|||||||
return getStorageDir() + "/tokens.dat";
|
return getStorageDir() + "/tokens.dat";
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SecureStorage::generateKey() const
|
QByteArray SecureStorage::loadOrCreateKey() const
|
||||||
{
|
{
|
||||||
if (!cachedKey_.isEmpty()) {
|
if (!cachedKey_.isEmpty()) {
|
||||||
return cachedKey_;
|
return cachedKey_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a deterministic key from machine-specific data
|
const QString keyPath = getStorageDir() + "/secrets.key";
|
||||||
// This makes it harder to copy tokens to another machine
|
const QFileInfo keyInfo{keyPath};
|
||||||
|
if (keyInfo.isSymLink()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QFile keyFile{keyPath};
|
||||||
|
if (keyFile.exists()) {
|
||||||
|
if (!keyFile.open(QIODevice::ReadOnly)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QByteArray key = keyFile.readAll();
|
||||||
|
if (key.size() !=
|
||||||
|
static_cast<qsizetype>(Void::Security::secret_key_bytes)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
cachedKey_ = key;
|
||||||
|
return cachedKey_;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto generated = Void::Security::random_secret_key();
|
||||||
|
if (!generated) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QByteArray key{reinterpret_cast<const char*>(generated->data()),
|
||||||
|
static_cast<qsizetype>(generated->size())};
|
||||||
|
QSaveFile output{keyPath};
|
||||||
|
if (!output.open(QIODevice::WriteOnly)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (!output.setPermissions(QFileDevice::ReadOwner |
|
||||||
|
QFileDevice::WriteOwner) ||
|
||||||
|
output.write(key) != key.size() || !output.commit()) {
|
||||||
|
output.cancelWriting();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
cachedKey_ = key;
|
||||||
|
return cachedKey_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray SecureStorage::legacyKey() const
|
||||||
|
{
|
||||||
QString seed =
|
QString seed =
|
||||||
QCoreApplication::applicationDirPath() +
|
QCoreApplication::applicationDirPath() +
|
||||||
QCoreApplication::applicationName() +
|
QCoreApplication::applicationName() +
|
||||||
@@ -56,17 +119,19 @@ namespace Echoion::Desktop
|
|||||||
hash[i] = hash[i] ^ static_cast<char>(rng.generate() & 0xFF);
|
hash[i] = hash[i] ^ static_cast<char>(rng.generate() & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedKey_ = hash;
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SecureStorage::xorEncrypt(const QByteArray& data,
|
QByteArray SecureStorage::legacyXor(const QByteArray& data,
|
||||||
const QByteArray& key) const
|
const QByteArray& key)
|
||||||
{
|
{
|
||||||
|
if (key.isEmpty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
QByteArray result = data;
|
QByteArray result = data;
|
||||||
int keyLen = key.length();
|
const qsizetype keyLen = key.size();
|
||||||
|
|
||||||
for (int i = 0; i < result.length(); ++i) {
|
for (qsizetype i = 0; i < result.size(); ++i) {
|
||||||
result[i] = result[i] ^ key[i % keyLen];
|
result[i] = result[i] ^ key[i % keyLen];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,39 +140,63 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
QByteArray SecureStorage::encrypt(const QByteArray& data) const
|
QByteArray SecureStorage::encrypt(const QByteArray& data) const
|
||||||
{
|
{
|
||||||
QByteArray key = generateKey();
|
const QByteArray encodedKey = loadOrCreateKey();
|
||||||
|
if (encodedKey.size() !=
|
||||||
// Add simple header for validation
|
static_cast<qsizetype>(Void::Security::secret_key_bytes)) {
|
||||||
QByteArray header;
|
return {};
|
||||||
QDataStream headerStream(&header, QIODevice::WriteOnly);
|
}
|
||||||
headerStream << quint32(0x4543484F); // "ECHO" magic
|
const auto* bytes =
|
||||||
headerStream << quint32(data.length());
|
reinterpret_cast<const unsigned char*>(data.constData());
|
||||||
|
auto sealed = Void::Security::seal_secret(
|
||||||
QByteArray encrypted = xorEncrypt(data, key);
|
std::span<const unsigned char>{
|
||||||
|
bytes, static_cast<std::size_t>(data.size())},
|
||||||
return header + encrypted;
|
toSecretKey(encodedKey));
|
||||||
|
if (!sealed) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QByteArray result = storageMagic;
|
||||||
|
result.append(reinterpret_cast<const char*>(sealed->data()),
|
||||||
|
static_cast<qsizetype>(sealed->size()));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SecureStorage::decrypt(const QByteArray& data) const
|
QByteArray SecureStorage::decrypt(const QByteArray& data) const
|
||||||
{
|
{
|
||||||
|
if (data.startsWith(storageMagic)) {
|
||||||
|
const QByteArray encodedKey = loadOrCreateKey();
|
||||||
|
if (encodedKey.size() !=
|
||||||
|
static_cast<qsizetype>(Void::Security::secret_key_bytes)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const auto envelope = data.sliced(storageMagic.size());
|
||||||
|
const auto* bytes =
|
||||||
|
reinterpret_cast<const unsigned char*>(envelope.constData());
|
||||||
|
auto opened = Void::Security::open_secret(
|
||||||
|
std::span<const unsigned char>{
|
||||||
|
bytes, static_cast<std::size_t>(envelope.size())},
|
||||||
|
toSecretKey(encodedKey));
|
||||||
|
if (!opened) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return QByteArray{reinterpret_cast<const char*>(opened->data()),
|
||||||
|
static_cast<qsizetype>(opened->size())};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept the v1 format only to migrate existing installations.
|
||||||
if (data.length() < 8) {
|
if (data.length() < 8) {
|
||||||
return QByteArray(); // Too short
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify header
|
|
||||||
QDataStream headerStream(data);
|
QDataStream headerStream(data);
|
||||||
quint32 magic;
|
quint32 magic = 0;
|
||||||
quint32 dataLen;
|
quint32 dataLen = 0;
|
||||||
headerStream >> magic >> dataLen;
|
headerStream >> magic >> dataLen;
|
||||||
|
if (magic != 0x4543484F ||
|
||||||
if (magic != 0x4543484F) {
|
dataLen != static_cast<quint32>(data.size() - 8)) {
|
||||||
return QByteArray(); // Invalid magic
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray key = generateKey();
|
return legacyXor(data.sliced(8), legacyKey());
|
||||||
QByteArray encrypted = data.mid(8); // Skip header
|
|
||||||
|
|
||||||
return xorEncrypt(encrypted, key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SecureStorage::saveToFile(const QString& filepath,
|
bool SecureStorage::saveToFile(const QString& filepath,
|
||||||
@@ -118,29 +207,18 @@ namespace Echoion::Desktop
|
|||||||
createBackup(filepath);
|
createBackup(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to temp file first
|
QSaveFile output{filepath};
|
||||||
QString tempPath = filepath + ".tmp";
|
if (!output.open(QIODevice::WriteOnly)) {
|
||||||
QFile tempFile(tempPath);
|
|
||||||
|
|
||||||
if (!tempFile.open(QIODevice::WriteOnly)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempFile.write(data) != data.length()) {
|
if (!output.setPermissions(QFileDevice::ReadOwner |
|
||||||
tempFile.close();
|
QFileDevice::WriteOwner) ||
|
||||||
QFile::remove(tempPath);
|
output.write(data) != data.size()) {
|
||||||
|
output.cancelWriting();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return output.commit();
|
||||||
tempFile.close();
|
|
||||||
|
|
||||||
// Atomic rename
|
|
||||||
if (!QFile::rename(tempPath, filepath)) {
|
|
||||||
QFile::remove(tempPath);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray SecureStorage::loadFromFile(const QString& filepath) const
|
QByteArray SecureStorage::loadFromFile(const QString& filepath) const
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QCryptographicHash>
|
#include <QByteArray>
|
||||||
#include <QDataStream>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QRandomGenerator>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace Echoion::Desktop
|
namespace Echoion::Desktop
|
||||||
@@ -15,7 +12,7 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
SecureStorage();
|
SecureStorage();
|
||||||
|
|
||||||
// Encrypt/decrypt data using Qt crypto
|
// Encrypt/decrypt data with authenticated VoidLibrary primitives.
|
||||||
[[nodiscard]] QByteArray encrypt(const QByteArray& data) const;
|
[[nodiscard]] QByteArray encrypt(const QByteArray& data) const;
|
||||||
[[nodiscard]] QByteArray decrypt(const QByteArray& data) const;
|
[[nodiscard]] QByteArray decrypt(const QByteArray& data) const;
|
||||||
|
|
||||||
@@ -40,12 +37,12 @@ namespace Echoion::Desktop
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Generate encryption key from machine-specific data
|
[[nodiscard]] QByteArray loadOrCreateKey() const;
|
||||||
[[nodiscard]] QByteArray generateKey() const;
|
|
||||||
|
|
||||||
// Simple XOR encryption with SHA-256 derived key
|
// Read-only migration support for the v1 deterministic XOR format.
|
||||||
[[nodiscard]] QByteArray xorEncrypt(const QByteArray& data,
|
[[nodiscard]] QByteArray legacyKey() const;
|
||||||
const QByteArray& key) const;
|
[[nodiscard]] static QByteArray legacyXor(const QByteArray& data,
|
||||||
|
const QByteArray& key);
|
||||||
|
|
||||||
mutable QByteArray cachedKey_;
|
mutable QByteArray cachedKey_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "storage/SecureStorage.hpp"
|
#include "storage/SecureStorage.hpp"
|
||||||
#include "storage/SettingsManager.hpp"
|
#include "storage/SettingsManager.hpp"
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QIODevice>
|
||||||
|
|
||||||
namespace Echoion::Desktop
|
namespace Echoion::Desktop
|
||||||
{
|
{
|
||||||
@@ -245,8 +248,9 @@ namespace Echoion::Desktop
|
|||||||
emit tokenSaved(host, port);
|
emit tokenSaved(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<QString> SettingsManager::loadToken(
|
std::optional<QString>
|
||||||
const QString& host, int port, QString& outNickname) const
|
SettingsManager::loadToken(const QString& host, int port,
|
||||||
|
QString& outNickname) const
|
||||||
{
|
{
|
||||||
for (const auto& ct : tokens_) {
|
for (const auto& ct : tokens_) {
|
||||||
if (ct.host == host && ct.port == port) {
|
if (ct.host == host && ct.port == port) {
|
||||||
|
|||||||
Reference in new issue
Block a user