Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eee74a2e9 | ||
|
|
d9e38fb3be | ||
|
|
81cc90e54a | ||
|
|
bd9771a88f | ||
|
|
f5cd81fe09 | ||
|
|
277e2cff59 | ||
|
|
6fa9514059 | ||
|
|
c5e38b71f7 | ||
|
|
3746915ae7 | ||
|
|
21bdf88d09 | ||
|
|
ff032c3cd7 | ||
|
|
c083110051 | ||
|
|
a7dbeb5d76 | ||
|
|
634f6ea9f5 | ||
|
|
f9e4f9a09a | ||
|
|
aab9889174 | ||
|
|
3b560e4e4f | ||
|
|
9e327c9556 | ||
|
|
1ec640e088 | ||
|
|
463aaf6942 | ||
|
|
71287dd77e | ||
|
|
b66c0f5573 | ||
|
|
a9f2c384fa | ||
|
|
ae9584c213 | ||
|
|
4db1c5ceb8 | ||
|
|
1738259467 | ||
|
|
fcee02edc1 | ||
|
|
4fff5820c5 | ||
|
|
9aa6da2faf | ||
|
|
279934411c | ||
|
|
fd829551e8 |
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -538,7 +538,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
ubuntu_version: [ 'noble', 'oracular' ]
|
ubuntu_version: [ 'noble', 'oracular', 'plucky' ]
|
||||||
container:
|
container:
|
||||||
image: ubuntu:${{matrix.ubuntu_version}}
|
image: ubuntu:${{matrix.ubuntu_version}}
|
||||||
steps:
|
steps:
|
||||||
@@ -631,7 +631,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
ubuntu_version: [ 'noble', 'oracular' ]
|
ubuntu_version: [ 'noble', 'oracular', 'plucky' ]
|
||||||
container:
|
container:
|
||||||
image: ubuntu:${{matrix.ubuntu_version}}
|
image: ubuntu:${{matrix.ubuntu_version}}
|
||||||
steps:
|
steps:
|
||||||
@@ -733,7 +733,7 @@ jobs:
|
|||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Build FreeBSD
|
- name: Build FreeBSD
|
||||||
id: build-freebsd
|
id: build-freebsd
|
||||||
uses: vmactions/freebsd-vm@v1.1.9
|
uses: vmactions/freebsd-vm@v1.2.0
|
||||||
with:
|
with:
|
||||||
usesh: true
|
usesh: true
|
||||||
mem: 4096
|
mem: 4096
|
||||||
@@ -758,7 +758,7 @@ jobs:
|
|||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Build OpenBSD
|
- name: Build OpenBSD
|
||||||
id: build-openbsd
|
id: build-openbsd
|
||||||
uses: vmactions/openbsd-vm@v1.1.6
|
uses: vmactions/openbsd-vm@v1.1.7
|
||||||
with:
|
with:
|
||||||
usesh: true
|
usesh: true
|
||||||
mem: 4096
|
mem: 4096
|
||||||
|
|||||||
42
3rdparty/discord-rpc/CMakeLists.txt
vendored
42
3rdparty/discord-rpc/CMakeLists.txt
vendored
@@ -1 +1,41 @@
|
|||||||
add_subdirectory(src)
|
set(DISCORD_RPC_SOURCES
|
||||||
|
discord_rpc.h
|
||||||
|
discord_register.h
|
||||||
|
discord_rpc.cpp
|
||||||
|
discord_rpc_connection.h
|
||||||
|
discord_rpc_connection.cpp
|
||||||
|
discord_serialization.h
|
||||||
|
discord_serialization.cpp
|
||||||
|
discord_connection.h
|
||||||
|
discord_backoff.h
|
||||||
|
discord_msg_queue.h
|
||||||
|
)
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
list(APPEND DISCORD_RPC_SOURCES discord_connection_unix.cpp)
|
||||||
|
if(APPLE)
|
||||||
|
list(APPEND DISCORD_RPC_SOURCES discord_register_osx.m)
|
||||||
|
add_definitions(-DDISCORD_OSX)
|
||||||
|
else()
|
||||||
|
list(APPEND DISCORD_RPC_SOURCES discord_register_linux.cpp)
|
||||||
|
add_definitions(-DDISCORD_LINUX)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND DISCORD_RPC_SOURCES discord_connection_win.cpp discord_register_win.cpp)
|
||||||
|
add_definitions(-DDISCORD_WINDOWS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(discord-rpc STATIC ${DISCORD_RPC_SOURCES})
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
target_link_libraries(discord-rpc PRIVATE "-framework AppKit")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(discord-rpc PRIVATE psapi advapi32)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(discord-rpc SYSTEM PRIVATE ${RapidJSON_INCLUDE_DIRS})
|
||||||
|
target_include_directories(discord-rpc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|||||||
63
3rdparty/discord-rpc/discord_backoff.h
vendored
Normal file
63
3rdparty/discord-rpc/discord_backoff.h
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_BACKOFF_H
|
||||||
|
#define DISCORD_BACKOFF_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <random>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace discord_rpc {
|
||||||
|
|
||||||
|
struct Backoff {
|
||||||
|
int64_t minAmount;
|
||||||
|
int64_t maxAmount;
|
||||||
|
int64_t current;
|
||||||
|
int fails;
|
||||||
|
std::mt19937_64 randGenerator;
|
||||||
|
std::uniform_real_distribution<> randDistribution;
|
||||||
|
|
||||||
|
double rand01() { return randDistribution(randGenerator); }
|
||||||
|
|
||||||
|
Backoff(int64_t min, int64_t max)
|
||||||
|
: minAmount(min), maxAmount(max), current(min), fails(0), randGenerator(static_cast<uint64_t>(time(0))) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
fails = 0;
|
||||||
|
current = minAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t nextDelay() {
|
||||||
|
++fails;
|
||||||
|
int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01());
|
||||||
|
current = std::min(current + delay, maxAmount);
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
#endif // DISCORD_BACKOFF_H
|
||||||
48
3rdparty/discord-rpc/discord_connection.h
vendored
Normal file
48
3rdparty/discord-rpc/discord_connection.h
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_CONNECTION_H
|
||||||
|
#define DISCORD_CONNECTION_H
|
||||||
|
|
||||||
|
// This is to wrap the platform specific kinds of connect/read/write.
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace discord_rpc {
|
||||||
|
|
||||||
|
// not really connectiony, but need per-platform
|
||||||
|
int GetProcessId();
|
||||||
|
|
||||||
|
struct BaseConnection {
|
||||||
|
static BaseConnection *Create();
|
||||||
|
static void Destroy(BaseConnection *&);
|
||||||
|
bool isOpen = false;
|
||||||
|
bool Open();
|
||||||
|
bool Close();
|
||||||
|
bool Write(const void *data, size_t length);
|
||||||
|
bool Read(void *data, size_t length);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
#endif // DISCORD_CONNECTION_H
|
||||||
@@ -1,4 +1,27 @@
|
|||||||
#include "connection.h"
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_connection.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -28,28 +51,34 @@ static int MsgFlags = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *GetTempPath() {
|
static const char *GetTempPath() {
|
||||||
|
|
||||||
const char *temp = getenv("XDG_RUNTIME_DIR");
|
const char *temp = getenv("XDG_RUNTIME_DIR");
|
||||||
temp = temp ? temp : getenv("TMPDIR");
|
temp = temp ? temp : getenv("TMPDIR");
|
||||||
temp = temp ? temp : getenv("TMP");
|
temp = temp ? temp : getenv("TMP");
|
||||||
temp = temp ? temp : getenv("TEMP");
|
temp = temp ? temp : getenv("TEMP");
|
||||||
temp = temp ? temp : "/tmp";
|
temp = temp ? temp : "/tmp";
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ BaseConnection *BaseConnection::Create() {
|
BaseConnection *BaseConnection::Create() {
|
||||||
PipeAddr.sun_family = AF_UNIX;
|
PipeAddr.sun_family = AF_UNIX;
|
||||||
return &Connection;
|
return &Connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void BaseConnection::Destroy(BaseConnection *&c) {
|
void BaseConnection::Destroy(BaseConnection *&c) {
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix *>(c);
|
|
||||||
|
auto self = reinterpret_cast<BaseConnectionUnix*>(c);
|
||||||
self->Close();
|
self->Close();
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Open() {
|
bool BaseConnection::Open() {
|
||||||
|
|
||||||
const char *tempPath = GetTempPath();
|
const char *tempPath = GetTempPath();
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix *>(this);
|
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||||
self->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
self->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (self->sock == -1) {
|
if (self->sock == -1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -61,8 +90,7 @@ bool BaseConnection::Open() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
|
for (int pipeNum = 0; pipeNum < 10; ++pipeNum) {
|
||||||
snprintf(
|
snprintf(PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
||||||
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
|
||||||
int err = connect(self->sock, reinterpret_cast<const sockaddr*>(&PipeAddr), sizeof(PipeAddr));
|
int err = connect(self->sock, reinterpret_cast<const sockaddr*>(&PipeAddr), sizeof(PipeAddr));
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
self->isOpen = true;
|
self->isOpen = true;
|
||||||
@@ -70,10 +98,13 @@ bool BaseConnection::Open() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->Close();
|
self->Close();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Close() {
|
bool BaseConnection::Close() {
|
||||||
|
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix *>(this);
|
auto self = reinterpret_cast<BaseConnectionUnix *>(this);
|
||||||
if (self->sock == -1) {
|
if (self->sock == -1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -81,11 +112,14 @@ bool BaseConnection::Close() {
|
|||||||
close(self->sock);
|
close(self->sock);
|
||||||
self->sock = -1;
|
self->sock = -1;
|
||||||
self->isOpen = false;
|
self->isOpen = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Write(const void *data, size_t length) {
|
bool BaseConnection::Write(const void *data, size_t length) {
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix *>(this);
|
|
||||||
|
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||||
|
|
||||||
if (self->sock == -1) {
|
if (self->sock == -1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -95,11 +129,14 @@ bool BaseConnection::Write(const void *data, size_t length) {
|
|||||||
if (sentBytes < 0) {
|
if (sentBytes < 0) {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return sentBytes == static_cast<ssize_t>(length);
|
return sentBytes == static_cast<ssize_t>(length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Read(void *data, size_t length) {
|
bool BaseConnection::Read(void *data, size_t length) {
|
||||||
auto self = reinterpret_cast<BaseConnectionUnix *>(this);
|
|
||||||
|
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||||
|
|
||||||
if (self->sock == -1) {
|
if (self->sock == -1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -115,8 +152,9 @@ bool BaseConnection::Read(void *data, size_t length) {
|
|||||||
else if (res == 0) {
|
else if (res == 0) {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<size_t>(res) == length;
|
return static_cast<size_t>(res) == length;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
@@ -1,9 +1,33 @@
|
|||||||
#include "connection.h"
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_connection.h"
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define NOMCX
|
#define NOMCX
|
||||||
#define NOSERVICE
|
#define NOSERVICE
|
||||||
#define NOIME
|
#define NOIME
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
@@ -19,24 +43,26 @@ struct BaseConnectionWin : public BaseConnection {
|
|||||||
|
|
||||||
static BaseConnectionWin Connection;
|
static BaseConnectionWin Connection;
|
||||||
|
|
||||||
/*static*/ BaseConnection *BaseConnection::Create() {
|
BaseConnection *BaseConnection::Create() {
|
||||||
return &Connection;
|
return &Connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void BaseConnection::Destroy(BaseConnection *&c) {
|
void BaseConnection::Destroy(BaseConnection *&c) {
|
||||||
|
|
||||||
auto self = reinterpret_cast<BaseConnectionWin*>(c);
|
auto self = reinterpret_cast<BaseConnectionWin*>(c);
|
||||||
self->Close();
|
self->Close();
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Open() {
|
bool BaseConnection::Open() {
|
||||||
|
|
||||||
wchar_t pipeName[] { L"\\\\?\\pipe\\discord-ipc-0" };
|
wchar_t pipeName[] { L"\\\\?\\pipe\\discord-ipc-0" };
|
||||||
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
||||||
pipeName[pipeDigit] = L'0';
|
pipeName[pipeDigit] = L'0';
|
||||||
auto self = reinterpret_cast<BaseConnectionWin *>(this);
|
auto self = reinterpret_cast<BaseConnectionWin *>(this);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
self->pipe = ::CreateFileW(
|
self->pipe = ::CreateFileW(pipeName, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||||
pipeName, GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
|
|
||||||
if (self->pipe != INVALID_HANDLE_VALUE) {
|
if (self->pipe != INVALID_HANDLE_VALUE) {
|
||||||
self->isOpen = true;
|
self->isOpen = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -57,17 +83,22 @@ bool BaseConnection::Open() {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Close() {
|
bool BaseConnection::Close() {
|
||||||
|
|
||||||
auto self = reinterpret_cast<BaseConnectionWin *>(this);
|
auto self = reinterpret_cast<BaseConnectionWin *>(this);
|
||||||
::CloseHandle(self->pipe);
|
::CloseHandle(self->pipe);
|
||||||
self->pipe = INVALID_HANDLE_VALUE;
|
self->pipe = INVALID_HANDLE_VALUE;
|
||||||
self->isOpen = false;
|
self->isOpen = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Write(const void *data, size_t length) {
|
bool BaseConnection::Write(const void *data, size_t length) {
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -85,11 +116,13 @@ bool BaseConnection::Write(const void *data, size_t length) {
|
|||||||
}
|
}
|
||||||
const DWORD bytesLength = static_cast<DWORD>(length);
|
const DWORD bytesLength = static_cast<DWORD>(length);
|
||||||
DWORD bytesWritten = 0;
|
DWORD bytesWritten = 0;
|
||||||
return ::WriteFile(self->pipe, data, bytesLength, &bytesWritten, nullptr) == TRUE &&
|
|
||||||
bytesWritten == bytesLength;
|
return ::WriteFile(self->pipe, data, bytesLength, &bytesWritten, nullptr) == TRUE && bytesWritten == bytesLength;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Read(void *data, size_t length) {
|
bool BaseConnection::Read(void *data, size_t length) {
|
||||||
|
|
||||||
assert(data);
|
assert(data);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return false;
|
return false;
|
||||||
@@ -119,8 +152,9 @@ bool BaseConnection::Read(void *data, size_t length) {
|
|||||||
else {
|
else {
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
64
3rdparty/discord-rpc/discord_msg_queue.h
vendored
Normal file
64
3rdparty/discord-rpc/discord_msg_queue.h
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_MSG_QUEUE_H
|
||||||
|
#define DISCORD_MSG_QUEUE_H
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
// A simple queue. No locks, but only works with a single thread as producer and a single thread as
|
||||||
|
// a consumer. Mutex up as needed.
|
||||||
|
|
||||||
|
namespace discord_rpc {
|
||||||
|
|
||||||
|
template<typename ElementType, std::size_t QueueSize>
|
||||||
|
class MsgQueue {
|
||||||
|
ElementType queue_[QueueSize];
|
||||||
|
std::atomic_uint nextAdd_ { 0 };
|
||||||
|
std::atomic_uint nextSend_ { 0 };
|
||||||
|
std::atomic_uint pendingSends_ { 0 };
|
||||||
|
|
||||||
|
public:
|
||||||
|
MsgQueue() {}
|
||||||
|
|
||||||
|
ElementType *GetNextAddMessage() {
|
||||||
|
// if we are falling behind, bail
|
||||||
|
if (pendingSends_.load() >= QueueSize) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
auto index = (nextAdd_++) % QueueSize;
|
||||||
|
return &queue_[index];
|
||||||
|
}
|
||||||
|
void CommitAdd() { ++pendingSends_; }
|
||||||
|
|
||||||
|
bool HavePendingSends() const { return pendingSends_.load() != 0; }
|
||||||
|
ElementType *GetNextSendMessage() {
|
||||||
|
auto index = (nextSend_++) % QueueSize;
|
||||||
|
return &queue_[index];
|
||||||
|
}
|
||||||
|
void CommitSend() { --pendingSends_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
#endif // DISCORD_MSG_QUEUE_H
|
||||||
37
3rdparty/discord-rpc/discord_register.h
vendored
Normal file
37
3rdparty/discord-rpc/discord_register.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_REGISTER_H
|
||||||
|
#define DISCORD_REGISTER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void Discord_Register(const char *applicationId, const char *command);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // DISCORD_REGISTER_H
|
||||||
120
3rdparty/discord-rpc/discord_register_linux.cpp
vendored
Normal file
120
3rdparty/discord-rpc/discord_register_linux.cpp
vendored
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_rpc.h"
|
||||||
|
#include "discord_register.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
static bool Mkdir(const char *path) {
|
||||||
|
int result = mkdir(path, 0755);
|
||||||
|
if (result == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (errno == EEXIST) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// We want to register games so we can run them from Discord client as discord-<appid>://
|
||||||
|
extern "C" void Discord_Register(const char *applicationId, const char *command) {
|
||||||
|
|
||||||
|
// Add a desktop file and update some mime handlers so that xdg-open does the right thing.
|
||||||
|
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
if (!home) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char exePath[1024]{};
|
||||||
|
if (!command || !command[0]) {
|
||||||
|
const ssize_t size = readlink("/proc/self/exe", exePath, sizeof(exePath));
|
||||||
|
if (size <= 0 || size >= static_cast<ssize_t>(sizeof(exePath))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exePath[size] = '\0';
|
||||||
|
command = exePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr char desktopFileFormat[] = "[Desktop Entry]\n"
|
||||||
|
"Name=Game %s\n"
|
||||||
|
"Exec=%s %%u\n" // note: it really wants that %u in there
|
||||||
|
"Type=Application\n"
|
||||||
|
"NoDisplay=true\n"
|
||||||
|
"Categories=Discord;Games;\n"
|
||||||
|
"MimeType=x-scheme-handler/discord-%s;\n";
|
||||||
|
char desktopFile[2048]{};
|
||||||
|
int fileLen = snprintf(desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId);
|
||||||
|
if (fileLen <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char desktopFilename[256]{};
|
||||||
|
(void)snprintf(desktopFilename, sizeof(desktopFilename), "/discord-%s.desktop", applicationId);
|
||||||
|
|
||||||
|
char desktopFilePath[1024]{};
|
||||||
|
(void)snprintf(desktopFilePath, sizeof(desktopFilePath), "%s/.local", home);
|
||||||
|
if (!Mkdir(desktopFilePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strcat(desktopFilePath, "/share");
|
||||||
|
if (!Mkdir(desktopFilePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strcat(desktopFilePath, "/applications");
|
||||||
|
if (!Mkdir(desktopFilePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strcat(desktopFilePath, desktopFilename);
|
||||||
|
|
||||||
|
FILE *fp = fopen(desktopFilePath, "w");
|
||||||
|
if (fp) {
|
||||||
|
fwrite(desktopFile, 1, fileLen, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char xdgMimeCommand[1024]{};
|
||||||
|
snprintf(xdgMimeCommand,
|
||||||
|
sizeof(xdgMimeCommand),
|
||||||
|
"xdg-mime default discord-%s.desktop x-scheme-handler/discord-%s",
|
||||||
|
applicationId,
|
||||||
|
applicationId);
|
||||||
|
if (system(xdgMimeCommand) < 0) {
|
||||||
|
fprintf(stderr, "Failed to register mime handler\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
99
3rdparty/discord-rpc/discord_register_osx.m
vendored
Normal file
99
3rdparty/discord-rpc/discord_register_osx.m
vendored
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
|
#include "discord_register.h"
|
||||||
|
|
||||||
|
static void RegisterCommand(const char *applicationId, const char *command) {
|
||||||
|
|
||||||
|
// There does not appear to be a way to register arbitrary commands on OSX, so instead we'll save the command
|
||||||
|
// to a file in the Discord config path, and when it is needed, Discord can try to load the file there, open
|
||||||
|
// the command therein (will pass to js's window.open, so requires a url-like thing)
|
||||||
|
|
||||||
|
// Note: will not work for sandboxed apps
|
||||||
|
NSString *home = NSHomeDirectory();
|
||||||
|
if (!home) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *path = [[[[[[home stringByAppendingPathComponent:@"Library"]
|
||||||
|
stringByAppendingPathComponent:@"Application Support"]
|
||||||
|
stringByAppendingPathComponent:@"discord"]
|
||||||
|
stringByAppendingPathComponent:@"games"]
|
||||||
|
stringByAppendingPathComponent:[NSString stringWithUTF8String:applicationId]]
|
||||||
|
stringByAppendingPathExtension:@"json"];
|
||||||
|
[[NSFileManager defaultManager] createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
|
||||||
|
|
||||||
|
NSString *jsonBuffer = [NSString stringWithFormat:@"{\"command\": \"%s\"}", command];
|
||||||
|
[jsonBuffer writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RegisterURL(const char *applicationId) {
|
||||||
|
|
||||||
|
char url[256];
|
||||||
|
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
||||||
|
CFStringRef cfURL = CFStringCreateWithCString(NULL, url, kCFStringEncodingUTF8);
|
||||||
|
|
||||||
|
NSString* myBundleId = [[NSBundle mainBundle] bundleIdentifier];
|
||||||
|
if (!myBundleId) {
|
||||||
|
fprintf(stderr, "No bundle id found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSURL* myURL = [[NSBundle mainBundle] bundleURL];
|
||||||
|
if (!myURL) {
|
||||||
|
fprintf(stderr, "No bundle url found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OSStatus status = LSSetDefaultHandlerForURLScheme(cfURL, (__bridge CFStringRef)myBundleId);
|
||||||
|
if (status != noErr) {
|
||||||
|
fprintf(stderr, "Error in LSSetDefaultHandlerForURLScheme: %d\n", (int)status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = LSRegisterURL((__bridge CFURLRef)myURL, true);
|
||||||
|
if (status != noErr) {
|
||||||
|
fprintf(stderr, "Error in LSRegisterURL: %d\n", (int)status);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Discord_Register(const char *applicationId, const char *command) {
|
||||||
|
|
||||||
|
if (command) {
|
||||||
|
RegisterCommand(applicationId, command);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// raii lite
|
||||||
|
@autoreleasepool {
|
||||||
|
RegisterURL(applicationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "discord_rpc.h"
|
#include "discord_rpc.h"
|
||||||
#include "discord_register.h"
|
#include "discord_register.h"
|
||||||
|
|
||||||
@@ -5,6 +28,7 @@
|
|||||||
#define NOMCX
|
#define NOMCX
|
||||||
#define NOSERVICE
|
#define NOSERVICE
|
||||||
#define NOIME
|
#define NOIME
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -46,12 +70,8 @@ static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat,
|
|||||||
#endif
|
#endif
|
||||||
#define RegSetKeyValueW regset
|
#define RegSetKeyValueW regset
|
||||||
|
|
||||||
static LSTATUS regset(HKEY hkey,
|
static LSTATUS regset(HKEY hkey, LPCWSTR subkey, LPCWSTR name, DWORD type, const void *data, DWORD len) {
|
||||||
LPCWSTR subkey,
|
|
||||||
LPCWSTR name,
|
|
||||||
DWORD type,
|
|
||||||
const void *data,
|
|
||||||
DWORD len) {
|
|
||||||
HKEY htkey = hkey, hsubkey = nullptr;
|
HKEY htkey = hkey, hsubkey = nullptr;
|
||||||
LSTATUS ret;
|
LSTATUS ret;
|
||||||
if (subkey && subkey[0]) {
|
if (subkey && subkey[0]) {
|
||||||
@@ -64,16 +84,18 @@ static LSTATUS regset(HKEY hkey,
|
|||||||
if (hsubkey && hsubkey != hkey)
|
if (hsubkey && hsubkey != hkey)
|
||||||
RegCloseKey(hsubkey);
|
RegCloseKey(hsubkey);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Discord_RegisterW(const wchar_t *applicationId, const wchar_t *command) {
|
static void Discord_RegisterW(const wchar_t *applicationId, const wchar_t *command) {
|
||||||
|
|
||||||
// https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
|
// https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
|
||||||
// we want to register games so we can run them as discord-<appid>://
|
// we want to register games so we can run them as discord-<appid>://
|
||||||
// Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions.
|
// Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions.
|
||||||
|
|
||||||
wchar_t exeFilePath[MAX_PATH];
|
wchar_t exeFilePath[MAX_PATH]{};
|
||||||
DWORD exeLen = GetModuleFileNameW(nullptr, exeFilePath, MAX_PATH);
|
DWORD exeLen = GetModuleFileNameW(nullptr, exeFilePath, MAX_PATH);
|
||||||
wchar_t openCommand[1024];
|
wchar_t openCommand[1024]{};
|
||||||
|
|
||||||
if (command && command[0]) {
|
if (command && command[0]) {
|
||||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command);
|
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", command);
|
||||||
@@ -83,18 +105,16 @@ static void Discord_RegisterW(const wchar_t *applicationId, const wchar_t *comma
|
|||||||
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", exeFilePath);
|
StringCbPrintfW(openCommand, sizeof(openCommand), L"%s", exeFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t protocolName[64];
|
wchar_t protocolName[64]{};
|
||||||
StringCbPrintfW(protocolName, sizeof(protocolName), L"discord-%s", applicationId);
|
StringCbPrintfW(protocolName, sizeof(protocolName), L"discord-%s", applicationId);
|
||||||
wchar_t protocolDescription[128];
|
wchar_t protocolDescription[128]{};
|
||||||
StringCbPrintfW(
|
StringCbPrintfW(protocolDescription, sizeof(protocolDescription), L"URL:Run game %s protocol", applicationId);
|
||||||
protocolDescription, sizeof(protocolDescription), L"URL:Run game %s protocol", applicationId);
|
|
||||||
wchar_t urlProtocol = 0;
|
wchar_t urlProtocol = 0;
|
||||||
|
|
||||||
wchar_t keyName[256];
|
wchar_t keyName[256]{};
|
||||||
StringCbPrintfW(keyName, sizeof(keyName), L"Software\\Classes\\%s", protocolName);
|
StringCbPrintfW(keyName, sizeof(keyName), L"Software\\Classes\\%s", protocolName);
|
||||||
HKEY key;
|
HKEY key;
|
||||||
auto status =
|
auto status = RegCreateKeyExW(HKEY_CURRENT_USER, keyName, 0, nullptr, 0, KEY_WRITE, nullptr, &key, nullptr);
|
||||||
RegCreateKeyExW(HKEY_CURRENT_USER, keyName, 0, nullptr, 0, KEY_WRITE, nullptr, &key, nullptr);
|
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
fprintf(stderr, "Error creating key\n");
|
fprintf(stderr, "Error creating key\n");
|
||||||
return;
|
return;
|
||||||
@@ -102,8 +122,7 @@ static void Discord_RegisterW(const wchar_t *applicationId, const wchar_t *comma
|
|||||||
DWORD len;
|
DWORD len;
|
||||||
LSTATUS result;
|
LSTATUS result;
|
||||||
len = static_cast<DWORD>(lstrlenW(protocolDescription) + 1);
|
len = static_cast<DWORD>(lstrlenW(protocolDescription) + 1);
|
||||||
result =
|
result = RegSetKeyValueW(key, nullptr, nullptr, REG_SZ, protocolDescription, len * sizeof(wchar_t));
|
||||||
RegSetKeyValueW(key, nullptr, nullptr, REG_SZ, protocolDescription, len * sizeof(wchar_t));
|
|
||||||
if (FAILED(result)) {
|
if (FAILED(result)) {
|
||||||
fprintf(stderr, "Error writing description\n");
|
fprintf(stderr, "Error writing description\n");
|
||||||
}
|
}
|
||||||
@@ -114,26 +133,26 @@ static void Discord_RegisterW(const wchar_t *applicationId, const wchar_t *comma
|
|||||||
fprintf(stderr, "Error writing description\n");
|
fprintf(stderr, "Error writing description\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
result = RegSetKeyValueW(
|
result = RegSetKeyValueW(key, L"DefaultIcon", nullptr, REG_SZ, exeFilePath, (exeLen + 1) * sizeof(wchar_t));
|
||||||
key, L"DefaultIcon", nullptr, REG_SZ, exeFilePath, (exeLen + 1) * sizeof(wchar_t));
|
|
||||||
if (FAILED(result)) {
|
if (FAILED(result)) {
|
||||||
fprintf(stderr, "Error writing icon\n");
|
fprintf(stderr, "Error writing icon\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
len = static_cast<DWORD>(lstrlenW(openCommand) + 1);
|
len = static_cast<DWORD>(lstrlenW(openCommand) + 1);
|
||||||
result = RegSetKeyValueW(
|
result = RegSetKeyValueW(key, L"shell\\open\\command", nullptr, REG_SZ, openCommand, len * sizeof(wchar_t));
|
||||||
key, L"shell\\open\\command", nullptr, REG_SZ, openCommand, len * sizeof(wchar_t));
|
|
||||||
if (FAILED(result)) {
|
if (FAILED(result)) {
|
||||||
fprintf(stderr, "Error writing command\n");
|
fprintf(stderr, "Error writing command\n");
|
||||||
}
|
}
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_Register(const char *applicationId, const char *command) {
|
extern "C" void Discord_Register(const char *applicationId, const char *command) {
|
||||||
wchar_t appId[32];
|
|
||||||
|
wchar_t appId[32]{};
|
||||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||||
|
|
||||||
wchar_t openCommand[1024];
|
wchar_t openCommand[1024]{};
|
||||||
const wchar_t *wcommand = nullptr;
|
const wchar_t *wcommand = nullptr;
|
||||||
if (command && command[0]) {
|
if (command && command[0]) {
|
||||||
const auto commandBufferLen = sizeof(openCommand) / sizeof(*openCommand);
|
const auto commandBufferLen = sizeof(openCommand) / sizeof(*openCommand);
|
||||||
@@ -142,42 +161,6 @@ extern "C" void Discord_Register(const char *applicationId, const char *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Discord_RegisterW(appId, wcommand);
|
Discord_RegisterW(appId, wcommand);
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void Discord_RegisterSteamGame(const char *applicationId,
|
|
||||||
const char *steamId) {
|
|
||||||
wchar_t appId[32];
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
|
||||||
|
|
||||||
wchar_t wSteamId[32];
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, steamId, -1, wSteamId, 32);
|
|
||||||
|
|
||||||
HKEY key;
|
|
||||||
auto status = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", 0, KEY_READ, &key);
|
|
||||||
if (status != ERROR_SUCCESS) {
|
|
||||||
fprintf(stderr, "Error opening Steam key\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t steamPath[MAX_PATH];
|
|
||||||
DWORD pathBytes = sizeof(steamPath);
|
|
||||||
status = RegQueryValueExW(key, L"SteamExe", nullptr, nullptr, (BYTE *)steamPath, &pathBytes);
|
|
||||||
RegCloseKey(key);
|
|
||||||
if (status != ERROR_SUCCESS || pathBytes < 1) {
|
|
||||||
fprintf(stderr, "Error reading SteamExe key\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD pathChars = pathBytes / sizeof(wchar_t);
|
|
||||||
for (DWORD i = 0; i < pathChars; ++i) {
|
|
||||||
if (steamPath[i] == L'/') {
|
|
||||||
steamPath[i] = L'\\';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t command[1024];
|
|
||||||
StringCbPrintfW(command, sizeof(command), L"\"%s\" steam://rungameid/%s", steamPath, wSteamId);
|
|
||||||
|
|
||||||
Discord_RegisterW(appId, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,19 +1,44 @@
|
|||||||
#include "discord_rpc.h"
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
#include "backoff.h"
|
*
|
||||||
#include "discord_register.h"
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
#include "msg_queue.h"
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
#include "rpc_connection.h"
|
* the Software without restriction, including without limitation the rights to
|
||||||
#include "serialization.h"
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace discord_rpc {
|
#include "discord_rpc.h"
|
||||||
|
#include "discord_backoff.h"
|
||||||
|
#include "discord_register.h"
|
||||||
|
#include "discord_msg_queue.h"
|
||||||
|
#include "discord_rpc_connection.h"
|
||||||
|
#include "discord_serialization.h"
|
||||||
|
|
||||||
|
using namespace discord_rpc;
|
||||||
|
|
||||||
|
static void Discord_UpdateConnection();
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
constexpr size_t MaxMessageSize { 16 * 1024 };
|
constexpr size_t MaxMessageSize { 16 * 1024 };
|
||||||
constexpr size_t MessageQueueSize { 8 };
|
constexpr size_t MessageQueueSize { 8 };
|
||||||
@@ -67,14 +92,12 @@ static MsgQueue<QueuedMessage, MessageQueueSize> SendQueue;
|
|||||||
static MsgQueue<User, JoinQueueSize> JoinAskQueue;
|
static MsgQueue<User, JoinQueueSize> JoinAskQueue;
|
||||||
static User connectedUser;
|
static User connectedUser;
|
||||||
|
|
||||||
// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential
|
// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential backoff from 0.5 seconds to 1 minute
|
||||||
// backoff from 0.5 seconds to 1 minute
|
|
||||||
static Backoff ReconnectTimeMs(500, 60 * 1000);
|
static Backoff ReconnectTimeMs(500, 60 * 1000);
|
||||||
static auto NextConnect = std::chrono::system_clock::now();
|
static auto NextConnect = std::chrono::system_clock::now();
|
||||||
static int Pid { 0 };
|
static int Pid { 0 };
|
||||||
static int Nonce { 1 };
|
static int Nonce { 1 };
|
||||||
|
|
||||||
static void Discord_UpdateConnection(void);
|
|
||||||
class IoThreadHolder {
|
class IoThreadHolder {
|
||||||
private:
|
private:
|
||||||
std::atomic_bool keepRunning { true };
|
std::atomic_bool keepRunning { true };
|
||||||
@@ -108,14 +131,55 @@ class IoThreadHolder {
|
|||||||
|
|
||||||
~IoThreadHolder() { Stop(); }
|
~IoThreadHolder() { Stop(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static IoThreadHolder *IoThread { nullptr };
|
static IoThreadHolder *IoThread { nullptr };
|
||||||
|
|
||||||
static void UpdateReconnectTime() {
|
static void UpdateReconnectTime() {
|
||||||
NextConnect = std::chrono::system_clock::now() +
|
|
||||||
std::chrono::duration<int64_t, std::milli> { ReconnectTimeMs.nextDelay() };
|
NextConnect = std::chrono::system_clock::now() + std::chrono::duration<int64_t, std::milli> { ReconnectTimeMs.nextDelay() };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Discord_UpdateConnection(void) {
|
static void SignalIOActivity() {
|
||||||
|
|
||||||
|
if (IoThread != nullptr) {
|
||||||
|
IoThread->Notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool RegisterForEvent(const char *evtName) {
|
||||||
|
|
||||||
|
auto qmessage = SendQueue.GetNextAddMessage();
|
||||||
|
if (qmessage) {
|
||||||
|
qmessage->length = JsonWriteSubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName);
|
||||||
|
SendQueue.CommitAdd();
|
||||||
|
SignalIOActivity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool DeregisterForEvent(const char *evtName) {
|
||||||
|
|
||||||
|
auto qmessage = SendQueue.GetNextAddMessage();
|
||||||
|
if (qmessage) {
|
||||||
|
qmessage->length = JsonWriteUnsubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName);
|
||||||
|
SendQueue.CommitAdd();
|
||||||
|
SignalIOActivity();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
static void Discord_UpdateConnection() {
|
||||||
|
|
||||||
if (!Connection) {
|
if (!Connection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -217,54 +281,18 @@ static void Discord_UpdateConnection(void) {
|
|||||||
SendQueue.CommitSend();
|
SendQueue.CommitSend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SignalIOActivity() {
|
extern "C" void Discord_Initialize(const char *applicationId, DiscordEventHandlers *handlers, const int autoRegister) {
|
||||||
if (IoThread != nullptr) {
|
|
||||||
IoThread->Notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool RegisterForEvent(const char *evtName) {
|
|
||||||
auto qmessage = SendQueue.GetNextAddMessage();
|
|
||||||
if (qmessage) {
|
|
||||||
qmessage->length =
|
|
||||||
JsonWriteSubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName);
|
|
||||||
SendQueue.CommitAdd();
|
|
||||||
SignalIOActivity();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool DeregisterForEvent(const char *evtName) {
|
|
||||||
auto qmessage = SendQueue.GetNextAddMessage();
|
|
||||||
if (qmessage) {
|
|
||||||
qmessage->length =
|
|
||||||
JsonWriteUnsubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName);
|
|
||||||
SendQueue.CommitAdd();
|
|
||||||
SignalIOActivity();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void Discord_Initialize(const char *applicationId,
|
|
||||||
DiscordEventHandlers *handlers,
|
|
||||||
int autoRegister,
|
|
||||||
const char *optionalSteamId) {
|
|
||||||
IoThread = new (std::nothrow) IoThreadHolder();
|
IoThread = new (std::nothrow) IoThreadHolder();
|
||||||
if (IoThread == nullptr) {
|
if (IoThread == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoRegister) {
|
if (autoRegister) {
|
||||||
if (optionalSteamId && optionalSteamId[0]) {
|
Discord_Register(applicationId, nullptr);
|
||||||
Discord_RegisterSteamGame(applicationId, optionalSteamId);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Discord_Register(applicationId, nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pid = GetProcessId();
|
Pid = GetProcessId();
|
||||||
@@ -323,9 +351,11 @@ extern "C" void Discord_Initialize(const char *applicationId,
|
|||||||
};
|
};
|
||||||
|
|
||||||
IoThread->Start();
|
IoThread->Start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_Shutdown(void) {
|
extern "C" void Discord_Shutdown() {
|
||||||
|
|
||||||
if (!Connection) {
|
if (!Connection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -341,16 +371,19 @@ extern "C" void Discord_Shutdown(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RpcConnection::Destroy(Connection);
|
RpcConnection::Destroy(Connection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) {
|
extern "C" void Discord_UpdatePresence(const DiscordRichPresence *presence) {
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(PresenceMutex);
|
std::lock_guard<std::mutex> guard(PresenceMutex);
|
||||||
QueuedPresence.length = JsonWriteRichPresenceObj(
|
QueuedPresence.length = JsonWriteRichPresenceObj(QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
|
||||||
QueuedPresence.buffer, sizeof(QueuedPresence.buffer), Nonce++, Pid, presence);
|
|
||||||
UpdatePresence.exchange(true);
|
UpdatePresence.exchange(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalIOActivity();
|
SignalIOActivity();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_ClearPresence(void) {
|
extern "C" void Discord_ClearPresence(void) {
|
||||||
@@ -358,20 +391,22 @@ extern "C" void Discord_ClearPresence(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_Respond(const char *userId, /* DISCORD_REPLY_ */ int reply) {
|
extern "C" void Discord_Respond(const char *userId, /* DISCORD_REPLY_ */ int reply) {
|
||||||
|
|
||||||
// if we are not connected, let's not batch up stale messages for later
|
// if we are not connected, let's not batch up stale messages for later
|
||||||
if (!Connection || !Connection->IsOpen()) {
|
if (!Connection || !Connection->IsOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto qmessage = SendQueue.GetNextAddMessage();
|
auto qmessage = SendQueue.GetNextAddMessage();
|
||||||
if (qmessage) {
|
if (qmessage) {
|
||||||
qmessage->length =
|
qmessage->length = JsonWriteJoinReply(qmessage->buffer, sizeof(qmessage->buffer), userId, reply, Nonce++);
|
||||||
JsonWriteJoinReply(qmessage->buffer, sizeof(qmessage->buffer), userId, reply, Nonce++);
|
|
||||||
SendQueue.CommitAdd();
|
SendQueue.CommitAdd();
|
||||||
SignalIOActivity();
|
SignalIOActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_RunCallbacks(void) {
|
extern "C" void Discord_RunCallbacks() {
|
||||||
|
|
||||||
// Note on some weirdness: internally we might connect, get other signals, disconnect any number
|
// Note on some weirdness: internally we might connect, get other signals, disconnect any number
|
||||||
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
||||||
// signals are book-ended by calls to ready and disconnect.
|
// signals are book-ended by calls to ready and disconnect.
|
||||||
@@ -380,8 +415,8 @@ extern "C" void Discord_RunCallbacks(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wasDisconnected = WasJustDisconnected.exchange(false);
|
const bool wasDisconnected = WasJustDisconnected.exchange(false);
|
||||||
bool isConnected = Connection->IsOpen();
|
const bool isConnected = Connection->IsOpen();
|
||||||
|
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
// if we are connected, disconnect cb first
|
// if we are connected, disconnect cb first
|
||||||
@@ -394,10 +429,7 @@ extern "C" void Discord_RunCallbacks(void) {
|
|||||||
if (WasJustConnected.exchange(false)) {
|
if (WasJustConnected.exchange(false)) {
|
||||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||||
if (Handlers.ready) {
|
if (Handlers.ready) {
|
||||||
DiscordUser du { connectedUser.userId,
|
DiscordUser du { connectedUser.userId, connectedUser.username, connectedUser.discriminator, connectedUser.avatar };
|
||||||
connectedUser.username,
|
|
||||||
connectedUser.discriminator,
|
|
||||||
connectedUser.avatar };
|
|
||||||
Handlers.ready(&du);
|
Handlers.ready(&du);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -429,7 +461,7 @@ extern "C" void Discord_RunCallbacks(void) {
|
|||||||
// maybe show them in one common dialog and/or start fetching the avatars in parallel, and if
|
// maybe show them in one common dialog and/or start fetching the avatars in parallel, and if
|
||||||
// not it should be trivial for the implementer to make a queue themselves.
|
// not it should be trivial for the implementer to make a queue themselves.
|
||||||
while (JoinAskQueue.HavePendingSends()) {
|
while (JoinAskQueue.HavePendingSends()) {
|
||||||
auto req = JoinAskQueue.GetNextSendMessage();
|
const auto req = JoinAskQueue.GetNextSendMessage();
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||||
if (Handlers.joinRequest) {
|
if (Handlers.joinRequest) {
|
||||||
@@ -447,9 +479,11 @@ extern "C" void Discord_RunCallbacks(void) {
|
|||||||
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
|
extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
|
||||||
|
|
||||||
if (newHandlers) {
|
if (newHandlers) {
|
||||||
#define HANDLE_EVENT_REGISTRATION(handler_name, event) \
|
#define HANDLE_EVENT_REGISTRATION(handler_name, event) \
|
||||||
if (!Handlers.handler_name && newHandlers->handler_name) { \
|
if (!Handlers.handler_name && newHandlers->handler_name) { \
|
||||||
@@ -472,8 +506,5 @@ extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
|
|||||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||||
Handlers = {};
|
Handlers = {};
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
|
|
||||||
93
3rdparty/discord-rpc/discord_rpc.h
vendored
Normal file
93
3rdparty/discord-rpc/discord_rpc.h
vendored
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_RPC_H
|
||||||
|
#define DISCORD_RPC_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct DiscordRichPresence {
|
||||||
|
int type;
|
||||||
|
const char *name; /* max 128 bytes */
|
||||||
|
const char *state; /* max 128 bytes */
|
||||||
|
const char *details; /* max 128 bytes */
|
||||||
|
int64_t startTimestamp;
|
||||||
|
int64_t endTimestamp;
|
||||||
|
const char *largeImageKey; /* max 32 bytes */
|
||||||
|
const char *largeImageText; /* max 128 bytes */
|
||||||
|
const char *smallImageKey; /* max 32 bytes */
|
||||||
|
const char *smallImageText; /* max 128 bytes */
|
||||||
|
const char *partyId; /* max 128 bytes */
|
||||||
|
int partySize;
|
||||||
|
int partyMax;
|
||||||
|
int partyPrivacy;
|
||||||
|
const char *matchSecret; /* max 128 bytes */
|
||||||
|
const char *joinSecret; /* max 128 bytes */
|
||||||
|
const char *spectateSecret; /* max 128 bytes */
|
||||||
|
int8_t instance;
|
||||||
|
} DiscordRichPresence;
|
||||||
|
|
||||||
|
typedef struct DiscordUser {
|
||||||
|
const char *userId;
|
||||||
|
const char *username;
|
||||||
|
const char *discriminator;
|
||||||
|
const char *avatar;
|
||||||
|
} DiscordUser;
|
||||||
|
|
||||||
|
typedef struct DiscordEventHandlers {
|
||||||
|
void (*ready)(const DiscordUser *request);
|
||||||
|
void (*disconnected)(int errorCode, const char *message);
|
||||||
|
void (*errored)(int errorCode, const char *message);
|
||||||
|
void (*joinGame)(const char *joinSecret);
|
||||||
|
void (*spectateGame)(const char *spectateSecret);
|
||||||
|
void (*joinRequest)(const DiscordUser *request);
|
||||||
|
} DiscordEventHandlers;
|
||||||
|
|
||||||
|
#define DISCORD_REPLY_NO 0
|
||||||
|
#define DISCORD_REPLY_YES 1
|
||||||
|
#define DISCORD_REPLY_IGNORE 2
|
||||||
|
#define DISCORD_PARTY_PRIVATE 0
|
||||||
|
#define DISCORD_PARTY_PUBLIC 1
|
||||||
|
|
||||||
|
void Discord_Initialize(const char *applicationId, DiscordEventHandlers *handlers, const int autoRegister);
|
||||||
|
void Discord_Shutdown(void);
|
||||||
|
|
||||||
|
// checks for incoming messages, dispatches callbacks
|
||||||
|
void Discord_RunCallbacks(void);
|
||||||
|
|
||||||
|
void Discord_UpdatePresence(const DiscordRichPresence *presence);
|
||||||
|
void Discord_ClearPresence(void);
|
||||||
|
|
||||||
|
void Discord_Respond(const char *userid, /* DISCORD_REPLY_ */ int reply);
|
||||||
|
|
||||||
|
void Discord_UpdateHandlers(DiscordEventHandlers *handlers);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // DISCORD_RPC_H
|
||||||
@@ -1,24 +1,52 @@
|
|||||||
#include "rpc_connection.h"
|
/*
|
||||||
#include "serialization.h"
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_rpc_connection.h"
|
||||||
|
#include "discord_serialization.h"
|
||||||
|
|
||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
static const int RpcVersion = 1;
|
static const int RpcVersion = 1;
|
||||||
static RpcConnection Instance;
|
static RpcConnection Instance;
|
||||||
|
|
||||||
/*static*/ RpcConnection *RpcConnection::Create(const char *applicationId) {
|
RpcConnection *RpcConnection::Create(const char *applicationId) {
|
||||||
|
|
||||||
Instance.connection = BaseConnection::Create();
|
Instance.connection = BaseConnection::Create();
|
||||||
StringCopy(Instance.appId, applicationId);
|
StringCopy(Instance.appId, applicationId);
|
||||||
return &Instance;
|
return &Instance;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void RpcConnection::Destroy(RpcConnection *&c) {
|
void RpcConnection::Destroy(RpcConnection *&c) {
|
||||||
|
|
||||||
c->Close();
|
c->Close();
|
||||||
BaseConnection::Destroy(c->connection);
|
BaseConnection::Destroy(c->connection);
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcConnection::Open() {
|
void RpcConnection::Open() {
|
||||||
|
|
||||||
if (state == State::Connected) {
|
if (state == State::Connected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -51,17 +79,21 @@ void RpcConnection::Open() {
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcConnection::Close() {
|
void RpcConnection::Close() {
|
||||||
|
|
||||||
if (onDisconnect && (state == State::Connected || state == State::SentHandshake)) {
|
if (onDisconnect && (state == State::Connected || state == State::SentHandshake)) {
|
||||||
onDisconnect(lastErrorCode, lastErrorMessage);
|
onDisconnect(lastErrorCode, lastErrorMessage);
|
||||||
}
|
}
|
||||||
connection->Close();
|
connection->Close();
|
||||||
state = State::Disconnected;
|
state = State::Disconnected;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RpcConnection::Write(const void *data, size_t length) {
|
bool RpcConnection::Write(const void *data, size_t length) {
|
||||||
|
|
||||||
sendFrame.opcode = Opcode::Frame;
|
sendFrame.opcode = Opcode::Frame;
|
||||||
memcpy(sendFrame.message, data, length);
|
memcpy(sendFrame.message, data, length);
|
||||||
sendFrame.length = static_cast<uint32_t>(length);
|
sendFrame.length = static_cast<uint32_t>(length);
|
||||||
@@ -69,14 +101,17 @@ bool RpcConnection::Write(const void *data, size_t length) {
|
|||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RpcConnection::Read(JsonDocument &message) {
|
bool RpcConnection::Read(JsonDocument &message) {
|
||||||
|
|
||||||
if (state != State::Connected && state != State::SentHandshake) {
|
if (state != State::Connected && state != State::SentHandshake) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MessageFrame readFrame;
|
MessageFrame readFrame{};
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bool didRead = connection->Read(&readFrame, sizeof(MessageFrameHeader));
|
bool didRead = connection->Read(&readFrame, sizeof(MessageFrameHeader));
|
||||||
if (!didRead) {
|
if (!didRead) {
|
||||||
@@ -127,7 +162,7 @@ bool RpcConnection::Read(JsonDocument &message) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
88
3rdparty/discord-rpc/discord_rpc_connection.h
vendored
Normal file
88
3rdparty/discord-rpc/discord_rpc_connection.h
vendored
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_RPC_CONNECTION_H
|
||||||
|
#define DISCORD_RPC_CONNECTION_H
|
||||||
|
|
||||||
|
#include "discord_connection.h"
|
||||||
|
#include "discord_serialization.h"
|
||||||
|
|
||||||
|
namespace discord_rpc {
|
||||||
|
|
||||||
|
// I took this from the buffer size libuv uses for named pipes; I suspect ours would usually be much smaller.
|
||||||
|
constexpr size_t MaxRpcFrameSize = 64 * 1024;
|
||||||
|
|
||||||
|
struct RpcConnection {
|
||||||
|
enum class ErrorCode : int {
|
||||||
|
Success = 0,
|
||||||
|
PipeClosed = 1,
|
||||||
|
ReadCorrupt = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Opcode : uint32_t {
|
||||||
|
Handshake = 0,
|
||||||
|
Frame = 1,
|
||||||
|
Close = 2,
|
||||||
|
Ping = 3,
|
||||||
|
Pong = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MessageFrameHeader {
|
||||||
|
Opcode opcode;
|
||||||
|
uint32_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MessageFrame : public MessageFrameHeader {
|
||||||
|
char message[MaxRpcFrameSize - sizeof(MessageFrameHeader)];
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class State : uint32_t {
|
||||||
|
Disconnected,
|
||||||
|
SentHandshake,
|
||||||
|
AwaitingResponse,
|
||||||
|
Connected,
|
||||||
|
};
|
||||||
|
|
||||||
|
BaseConnection *connection { nullptr };
|
||||||
|
State state { State::Disconnected };
|
||||||
|
void (*onConnect)(JsonDocument &message) { nullptr };
|
||||||
|
void (*onDisconnect)(int errorCode, const char *message) { nullptr };
|
||||||
|
char appId[64] {};
|
||||||
|
int lastErrorCode { 0 };
|
||||||
|
char lastErrorMessage[256] {};
|
||||||
|
RpcConnection::MessageFrame sendFrame;
|
||||||
|
|
||||||
|
static RpcConnection *Create(const char *applicationId);
|
||||||
|
static void Destroy(RpcConnection *&);
|
||||||
|
|
||||||
|
inline bool IsOpen() const { return state == State::Connected; }
|
||||||
|
|
||||||
|
void Open();
|
||||||
|
void Close();
|
||||||
|
bool Write(const void *data, size_t length);
|
||||||
|
bool Read(JsonDocument &message);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
#endif // DISCORD_RPC_CONNECTION_H
|
||||||
@@ -1,11 +1,35 @@
|
|||||||
#include "serialization.h"
|
/*
|
||||||
#include "connection.h"
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "discord_serialization.h"
|
||||||
|
#include "discord_connection.h"
|
||||||
#include "discord_rpc.h"
|
#include "discord_rpc.h"
|
||||||
|
|
||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void NumberToString(char *dest, T number) {
|
void NumberToString(char *dest, T number) {
|
||||||
|
|
||||||
if (!number) {
|
if (!number) {
|
||||||
*dest++ = '0';
|
*dest++ = '0';
|
||||||
*dest++ = 0;
|
*dest++ = 0;
|
||||||
@@ -26,6 +50,7 @@ void NumberToString(char *dest, T number) {
|
|||||||
*dest++ = temp[place];
|
*dest++ = temp[place];
|
||||||
}
|
}
|
||||||
*dest = 0;
|
*dest = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// it's ever so slightly faster to not have to strlen the key
|
// it's ever so slightly faster to not have to strlen the key
|
||||||
@@ -62,24 +87,25 @@ struct WriteArray {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void WriteOptionalString(JsonWriter &w, T &k, const char *value) {
|
void WriteOptionalString(JsonWriter &w, T &k, const char *value) {
|
||||||
|
|
||||||
if (value && value[0]) {
|
if (value && value[0]) {
|
||||||
w.Key(k, sizeof(T) - 1);
|
w.Key(k, sizeof(T) - 1);
|
||||||
w.String(value);
|
w.String(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void JsonWriteNonce(JsonWriter &writer, int nonce) {
|
static void JsonWriteNonce(JsonWriter &writer, const int nonce) {
|
||||||
|
|
||||||
WriteKey(writer, "nonce");
|
WriteKey(writer, "nonce");
|
||||||
char nonceBuffer[32];
|
char nonceBuffer[32];
|
||||||
NumberToString(nonceBuffer, nonce);
|
NumberToString(nonceBuffer, nonce);
|
||||||
writer.String(nonceBuffer);
|
writer.String(nonceBuffer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteRichPresenceObj(char *dest,
|
size_t JsonWriteRichPresenceObj(char *dest, const size_t maxLen, const int nonce, const int pid, const DiscordRichPresence *presence) {
|
||||||
size_t maxLen,
|
|
||||||
int nonce,
|
|
||||||
int pid,
|
|
||||||
const DiscordRichPresence *presence) {
|
|
||||||
JsonWriter writer(dest, maxLen);
|
JsonWriter writer(dest, maxLen);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -168,6 +194,7 @@ size_t JsonWriteRichPresenceObj(char *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId) {
|
size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId) {
|
||||||
|
|
||||||
JsonWriter writer(dest, maxLen);
|
JsonWriter writer(dest, maxLen);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -179,9 +206,11 @@ size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
return writer.Size();
|
return writer.Size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName) {
|
size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName) {
|
||||||
|
|
||||||
JsonWriter writer(dest, maxLen);
|
JsonWriter writer(dest, maxLen);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -197,9 +226,11 @@ size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
return writer.Size();
|
return writer.Size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteUnsubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName) {
|
size_t JsonWriteUnsubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName) {
|
||||||
|
|
||||||
JsonWriter writer(dest, maxLen);
|
JsonWriter writer(dest, maxLen);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -215,9 +246,11 @@ size_t JsonWriteUnsubscribeCommand(char *dest, size_t maxLen, int nonce, const c
|
|||||||
}
|
}
|
||||||
|
|
||||||
return writer.Size();
|
return writer.Size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsonWriteJoinReply(char *dest, size_t maxLen, const char *userId, int reply, int nonce) {
|
size_t JsonWriteJoinReply(char *dest, size_t maxLen, const char *userId, const int reply, const int nonce) {
|
||||||
|
|
||||||
JsonWriter writer(dest, maxLen);
|
JsonWriter writer(dest, maxLen);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -243,7 +276,7 @@ size_t JsonWriteJoinReply(char *dest, size_t maxLen, const char *userId, int rep
|
|||||||
}
|
}
|
||||||
|
|
||||||
return writer.Size();
|
return writer.Size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
@@ -1,9 +1,35 @@
|
|||||||
#pragma once
|
/*
|
||||||
|
* Copyright 2017 Discord, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISCORD_SERIALIZATION_H
|
||||||
|
#define DISCORD_SERIALIZATION_H
|
||||||
|
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include <rapidjson/stringbuffer.h>
|
#include <rapidjson/stringbuffer.h>
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
|
struct DiscordRichPresence;
|
||||||
|
|
||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
// if only there was a standard library function for this
|
// if only there was a standard library function for this
|
||||||
@@ -24,12 +50,7 @@ inline size_t StringCopy(char (&dest)[Len], const char *src) {
|
|||||||
size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId);
|
size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId);
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
struct DiscordRichPresence;
|
size_t JsonWriteRichPresenceObj(char *dest, const size_t maxLen, const int nonce, const int pid, const DiscordRichPresence *presence);
|
||||||
size_t JsonWriteRichPresenceObj(char *dest,
|
|
||||||
size_t maxLen,
|
|
||||||
int nonce,
|
|
||||||
int pid,
|
|
||||||
const DiscordRichPresence *presence);
|
|
||||||
size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName);
|
size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName);
|
||||||
|
|
||||||
size_t JsonWriteUnsubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName);
|
size_t JsonWriteUnsubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName);
|
||||||
@@ -149,35 +170,44 @@ class JsonDocument : public JsonDocumentBase {
|
|||||||
using JsonValue = rapidjson::GenericValue<UTF8, PoolAllocator>;
|
using JsonValue = rapidjson::GenericValue<UTF8, PoolAllocator>;
|
||||||
|
|
||||||
inline JsonValue *GetObjMember(JsonValue *obj, const char *name) {
|
inline JsonValue *GetObjMember(JsonValue *obj, const char *name) {
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
auto member = obj->FindMember(name);
|
auto member = obj->FindMember(name);
|
||||||
if (member != obj->MemberEnd() && member->value.IsObject()) {
|
if (member != obj->MemberEnd() && member->value.IsObject()) {
|
||||||
return &member->value;
|
return &member->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int GetIntMember(JsonValue *obj, const char *name, int notFoundDefault = 0) {
|
inline int GetIntMember(JsonValue *obj, const char *name, int notFoundDefault = 0) {
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
auto member = obj->FindMember(name);
|
auto member = obj->FindMember(name);
|
||||||
if (member != obj->MemberEnd() && member->value.IsInt()) {
|
if (member != obj->MemberEnd() && member->value.IsInt()) {
|
||||||
return member->value.GetInt();
|
return member->value.GetInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return notFoundDefault;
|
return notFoundDefault;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char *GetStrMember(JsonValue *obj,
|
inline const char *GetStrMember(JsonValue *obj, const char *name, const char *notFoundDefault = nullptr) {
|
||||||
const char *name,
|
|
||||||
const char *notFoundDefault = nullptr) {
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
auto member = obj->FindMember(name);
|
auto member = obj->FindMember(name);
|
||||||
if (member != obj->MemberEnd() && member->value.IsString()) {
|
if (member != obj->MemberEnd() && member->value.IsString()) {
|
||||||
return member->value.GetString();
|
return member->value.GetString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return notFoundDefault;
|
return notFoundDefault;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
} // namespace discord_rpc
|
||||||
|
|
||||||
|
#endif // DISCORD_SERIALIZATION_H
|
||||||
12
3rdparty/discord-rpc/include/discord_register.h
vendored
12
3rdparty/discord-rpc/include/discord_register.h
vendored
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Discord_Register(const char* applicationId, const char* command);
|
|
||||||
void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
77
3rdparty/discord-rpc/include/discord_rpc.h
vendored
77
3rdparty/discord-rpc/include/discord_rpc.h
vendored
@@ -1,77 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct DiscordRichPresence {
|
|
||||||
int type;
|
|
||||||
const char* name; /* max 128 bytes */
|
|
||||||
const char* state; /* max 128 bytes */
|
|
||||||
const char* details; /* max 128 bytes */
|
|
||||||
int64_t startTimestamp;
|
|
||||||
int64_t endTimestamp;
|
|
||||||
const char* largeImageKey; /* max 32 bytes */
|
|
||||||
const char* largeImageText; /* max 128 bytes */
|
|
||||||
const char* smallImageKey; /* max 32 bytes */
|
|
||||||
const char* smallImageText; /* max 128 bytes */
|
|
||||||
const char* partyId; /* max 128 bytes */
|
|
||||||
int partySize;
|
|
||||||
int partyMax;
|
|
||||||
int partyPrivacy;
|
|
||||||
const char* matchSecret; /* max 128 bytes */
|
|
||||||
const char* joinSecret; /* max 128 bytes */
|
|
||||||
const char* spectateSecret; /* max 128 bytes */
|
|
||||||
int8_t instance;
|
|
||||||
} DiscordRichPresence;
|
|
||||||
|
|
||||||
typedef struct DiscordUser {
|
|
||||||
const char* userId;
|
|
||||||
const char* username;
|
|
||||||
const char* discriminator;
|
|
||||||
const char* avatar;
|
|
||||||
} DiscordUser;
|
|
||||||
|
|
||||||
typedef struct DiscordEventHandlers {
|
|
||||||
void (*ready)(const DiscordUser* request);
|
|
||||||
void (*disconnected)(int errorCode, const char* message);
|
|
||||||
void (*errored)(int errorCode, const char* message);
|
|
||||||
void (*joinGame)(const char* joinSecret);
|
|
||||||
void (*spectateGame)(const char* spectateSecret);
|
|
||||||
void (*joinRequest)(const DiscordUser* request);
|
|
||||||
} DiscordEventHandlers;
|
|
||||||
|
|
||||||
#define DISCORD_REPLY_NO 0
|
|
||||||
#define DISCORD_REPLY_YES 1
|
|
||||||
#define DISCORD_REPLY_IGNORE 2
|
|
||||||
#define DISCORD_PARTY_PRIVATE 0
|
|
||||||
#define DISCORD_PARTY_PUBLIC 1
|
|
||||||
|
|
||||||
void Discord_Initialize(const char* applicationId,
|
|
||||||
DiscordEventHandlers* handlers,
|
|
||||||
int autoRegister,
|
|
||||||
const char* optionalSteamId);
|
|
||||||
void Discord_Shutdown(void);
|
|
||||||
|
|
||||||
/* checks for incoming messages, dispatches callbacks */
|
|
||||||
void Discord_RunCallbacks(void);
|
|
||||||
|
|
||||||
void Discord_UpdatePresence(const DiscordRichPresence* presence);
|
|
||||||
void Discord_ClearPresence(void);
|
|
||||||
|
|
||||||
void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
|
|
||||||
|
|
||||||
void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
} // namespace discord_rpc
|
|
||||||
|
|
||||||
#endif
|
|
||||||
41
3rdparty/discord-rpc/src/CMakeLists.txt
vendored
41
3rdparty/discord-rpc/src/CMakeLists.txt
vendored
@@ -1,41 +0,0 @@
|
|||||||
set(DISCORD_RPC_SOURCES
|
|
||||||
../include/discord_rpc.h
|
|
||||||
../include/discord_register.h
|
|
||||||
discord_rpc.cpp
|
|
||||||
rpc_connection.h
|
|
||||||
rpc_connection.cpp
|
|
||||||
serialization.h
|
|
||||||
serialization.cpp
|
|
||||||
connection.h
|
|
||||||
backoff.h
|
|
||||||
msg_queue.h
|
|
||||||
)
|
|
||||||
|
|
||||||
if(UNIX)
|
|
||||||
list(APPEND DISCORD_RPC_SOURCES connection_unix.cpp)
|
|
||||||
if(APPLE)
|
|
||||||
list(APPEND DISCORD_RPC_SOURCES discord_register_osx.m)
|
|
||||||
add_definitions(-DDISCORD_OSX)
|
|
||||||
else()
|
|
||||||
list(APPEND DISCORD_RPC_SOURCES discord_register_linux.cpp)
|
|
||||||
add_definitions(-DDISCORD_LINUX)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
list(APPEND DISCORD_RPC_SOURCES connection_win.cpp discord_register_win.cpp)
|
|
||||||
add_definitions(-DDISCORD_WINDOWS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(discord-rpc STATIC ${DISCORD_RPC_SOURCES})
|
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
target_link_libraries(discord-rpc PRIVATE "-framework AppKit")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
target_link_libraries(discord-rpc PRIVATE psapi advapi32)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(discord-rpc SYSTEM PRIVATE ${RapidJSON_INCLUDE_DIRS})
|
|
||||||
target_include_directories(discord-rpc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
|
||||||
44
3rdparty/discord-rpc/src/backoff.h
vendored
44
3rdparty/discord-rpc/src/backoff.h
vendored
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <random>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
struct Backoff {
|
|
||||||
int64_t minAmount;
|
|
||||||
int64_t maxAmount;
|
|
||||||
int64_t current;
|
|
||||||
int fails;
|
|
||||||
std::mt19937_64 randGenerator;
|
|
||||||
std::uniform_real_distribution<> randDistribution;
|
|
||||||
|
|
||||||
double rand01() { return randDistribution(randGenerator); }
|
|
||||||
|
|
||||||
Backoff(int64_t min, int64_t max)
|
|
||||||
: minAmount(min)
|
|
||||||
, maxAmount(max)
|
|
||||||
, current(min)
|
|
||||||
, fails(0)
|
|
||||||
, randGenerator(static_cast<uint64_t>(time(0)))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset()
|
|
||||||
{
|
|
||||||
fails = 0;
|
|
||||||
current = minAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t nextDelay()
|
|
||||||
{
|
|
||||||
++fails;
|
|
||||||
int64_t delay = static_cast<int64_t>(static_cast<double>(current) * 2.0 * rand01());
|
|
||||||
current = std::min(current + delay, maxAmount);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
22
3rdparty/discord-rpc/src/connection.h
vendored
22
3rdparty/discord-rpc/src/connection.h
vendored
@@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// This is to wrap the platform specific kinds of connect/read/write.
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
// not really connectiony, but need per-platform
|
|
||||||
int GetProcessId();
|
|
||||||
|
|
||||||
struct BaseConnection {
|
|
||||||
static BaseConnection *Create();
|
|
||||||
static void Destroy(BaseConnection *&);
|
|
||||||
bool isOpen { false };
|
|
||||||
bool Open();
|
|
||||||
bool Close();
|
|
||||||
bool Write(const void *data, size_t length);
|
|
||||||
bool Read(void *data, size_t length);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
104
3rdparty/discord-rpc/src/discord_register_linux.cpp
vendored
104
3rdparty/discord-rpc/src/discord_register_linux.cpp
vendored
@@ -1,104 +0,0 @@
|
|||||||
#include "discord_rpc.h"
|
|
||||||
#include "discord_register.h"
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
static bool Mkdir(const char *path) {
|
|
||||||
int result = mkdir(path, 0755);
|
|
||||||
if (result == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (errno == EEXIST) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// we want to register games so we can run them from Discord client as discord-<appid>://
|
|
||||||
extern "C" void Discord_Register(const char *applicationId, const char *command) {
|
|
||||||
// Add a desktop file and update some mime handlers so that xdg-open does the right thing.
|
|
||||||
|
|
||||||
const char *home = getenv("HOME");
|
|
||||||
if (!home) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char exePath[1024];
|
|
||||||
if (!command || !command[0]) {
|
|
||||||
ssize_t size = readlink("/proc/self/exe", exePath, sizeof(exePath));
|
|
||||||
if (size <= 0 || size >= static_cast<ssize_t>(sizeof(exePath))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exePath[size] = '\0';
|
|
||||||
command = exePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr char desktopFileFormat[] = "[Desktop Entry]\n"
|
|
||||||
"Name=Game %s\n"
|
|
||||||
"Exec=%s %%u\n" // note: it really wants that %u in there
|
|
||||||
"Type=Application\n"
|
|
||||||
"NoDisplay=true\n"
|
|
||||||
"Categories=Discord;Games;\n"
|
|
||||||
"MimeType=x-scheme-handler/discord-%s;\n";
|
|
||||||
char desktopFile[2048];
|
|
||||||
int fileLen = snprintf(
|
|
||||||
desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId);
|
|
||||||
if (fileLen <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char desktopFilename[256];
|
|
||||||
(void)snprintf(desktopFilename, sizeof(desktopFilename), "/discord-%s.desktop", applicationId);
|
|
||||||
|
|
||||||
char desktopFilePath[1024];
|
|
||||||
(void)snprintf(desktopFilePath, sizeof(desktopFilePath), "%s/.local", home);
|
|
||||||
if (!Mkdir(desktopFilePath)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcat(desktopFilePath, "/share");
|
|
||||||
if (!Mkdir(desktopFilePath)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcat(desktopFilePath, "/applications");
|
|
||||||
if (!Mkdir(desktopFilePath)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcat(desktopFilePath, desktopFilename);
|
|
||||||
|
|
||||||
FILE *fp = fopen(desktopFilePath, "w");
|
|
||||||
if (fp) {
|
|
||||||
fwrite(desktopFile, 1, fileLen, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char xdgMimeCommand[1024];
|
|
||||||
snprintf(xdgMimeCommand,
|
|
||||||
sizeof(xdgMimeCommand),
|
|
||||||
"xdg-mime default discord-%s.desktop x-scheme-handler/discord-%s",
|
|
||||||
applicationId,
|
|
||||||
applicationId);
|
|
||||||
if (system(xdgMimeCommand) < 0) {
|
|
||||||
fprintf(stderr, "Failed to register mime handler\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void Discord_RegisterSteamGame(const char *applicationId,
|
|
||||||
const char *steamId) {
|
|
||||||
char command[256];
|
|
||||||
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
|
||||||
Discord_Register(applicationId, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
80
3rdparty/discord-rpc/src/discord_register_osx.m
vendored
80
3rdparty/discord-rpc/src/discord_register_osx.m
vendored
@@ -1,80 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
|
||||||
|
|
||||||
#include "discord_register.h"
|
|
||||||
|
|
||||||
static void RegisterCommand(const char* applicationId, const char* command)
|
|
||||||
{
|
|
||||||
// There does not appear to be a way to register arbitrary commands on OSX, so instead we'll save the command
|
|
||||||
// to a file in the Discord config path, and when it is needed, Discord can try to load the file there, open
|
|
||||||
// the command therein (will pass to js's window.open, so requires a url-like thing)
|
|
||||||
|
|
||||||
// Note: will not work for sandboxed apps
|
|
||||||
NSString *home = NSHomeDirectory();
|
|
||||||
if (!home) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *path = [[[[[[home stringByAppendingPathComponent:@"Library"]
|
|
||||||
stringByAppendingPathComponent:@"Application Support"]
|
|
||||||
stringByAppendingPathComponent:@"discord"]
|
|
||||||
stringByAppendingPathComponent:@"games"]
|
|
||||||
stringByAppendingPathComponent:[NSString stringWithUTF8String:applicationId]]
|
|
||||||
stringByAppendingPathExtension:@"json"];
|
|
||||||
[[NSFileManager defaultManager] createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
|
|
||||||
|
|
||||||
NSString *jsonBuffer = [NSString stringWithFormat:@"{\"command\": \"%s\"}", command];
|
|
||||||
[jsonBuffer writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RegisterURL(const char* applicationId)
|
|
||||||
{
|
|
||||||
char url[256];
|
|
||||||
snprintf(url, sizeof(url), "discord-%s", applicationId);
|
|
||||||
CFStringRef cfURL = CFStringCreateWithCString(NULL, url, kCFStringEncodingUTF8);
|
|
||||||
|
|
||||||
NSString* myBundleId = [[NSBundle mainBundle] bundleIdentifier];
|
|
||||||
if (!myBundleId) {
|
|
||||||
fprintf(stderr, "No bundle id found\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSURL* myURL = [[NSBundle mainBundle] bundleURL];
|
|
||||||
if (!myURL) {
|
|
||||||
fprintf(stderr, "No bundle url found\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
OSStatus status = LSSetDefaultHandlerForURLScheme(cfURL, (__bridge CFStringRef)myBundleId);
|
|
||||||
if (status != noErr) {
|
|
||||||
fprintf(stderr, "Error in LSSetDefaultHandlerForURLScheme: %d\n", (int)status);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = LSRegisterURL((__bridge CFURLRef)myURL, true);
|
|
||||||
if (status != noErr) {
|
|
||||||
fprintf(stderr, "Error in LSRegisterURL: %d\n", (int)status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Discord_Register(const char* applicationId, const char* command)
|
|
||||||
{
|
|
||||||
if (command) {
|
|
||||||
RegisterCommand(applicationId, command);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// raii lite
|
|
||||||
@autoreleasepool {
|
|
||||||
RegisterURL(applicationId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Discord_RegisterSteamGame(const char* applicationId, const char* steamId)
|
|
||||||
{
|
|
||||||
char command[256];
|
|
||||||
snprintf(command, 256, "steam://rungameid/%s", steamId);
|
|
||||||
Discord_Register(applicationId, command);
|
|
||||||
}
|
|
||||||
40
3rdparty/discord-rpc/src/msg_queue.h
vendored
40
3rdparty/discord-rpc/src/msg_queue.h
vendored
@@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
// A simple queue. No locks, but only works with a single thread as producer and a single thread as
|
|
||||||
// a consumer. Mutex up as needed.
|
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
template <typename ElementType, std::size_t QueueSize>
|
|
||||||
class MsgQueue {
|
|
||||||
ElementType queue_[QueueSize];
|
|
||||||
std::atomic_uint nextAdd_{0};
|
|
||||||
std::atomic_uint nextSend_{0};
|
|
||||||
std::atomic_uint pendingSends_{0};
|
|
||||||
|
|
||||||
public:
|
|
||||||
MsgQueue() {}
|
|
||||||
|
|
||||||
ElementType* GetNextAddMessage()
|
|
||||||
{
|
|
||||||
// if we are falling behind, bail
|
|
||||||
if (pendingSends_.load() >= QueueSize) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto index = (nextAdd_++) % QueueSize;
|
|
||||||
return &queue_[index];
|
|
||||||
}
|
|
||||||
void CommitAdd() { ++pendingSends_; }
|
|
||||||
|
|
||||||
bool HavePendingSends() const { return pendingSends_.load() != 0; }
|
|
||||||
ElementType* GetNextSendMessage()
|
|
||||||
{
|
|
||||||
auto index = (nextSend_++) % QueueSize;
|
|
||||||
return &queue_[index];
|
|
||||||
}
|
|
||||||
void CommitSend() { --pendingSends_; }
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
64
3rdparty/discord-rpc/src/rpc_connection.h
vendored
64
3rdparty/discord-rpc/src/rpc_connection.h
vendored
@@ -1,64 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "connection.h"
|
|
||||||
#include "serialization.h"
|
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
// I took this from the buffer size libuv uses for named pipes; I suspect ours would usually be much
|
|
||||||
// smaller.
|
|
||||||
constexpr size_t MaxRpcFrameSize = 64 * 1024;
|
|
||||||
|
|
||||||
struct RpcConnection {
|
|
||||||
enum class ErrorCode : int {
|
|
||||||
Success = 0,
|
|
||||||
PipeClosed = 1,
|
|
||||||
ReadCorrupt = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Opcode : uint32_t {
|
|
||||||
Handshake = 0,
|
|
||||||
Frame = 1,
|
|
||||||
Close = 2,
|
|
||||||
Ping = 3,
|
|
||||||
Pong = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MessageFrameHeader {
|
|
||||||
Opcode opcode;
|
|
||||||
uint32_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MessageFrame : public MessageFrameHeader {
|
|
||||||
char message[MaxRpcFrameSize - sizeof(MessageFrameHeader)];
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class State : uint32_t {
|
|
||||||
Disconnected,
|
|
||||||
SentHandshake,
|
|
||||||
AwaitingResponse,
|
|
||||||
Connected,
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseConnection *connection { nullptr };
|
|
||||||
State state { State::Disconnected };
|
|
||||||
void (*onConnect)(JsonDocument &message) { nullptr };
|
|
||||||
void (*onDisconnect)(int errorCode, const char *message) { nullptr };
|
|
||||||
char appId[64] {};
|
|
||||||
int lastErrorCode { 0 };
|
|
||||||
char lastErrorMessage[256] {};
|
|
||||||
RpcConnection::MessageFrame sendFrame;
|
|
||||||
|
|
||||||
static RpcConnection *Create(const char *applicationId);
|
|
||||||
static void Destroy(RpcConnection *&);
|
|
||||||
|
|
||||||
inline bool IsOpen() const { return state == State::Connected; }
|
|
||||||
|
|
||||||
void Open();
|
|
||||||
void Close();
|
|
||||||
bool Write(const void *data, size_t length);
|
|
||||||
bool Read(JsonDocument &message);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
|
|
||||||
@@ -682,7 +682,6 @@ set(SOURCES
|
|||||||
src/lyrics/htmllyricsprovider.cpp
|
src/lyrics/htmllyricsprovider.cpp
|
||||||
src/lyrics/ovhlyricsprovider.cpp
|
src/lyrics/ovhlyricsprovider.cpp
|
||||||
src/lyrics/lololyricsprovider.cpp
|
src/lyrics/lololyricsprovider.cpp
|
||||||
src/lyrics/geniuslyricsprovider.cpp
|
|
||||||
src/lyrics/musixmatchlyricsprovider.cpp
|
src/lyrics/musixmatchlyricsprovider.cpp
|
||||||
src/lyrics/chartlyricsprovider.cpp
|
src/lyrics/chartlyricsprovider.cpp
|
||||||
src/lyrics/songlyricscomlyricsprovider.cpp
|
src/lyrics/songlyricscomlyricsprovider.cpp
|
||||||
@@ -980,7 +979,6 @@ set(HEADERS
|
|||||||
src/lyrics/htmllyricsprovider.h
|
src/lyrics/htmllyricsprovider.h
|
||||||
src/lyrics/ovhlyricsprovider.h
|
src/lyrics/ovhlyricsprovider.h
|
||||||
src/lyrics/lololyricsprovider.h
|
src/lyrics/lololyricsprovider.h
|
||||||
src/lyrics/geniuslyricsprovider.h
|
|
||||||
src/lyrics/musixmatchlyricsprovider.h
|
src/lyrics/musixmatchlyricsprovider.h
|
||||||
src/lyrics/chartlyricsprovider.h
|
src/lyrics/chartlyricsprovider.h
|
||||||
src/lyrics/songlyricscomlyricsprovider.h
|
src/lyrics/songlyricscomlyricsprovider.h
|
||||||
@@ -1494,7 +1492,7 @@ endif()
|
|||||||
|
|
||||||
if(HAVE_DISCORD_RPC)
|
if(HAVE_DISCORD_RPC)
|
||||||
add_subdirectory(3rdparty/discord-rpc)
|
add_subdirectory(3rdparty/discord-rpc)
|
||||||
target_include_directories(strawberry_lib PUBLIC 3rdparty/discord-rpc/include)
|
target_include_directories(strawberry_lib PUBLIC 3rdparty/discord-rpc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(HAVE_TRANSLATIONS)
|
if(HAVE_TRANSLATIONS)
|
||||||
|
|||||||
22
Changelog
22
Changelog
@@ -2,6 +2,28 @@ Strawberry Music Player
|
|||||||
=======================
|
=======================
|
||||||
ChangeLog
|
ChangeLog
|
||||||
|
|
||||||
|
Version 1.2.10 (2025.04.18):
|
||||||
|
|
||||||
|
Bugfixes:
|
||||||
|
* Fixed Discord rich presence showing bogus artist and album.
|
||||||
|
* Fixed incorrect ID3v2 comment tag.
|
||||||
|
* (macOS|Windows MSVC) Fixed stuck playback of some streams.
|
||||||
|
|
||||||
|
Enhancements:
|
||||||
|
* Removed Genius lyrics (longer working properly because of website changes).
|
||||||
|
* (macOS|Windows MSVC) Added back Spotify
|
||||||
|
|
||||||
|
Version 1.2.9 (2025.04.08):
|
||||||
|
|
||||||
|
Bugfixes:
|
||||||
|
* Fixed subsonic parse error (#1719).
|
||||||
|
* Fixed Deezer cover provider parse error (#1716).
|
||||||
|
* Fixed last.fm import progress.
|
||||||
|
* (Windows|MinGW) Switched from winpthreads to win32 threads, winpthreads are no longer working with Qt as of version 6.9 (QTBUG-131892).
|
||||||
|
|
||||||
|
Enhancements:
|
||||||
|
* Added option to disable playbin3.
|
||||||
|
|
||||||
Version 1.2.8 (2025.04.05):
|
Version 1.2.8 (2025.04.05):
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ Funding developers is a way to contribute to open source projects you appreciate
|
|||||||
* Edit tags on audio files
|
* Edit tags on audio files
|
||||||
* Fetch tags from MusicBrainz
|
* Fetch tags from MusicBrainz
|
||||||
* Album cover art from [Last.fm](https://www.last.fm/), [Musicbrainz](https://musicbrainz.org/), [Discogs](https://www.discogs.com/), [Musixmatch](https://www.musixmatch.com/), [Deezer](https://www.deezer.com/), [Tidal](https://www.tidal.com/), [Qobuz](https://www.qobuz.com/) and [Spotify](https://www.spotify.com/)
|
* Album cover art from [Last.fm](https://www.last.fm/), [Musicbrainz](https://musicbrainz.org/), [Discogs](https://www.discogs.com/), [Musixmatch](https://www.musixmatch.com/), [Deezer](https://www.deezer.com/), [Tidal](https://www.tidal.com/), [Qobuz](https://www.qobuz.com/) and [Spotify](https://www.spotify.com/)
|
||||||
* Song lyrics from [Genius](https://genius.com/), [Musixmatch](https://www.musixmatch.com/), [ChartLyrics](http://www.chartlyrics.com/), [lyrics.ovh](https://lyrics.ovh/), [lololyrics.com](https://www.lololyrics.com/), [songlyrics.com](https://www.songlyrics.com/), [azlyrics.com](https://www.azlyrics.com/) and [elyrics.net](https://www.elyrics.net/)
|
* Song lyrics from [Musixmatch](https://www.musixmatch.com/), [ChartLyrics](http://www.chartlyrics.com/), [lyrics.ovh](https://lyrics.ovh/), [lololyrics.com](https://www.lololyrics.com/), [songlyrics.com](https://www.songlyrics.com/), [azlyrics.com](https://www.azlyrics.com/) and [elyrics.net](https://www.elyrics.net/)
|
||||||
* Support for multiple backends
|
* Support for multiple backends
|
||||||
* Audio analyzer
|
* Audio analyzer
|
||||||
* Audio equalizer
|
* Audio equalizer
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
set(STRAWBERRY_VERSION_MAJOR 1)
|
set(STRAWBERRY_VERSION_MAJOR 1)
|
||||||
set(STRAWBERRY_VERSION_MINOR 2)
|
set(STRAWBERRY_VERSION_MINOR 2)
|
||||||
set(STRAWBERRY_VERSION_PATCH 8)
|
set(STRAWBERRY_VERSION_PATCH 10)
|
||||||
#set(STRAWBERRY_VERSION_PRERELEASE rc1)
|
#set(STRAWBERRY_VERSION_PRERELEASE rc1)
|
||||||
|
|
||||||
set(INCLUDE_GIT_REVISION OFF)
|
set(INCLUDE_GIT_REVISION OFF)
|
||||||
|
|||||||
2
debian/control
vendored
2
debian/control
vendored
@@ -60,7 +60,7 @@ Description: music player and music collection organizer
|
|||||||
- Edit tags on audio files
|
- Edit tags on audio files
|
||||||
- Automatically retrieve tags from MusicBrainz
|
- Automatically retrieve tags from MusicBrainz
|
||||||
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
||||||
- Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net
|
- Song lyrics from Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net
|
||||||
- Audio analyzer
|
- Audio analyzer
|
||||||
- Audio equalizer
|
- Audio equalizer
|
||||||
- Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic
|
- Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<li>Edit tags on audio files</li>
|
<li>Edit tags on audio files</li>
|
||||||
<li>Automatically retrieve tags from MusicBrainz</li>
|
<li>Automatically retrieve tags from MusicBrainz</li>
|
||||||
<li>Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify</li>
|
<li>Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify</li>
|
||||||
<li>Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net</li>
|
<li>Song lyrics from Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net</li>
|
||||||
<li>Audio analyzer and equalizer</li>
|
<li>Audio analyzer and equalizer</li>
|
||||||
<li>Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic</li>
|
<li>Transfer music to mass-storage USB players, MTP compatible devices and iPod Nano/Classic</li>
|
||||||
<li>Scrobbler with support for Last.fm, Libre.fm and ListenBrainz</li>
|
<li>Scrobbler with support for Last.fm, Libre.fm and ListenBrainz</li>
|
||||||
@@ -51,6 +51,8 @@
|
|||||||
</screenshots>
|
</screenshots>
|
||||||
<update_contact>eclipseo@fedoraproject.org</update_contact>
|
<update_contact>eclipseo@fedoraproject.org</update_contact>
|
||||||
<releases>
|
<releases>
|
||||||
|
<release version="1.2.10" date="2025-04-18"/>
|
||||||
|
<release version="1.2.9" date="2025-04-08"/>
|
||||||
<release version="1.2.8" date="2025-04-05"/>
|
<release version="1.2.8" date="2025-04-05"/>
|
||||||
<release version="1.2.7" date="2025-01-31"/>
|
<release version="1.2.7" date="2025-01-31"/>
|
||||||
<release version="1.2.6" date="2025-01-17"/>
|
<release version="1.2.6" date="2025-01-17"/>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ TryExec=strawberry
|
|||||||
Icon=strawberry
|
Icon=strawberry
|
||||||
Terminal=false
|
Terminal=false
|
||||||
Categories=AudioVideo;Player;Qt;Audio;
|
Categories=AudioVideo;Player;Qt;Audio;
|
||||||
Keywords=Audio;Player;
|
Keywords=Audio;Player;Clementine;
|
||||||
StartupNotify=false
|
StartupNotify=false
|
||||||
MimeType=x-content/audio-player;application/ogg;application/x-ogg;application/x-ogm-audio;audio/flac;audio/ogg;audio/vorbis;audio/aac;audio/mp4;audio/mpeg;audio/mpegurl;audio/vnd.rn-realaudio;audio/x-flac;audio/x-oggflac;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-speex;audio/x-wav;audio/x-wavpack;audio/x-ape;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-wma;audio/x-musepack;audio/x-pn-realaudio;audio/x-scpls;video/x-ms-asf;x-scheme-handler/tidal;
|
MimeType=x-content/audio-player;application/ogg;application/x-ogg;application/x-ogm-audio;audio/flac;audio/ogg;audio/vorbis;audio/aac;audio/mp4;audio/mpeg;audio/mpegurl;audio/vnd.rn-realaudio;audio/x-flac;audio/x-oggflac;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-speex;audio/x-wav;audio/x-wavpack;audio/x-ape;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-wma;audio/x-musepack;audio/x-pn-realaudio;audio/x-scpls;video/x-ms-asf;x-scheme-handler/tidal;
|
||||||
StartupWMClass=strawberry
|
StartupWMClass=strawberry
|
||||||
|
|||||||
2
dist/unix/strawberry.1
vendored
2
dist/unix/strawberry.1
vendored
@@ -29,7 +29,7 @@ Features:
|
|||||||
.br
|
.br
|
||||||
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
||||||
.br
|
.br
|
||||||
- Song lyrics from Lyrics.com, Genius, Musixmatch, ChartLyrics, lyrics.ovh and lololyrics.com
|
- Song lyrics from Musixmatch, ChartLyrics, lyrics.ovh and lololyrics.com
|
||||||
.br
|
.br
|
||||||
- Support for multiple backends
|
- Support for multiple backends
|
||||||
.br
|
.br
|
||||||
|
|||||||
2
dist/unix/strawberry.spec.in
vendored
2
dist/unix/strawberry.spec.in
vendored
@@ -93,7 +93,7 @@ Features:
|
|||||||
- Edit tags on audio files
|
- Edit tags on audio files
|
||||||
- Automatically retrieve tags from MusicBrainz
|
- Automatically retrieve tags from MusicBrainz
|
||||||
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
- Album cover art from Last.fm, Musicbrainz, Discogs, Musixmatch, Deezer, Tidal, Qobuz and Spotify
|
||||||
- Song lyrics from Genius, Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net
|
- Song lyrics from Musixmatch, ChartLyrics, lyrics.ovh, lololyrics.com, songlyrics.com, azlyrics.com and elyrics.net
|
||||||
- Support for multiple backends
|
- Support for multiple backends
|
||||||
- Audio analyzer
|
- Audio analyzer
|
||||||
- Audio equalizer
|
- Audio equalizer
|
||||||
|
|||||||
4
dist/windows/strawberry.nsi.in
vendored
4
dist/windows/strawberry.nsi.in
vendored
@@ -720,7 +720,7 @@ Section "Gstreamer plugins" gstreamer-plugins
|
|||||||
File "/oname=gstwavparse.dll" "gstreamer-plugins\gstwavparse.dll"
|
File "/oname=gstwavparse.dll" "gstreamer-plugins\gstwavparse.dll"
|
||||||
File "/oname=gstxingmux.dll" "gstreamer-plugins\gstxingmux.dll"
|
File "/oname=gstxingmux.dll" "gstreamer-plugins\gstxingmux.dll"
|
||||||
!ifdef arch_x64
|
!ifdef arch_x64
|
||||||
;File "/oname=gstspotify.dll" "gstreamer-plugins\gstspotify.dll"
|
File "/oname=gstspotify.dll" "gstreamer-plugins\gstspotify.dll"
|
||||||
!endif
|
!endif
|
||||||
!endif ; MSVC
|
!endif ; MSVC
|
||||||
|
|
||||||
@@ -1179,7 +1179,7 @@ Section "Uninstall"
|
|||||||
Delete "$INSTDIR\gstreamer-plugins\gstwavparse.dll"
|
Delete "$INSTDIR\gstreamer-plugins\gstwavparse.dll"
|
||||||
Delete "$INSTDIR\gstreamer-plugins\gstxingmux.dll"
|
Delete "$INSTDIR\gstreamer-plugins\gstxingmux.dll"
|
||||||
!ifdef arch_x64
|
!ifdef arch_x64
|
||||||
;Delete "$INSTDIR\gstreamer-plugins\gstspotify.dll"
|
Delete "$INSTDIR\gstreamer-plugins\gstspotify.dll"
|
||||||
!endif
|
!endif
|
||||||
!endif ; msvc
|
!endif ; msvc
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ constexpr char kOutputU[] = "Output";
|
|||||||
constexpr char kDevice[] = "device";
|
constexpr char kDevice[] = "device";
|
||||||
constexpr char kDeviceU[] = "Device";
|
constexpr char kDeviceU[] = "Device";
|
||||||
constexpr char kALSAPlugin[] = "alsaplugin";
|
constexpr char kALSAPlugin[] = "alsaplugin";
|
||||||
|
constexpr char kPlaybin3[] = "playbin3";
|
||||||
constexpr char kExclusiveMode[] = "exclusive_mode";
|
constexpr char kExclusiveMode[] = "exclusive_mode";
|
||||||
constexpr char kVolumeControl[] = "volume_control";
|
constexpr char kVolumeControl[] = "volume_control";
|
||||||
constexpr char kChannelsEnabled[] = "channels_enabled";
|
constexpr char kChannelsEnabled[] = "channels_enabled";
|
||||||
|
|||||||
@@ -64,7 +64,6 @@
|
|||||||
#include "covermanager/opentidalcoverprovider.h"
|
#include "covermanager/opentidalcoverprovider.h"
|
||||||
|
|
||||||
#include "lyrics/lyricsproviders.h"
|
#include "lyrics/lyricsproviders.h"
|
||||||
#include "lyrics/geniuslyricsprovider.h"
|
|
||||||
#include "lyrics/ovhlyricsprovider.h"
|
#include "lyrics/ovhlyricsprovider.h"
|
||||||
#include "lyrics/lololyricsprovider.h"
|
#include "lyrics/lololyricsprovider.h"
|
||||||
#include "lyrics/musixmatchlyricsprovider.h"
|
#include "lyrics/musixmatchlyricsprovider.h"
|
||||||
@@ -173,7 +172,6 @@ class ApplicationImpl {
|
|||||||
lyrics_providers_([app]() {
|
lyrics_providers_([app]() {
|
||||||
LyricsProviders *lyrics_providers = new LyricsProviders(app);
|
LyricsProviders *lyrics_providers = new LyricsProviders(app);
|
||||||
// Initialize the repository of lyrics providers.
|
// Initialize the repository of lyrics providers.
|
||||||
lyrics_providers->AddProvider(new GeniusLyricsProvider(lyrics_providers->network()));
|
|
||||||
lyrics_providers->AddProvider(new OVHLyricsProvider(lyrics_providers->network()));
|
lyrics_providers->AddProvider(new OVHLyricsProvider(lyrics_providers->network()));
|
||||||
lyrics_providers->AddProvider(new LoloLyricsProvider(lyrics_providers->network()));
|
lyrics_providers->AddProvider(new LoloLyricsProvider(lyrics_providers->network()));
|
||||||
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(lyrics_providers->network()));
|
lyrics_providers->AddProvider(new MusixmatchLyricsProvider(lyrics_providers->network()));
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ void AlbumCoverFetcherSearch::Start(SharedPtr<CoverProviders> cover_providers) {
|
|||||||
|
|
||||||
for (CoverProvider *provider : std::as_const(cover_providers_sorted)) {
|
for (CoverProvider *provider : std::as_const(cover_providers_sorted)) {
|
||||||
|
|
||||||
if (!provider->is_enabled()) continue;
|
if (!provider->enabled()) continue;
|
||||||
|
|
||||||
// Skip any provider that requires authentication but is not authenticated.
|
// Skip any provider that requires authentication but is not authenticated.
|
||||||
if (provider->authentication_required() && !provider->authenticated()) {
|
if (provider->authentication_required() && !provider->authenticated()) {
|
||||||
@@ -249,6 +249,8 @@ void AlbumCoverFetcherSearch::ProviderSearchFinished(const int id, const CoverPr
|
|||||||
|
|
||||||
void AlbumCoverFetcherSearch::AllProvidersFinished() {
|
void AlbumCoverFetcherSearch::AllProvidersFinished() {
|
||||||
|
|
||||||
|
qLog(Debug) << "Search finished, got" << results_.count() << "results";
|
||||||
|
|
||||||
if (cancel_requested_) {
|
if (cancel_requested_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class CoverProvider : public JsonBaseRequest {
|
|||||||
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent);
|
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, const SharedPtr<NetworkAccessManager> network, QObject *parent);
|
||||||
|
|
||||||
QString name() const { return name_; }
|
QString name() const { return name_; }
|
||||||
bool is_enabled() const { return enabled_; }
|
bool enabled() const { return enabled_; }
|
||||||
int order() const { return order_; }
|
int order() const { return order_; }
|
||||||
float quality() const { return quality_; }
|
float quality() const { return quality_; }
|
||||||
bool batch() const { return batch_; }
|
bool batch() const { return batch_; }
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ void CoverProviders::ReloadSettings() {
|
|||||||
QMap<int, QString> all_providers;
|
QMap<int, QString> all_providers;
|
||||||
QList<CoverProvider*> old_providers = cover_providers_.keys();
|
QList<CoverProvider*> old_providers = cover_providers_.keys();
|
||||||
for (CoverProvider *provider : std::as_const(old_providers)) {
|
for (CoverProvider *provider : std::as_const(old_providers)) {
|
||||||
if (!provider->is_enabled()) continue;
|
if (!provider->enabled()) continue;
|
||||||
all_providers.insert(provider->order(), provider->name());
|
all_providers.insert(provider->order(), provider->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,16 +158,16 @@ void DeezerCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QJsonObject &json_object = json_object_result.json_object;
|
const QJsonObject &json_object = json_object_result.json_object;
|
||||||
if (!json_object.isEmpty()) {
|
if (json_object.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray array_data;
|
QJsonArray array_data;
|
||||||
if (json_object.contains("data"_L1) && json_object["DATA"_L1].isArray()) {
|
if (json_object.contains("data"_L1) && json_object["data"_L1].isArray()) {
|
||||||
array_data = json_object["data"_L1].toArray();
|
array_data = json_object["data"_L1].toArray();
|
||||||
}
|
}
|
||||||
else if (json_object.contains("DATA"_L1) && json_object["DATA"_L1].isArray()) {
|
else if (json_object.contains("DATA"_L1) && json_object["DATA"_L1].isArray()) {
|
||||||
array_data = json_object["data"_L1].toArray();
|
array_data = json_object["DATA"_L1].toArray();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Error(u"Json reply object is missing data."_s, json_object);
|
Error(u"Json reply object is missing data."_s, json_object);
|
||||||
@@ -180,23 +180,23 @@ void DeezerCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
|||||||
|
|
||||||
QMap<QUrl, CoverProviderSearchResult> cover_results;
|
QMap<QUrl, CoverProviderSearchResult> cover_results;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const QJsonValue &json_value : std::as_const(array_data)) {
|
for (const QJsonValue &value_entry : std::as_const(array_data)) {
|
||||||
|
|
||||||
if (!json_value.isObject()) {
|
if (!value_entry.isObject()) {
|
||||||
Error(u"Invalid Json reply, data array value is not a object."_s);
|
Error(u"Invalid Json reply, data array value is not a object."_s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const QJsonObject value_object = json_value.toObject();
|
const QJsonObject object_entry = value_entry.toObject();
|
||||||
QJsonObject object_album;
|
QJsonObject object_album;
|
||||||
if (value_object.contains("album"_L1) && value_object["album"_L1].isObject()) { // Song search, so extract the album.
|
if (object_entry.contains("album"_L1) && object_entry["album"_L1].isObject()) { // Song search, so extract the album.
|
||||||
object_album = value_object["album"_L1].toObject();
|
object_album = object_entry["album"_L1].toObject();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
object_album = value_object;
|
object_album = object_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!value_object.contains("id"_L1) || !object_album.contains("id"_L1)) {
|
if (!object_entry.contains("id"_L1) || !object_album.contains("id"_L1)) {
|
||||||
Error(u"Invalid Json reply, data array value object is missing ID."_s, value_object);
|
Error(u"Invalid Json reply, data array value object is missing ID."_s, object_entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,11 +210,11 @@ void DeezerCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_object.contains("artist"_L1)) {
|
if (!object_entry.contains("artist"_L1)) {
|
||||||
Error(u"Invalid Json reply, data array value object is missing artist."_s, json_object);
|
Error(u"Invalid Json reply, data array value object is missing artist."_s, object_entry);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const QJsonValue value_artist = json_object["artist"_L1];
|
const QJsonValue value_artist = object_entry["artist"_L1];
|
||||||
if (!value_artist.isObject()) {
|
if (!value_artist.isObject()) {
|
||||||
Error(u"Invalid Json reply, data array value artist is not a object."_s, value_artist);
|
Error(u"Invalid Json reply, data array value artist is not a object."_s, value_artist);
|
||||||
continue;
|
continue;
|
||||||
@@ -242,12 +242,12 @@ void DeezerCoverProvider::HandleSearchReply(QNetworkReply *reply, const int id)
|
|||||||
<< qMakePair(u"cover_big"_s, QSize(500, 500));
|
<< qMakePair(u"cover_big"_s, QSize(500, 500));
|
||||||
for (const QPair<QString, QSize> &cover_size : cover_sizes) {
|
for (const QPair<QString, QSize> &cover_size : cover_sizes) {
|
||||||
if (!object_album.contains(cover_size.first)) continue;
|
if (!object_album.contains(cover_size.first)) continue;
|
||||||
QString cover = object_album[cover_size.first].toString();
|
const QString cover = object_album[cover_size.first].toString();
|
||||||
if (!have_cover) {
|
if (!have_cover) {
|
||||||
have_cover = true;
|
have_cover = true;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
QUrl url(cover);
|
const QUrl url(cover);
|
||||||
if (!cover_results.contains(url)) {
|
if (!cover_results.contains(url)) {
|
||||||
cover_result.image_url = url;
|
cover_result.image_url = url;
|
||||||
cover_result.image_size = cover_size.second;
|
cover_result.image_size = cover_size.second;
|
||||||
|
|||||||
@@ -36,11 +36,8 @@ namespace {
|
|||||||
constexpr char kDiscordApplicationId[] = "1352351827206733974";
|
constexpr char kDiscordApplicationId[] = "1352351827206733974";
|
||||||
constexpr char kStrawberryIconResourceName[] = "embedded_cover";
|
constexpr char kStrawberryIconResourceName[] = "embedded_cover";
|
||||||
constexpr char kStrawberryIconDescription[] = "Strawberry Music Player";
|
constexpr char kStrawberryIconDescription[] = "Strawberry Music Player";
|
||||||
constexpr qint64 kDiscordPresenceUpdateRateLimitMs = 2000;
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
using namespace discord_rpc;
|
|
||||||
|
|
||||||
namespace discord {
|
namespace discord {
|
||||||
|
|
||||||
RichPresence::RichPresence(const SharedPtr<Player> player,
|
RichPresence::RichPresence(const SharedPtr<Player> player,
|
||||||
@@ -49,11 +46,7 @@ RichPresence::RichPresence(const SharedPtr<Player> player,
|
|||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
player_(player),
|
player_(player),
|
||||||
playlist_manager_(playlist_manager),
|
playlist_manager_(playlist_manager),
|
||||||
activity_({ {}, {}, {}, 0, 0, 0 }),
|
initialized_(false) {
|
||||||
send_presence_timestamp_(0),
|
|
||||||
enabled_(false) {
|
|
||||||
|
|
||||||
Discord_Initialize(kDiscordApplicationId, nullptr, 1, nullptr);
|
|
||||||
|
|
||||||
QObject::connect(&*player_->engine(), &EngineBase::StateChanged, this, &RichPresence::EngineStateChanged);
|
QObject::connect(&*player_->engine(), &EngineBase::StateChanged, this, &RichPresence::EngineStateChanged);
|
||||||
QObject::connect(&*playlist_manager_, &PlaylistManager::CurrentSongChanged, this, &RichPresence::CurrentSongChanged);
|
QObject::connect(&*playlist_manager_, &PlaylistManager::CurrentSongChanged, this, &RichPresence::CurrentSongChanged);
|
||||||
@@ -64,7 +57,11 @@ RichPresence::RichPresence(const SharedPtr<Player> player,
|
|||||||
}
|
}
|
||||||
|
|
||||||
RichPresence::~RichPresence() {
|
RichPresence::~RichPresence() {
|
||||||
Discord_Shutdown();
|
|
||||||
|
if (initialized_) {
|
||||||
|
Discord_Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichPresence::ReloadSettings() {
|
void RichPresence::ReloadSettings() {
|
||||||
@@ -74,16 +71,22 @@ void RichPresence::ReloadSettings() {
|
|||||||
const bool enabled = s.value(DiscordRPCSettings::kEnabled, false).toBool();
|
const bool enabled = s.value(DiscordRPCSettings::kEnabled, false).toBool();
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
if (enabled_ && !enabled) {
|
if (enabled && !initialized_) {
|
||||||
Discord_ClearPresence();
|
Discord_Initialize(kDiscordApplicationId, nullptr, 1);
|
||||||
|
initialized_ = true;
|
||||||
|
}
|
||||||
|
else if (!enabled && initialized_) {
|
||||||
|
Discord_ClearPresence();
|
||||||
|
Discord_Shutdown();
|
||||||
|
initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled_ = enabled;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichPresence::EngineStateChanged(const EngineBase::State state) {
|
void RichPresence::EngineStateChanged(const EngineBase::State state) {
|
||||||
|
|
||||||
|
if (!initialized_) return;
|
||||||
|
|
||||||
if (state == EngineBase::State::Playing) {
|
if (state == EngineBase::State::Playing) {
|
||||||
SetTimestamp(player_->engine()->position_nanosec() / kNsecPerSec);
|
SetTimestamp(player_->engine()->position_nanosec() / kNsecPerSec);
|
||||||
SendPresenceUpdate();
|
SendPresenceUpdate();
|
||||||
@@ -96,6 +99,8 @@ void RichPresence::EngineStateChanged(const EngineBase::State state) {
|
|||||||
|
|
||||||
void RichPresence::CurrentSongChanged(const Song &song) {
|
void RichPresence::CurrentSongChanged(const Song &song) {
|
||||||
|
|
||||||
|
if (!initialized_) return;
|
||||||
|
|
||||||
SetTimestamp(0LL);
|
SetTimestamp(0LL);
|
||||||
activity_.length_secs = song.length_nanosec() / kNsecPerSec;
|
activity_.length_secs = song.length_nanosec() / kNsecPerSec;
|
||||||
activity_.title = song.title();
|
activity_.title = song.title();
|
||||||
@@ -108,17 +113,7 @@ void RichPresence::CurrentSongChanged(const Song &song) {
|
|||||||
|
|
||||||
void RichPresence::SendPresenceUpdate() {
|
void RichPresence::SendPresenceUpdate() {
|
||||||
|
|
||||||
if (!enabled_) {
|
if (!initialized_) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const qint64 current_timestamp = QDateTime::currentMSecsSinceEpoch();
|
|
||||||
if (current_timestamp - send_presence_timestamp_ < kDiscordPresenceUpdateRateLimitMs) {
|
|
||||||
qLog(Info) << "Not sending rich presence due to rate limit of" << kDiscordPresenceUpdateRateLimitMs << "ms";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
send_presence_timestamp_ = current_timestamp;
|
|
||||||
|
|
||||||
::DiscordRichPresence presence_data{};
|
::DiscordRichPresence presence_data{};
|
||||||
memset(&presence_data, 0, sizeof(presence_data));
|
memset(&presence_data, 0, sizeof(presence_data));
|
||||||
@@ -128,14 +123,16 @@ void RichPresence::SendPresenceUpdate() {
|
|||||||
presence_data.smallImageText = kStrawberryIconDescription;
|
presence_data.smallImageText = kStrawberryIconDescription;
|
||||||
presence_data.instance = 0;
|
presence_data.instance = 0;
|
||||||
|
|
||||||
|
QByteArray artist;
|
||||||
if (!activity_.artist.isEmpty()) {
|
if (!activity_.artist.isEmpty()) {
|
||||||
QByteArray artist = activity_.artist.toUtf8();
|
artist = activity_.artist.toUtf8();
|
||||||
artist.prepend(tr("by ").toUtf8());
|
artist.prepend(tr("by ").toUtf8());
|
||||||
presence_data.state = artist.constData();
|
presence_data.state = artist.constData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activity_.album.isEmpty() && activity_.album != activity_.title) {
|
QByteArray album;
|
||||||
QByteArray album = activity_.album.toUtf8();
|
if (!activity_.album.isEmpty()) {
|
||||||
|
album = activity_.album.toUtf8();
|
||||||
album.prepend(tr("on ").toUtf8());
|
album.prepend(tr("on ").toUtf8());
|
||||||
presence_data.largeImageText = album.constData();
|
presence_data.largeImageText = album.constData();
|
||||||
}
|
}
|
||||||
@@ -152,13 +149,19 @@ void RichPresence::SendPresenceUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RichPresence::SetTimestamp(const qint64 seconds) {
|
void RichPresence::SetTimestamp(const qint64 seconds) {
|
||||||
|
|
||||||
activity_.start_timestamp = QDateTime::currentSecsSinceEpoch();
|
activity_.start_timestamp = QDateTime::currentSecsSinceEpoch();
|
||||||
activity_.seek_secs = seconds;
|
activity_.seek_secs = seconds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichPresence::Seeked(const qint64 seek_microseconds) {
|
void RichPresence::Seeked(const qint64 seek_microseconds) {
|
||||||
|
|
||||||
|
if (!initialized_) return;
|
||||||
|
|
||||||
SetTimestamp(seek_microseconds / 1000LL);
|
SetTimestamp(seek_microseconds / 1000LL);
|
||||||
SendPresenceUpdate();
|
SendPresenceUpdate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord
|
} // namespace discord
|
||||||
|
|||||||
@@ -58,16 +58,18 @@ class RichPresence : public QObject {
|
|||||||
const SharedPtr<Player> player_;
|
const SharedPtr<Player> player_;
|
||||||
const SharedPtr<PlaylistManager> playlist_manager_;
|
const SharedPtr<PlaylistManager> playlist_manager_;
|
||||||
|
|
||||||
struct {
|
class Activity {
|
||||||
|
public:
|
||||||
|
explicit Activity() : start_timestamp(0), length_secs(0), seek_secs(0) {}
|
||||||
QString title;
|
QString title;
|
||||||
QString artist;
|
QString artist;
|
||||||
QString album;
|
QString album;
|
||||||
qint64 start_timestamp;
|
qint64 start_timestamp;
|
||||||
qint64 length_secs;
|
qint64 length_secs;
|
||||||
qint64 seek_secs;
|
qint64 seek_secs;
|
||||||
} activity_;
|
};
|
||||||
qint64 send_presence_timestamp_;
|
Activity activity_;
|
||||||
bool enabled_;
|
bool initialized_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace discord
|
} // namespace discord
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ using namespace Qt::Literals::StringLiterals;
|
|||||||
|
|
||||||
EngineBase::EngineBase(QObject *parent)
|
EngineBase::EngineBase(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
|
playbin3_enabled_(true),
|
||||||
exclusive_mode_(false),
|
exclusive_mode_(false),
|
||||||
volume_control_(true),
|
volume_control_(true),
|
||||||
volume_(100),
|
volume_(100),
|
||||||
@@ -156,6 +157,8 @@ void EngineBase::ReloadSettings() {
|
|||||||
device_ = s.value(BackendSettings::kDevice);
|
device_ = s.value(BackendSettings::kDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playbin3_enabled_ = s.value(BackendSettings::kPlaybin3, true).toBool();
|
||||||
|
|
||||||
exclusive_mode_ = s.value(BackendSettings::kExclusiveMode, false).toBool();
|
exclusive_mode_ = s.value(BackendSettings::kExclusiveMode, false).toBool();
|
||||||
|
|
||||||
volume_control_ = s.value(BackendSettings::kVolumeControl, true).toBool();
|
volume_control_ = s.value(BackendSettings::kVolumeControl, true).toBool();
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ class EngineBase : public QObject {
|
|||||||
void Finished();
|
void Finished();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool playbin3_enabled_;
|
||||||
bool exclusive_mode_;
|
bool exclusive_mode_;
|
||||||
bool volume_control_;
|
bool volume_control_;
|
||||||
uint volume_;
|
uint volume_;
|
||||||
|
|||||||
@@ -899,6 +899,7 @@ GstEnginePipelinePtr GstEngine::CreatePipeline() {
|
|||||||
|
|
||||||
GstEnginePipelinePtr pipeline = GstEnginePipelinePtr(new GstEnginePipeline);
|
GstEnginePipelinePtr pipeline = GstEnginePipelinePtr(new GstEnginePipeline);
|
||||||
pipeline->set_output_device(output_, device_);
|
pipeline->set_output_device(output_, device_);
|
||||||
|
pipeline->set_playbin3_enabled(playbin3_enabled_);
|
||||||
pipeline->set_exclusive_mode(exclusive_mode_);
|
pipeline->set_exclusive_mode(exclusive_mode_);
|
||||||
pipeline->set_volume_enabled(volume_control_);
|
pipeline->set_volume_enabled(volume_control_);
|
||||||
pipeline->set_stereo_balancer_enabled(stereo_balancer_enabled_);
|
pipeline->set_stereo_balancer_enabled(stereo_balancer_enabled_);
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
|
|||||||
id_(sId++),
|
id_(sId++),
|
||||||
playbin3_support_(false),
|
playbin3_support_(false),
|
||||||
volume_full_range_support_(false),
|
volume_full_range_support_(false),
|
||||||
|
playbin3_enabled_(true),
|
||||||
exclusive_mode_(false),
|
exclusive_mode_(false),
|
||||||
volume_enabled_(true),
|
volume_enabled_(true),
|
||||||
fading_enabled_(false),
|
fading_enabled_(false),
|
||||||
@@ -221,6 +222,10 @@ void GstEnginePipeline::set_output_device(const QString &output, const QVariant
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GstEnginePipeline::set_playbin3_enabled(const bool playbin3_enabled) {
|
||||||
|
playbin3_enabled_ = playbin3_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void GstEnginePipeline::set_exclusive_mode(const bool exclusive_mode) {
|
void GstEnginePipeline::set_exclusive_mode(const bool exclusive_mode) {
|
||||||
exclusive_mode_ = exclusive_mode;
|
exclusive_mode_ = exclusive_mode;
|
||||||
}
|
}
|
||||||
@@ -450,7 +455,9 @@ bool GstEnginePipeline::InitFromUrl(const QUrl &media_url, const QUrl &stream_ur
|
|||||||
end_offset_nanosec_ = end_offset_nanosec;
|
end_offset_nanosec_ = end_offset_nanosec;
|
||||||
ebur128_loudness_normalizing_gain_db_ = ebur128_loudness_normalizing_gain_db;
|
ebur128_loudness_normalizing_gain_db_ = ebur128_loudness_normalizing_gain_db;
|
||||||
|
|
||||||
pipeline_ = CreateElement(playbin3_support_ ? u"playbin3"_s : u"playbin"_s, u"pipeline"_s, nullptr, error);
|
const QString playbin_name = playbin3_support_ && playbin3_enabled_ ? u"playbin3"_s : u"playbin"_s;
|
||||||
|
qLog(Debug) << "Using" << playbin_name << "for pipeline";
|
||||||
|
pipeline_ = CreateElement(playbin_name, u"pipeline"_s, nullptr, error);
|
||||||
if (!pipeline_) return false;
|
if (!pipeline_) return false;
|
||||||
|
|
||||||
pad_added_cb_id_ = CHECKED_GCONNECT(G_OBJECT(pipeline_), "pad-added", &PadAddedCallback, this);
|
pad_added_cb_id_ = CHECKED_GCONNECT(G_OBJECT(pipeline_), "pad-added", &PadAddedCallback, this);
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class GstEnginePipeline : public QObject {
|
|||||||
|
|
||||||
// Call these setters before Init
|
// Call these setters before Init
|
||||||
void set_output_device(const QString &output, const QVariant &device);
|
void set_output_device(const QString &output, const QVariant &device);
|
||||||
|
void set_playbin3_enabled(const bool playbin3_enabled);
|
||||||
void set_exclusive_mode(const bool exclusive_mode);
|
void set_exclusive_mode(const bool exclusive_mode);
|
||||||
void set_volume_enabled(const bool enabled);
|
void set_volume_enabled(const bool enabled);
|
||||||
void set_stereo_balancer_enabled(const bool enabled);
|
void set_stereo_balancer_enabled(const bool enabled);
|
||||||
@@ -219,6 +220,8 @@ class GstEnginePipeline : public QObject {
|
|||||||
bool playbin3_support_;
|
bool playbin3_support_;
|
||||||
bool volume_full_range_support_;
|
bool volume_full_range_support_;
|
||||||
|
|
||||||
|
bool playbin3_enabled_;
|
||||||
|
|
||||||
// General settings for the pipeline
|
// General settings for the pipeline
|
||||||
QString output_;
|
QString output_;
|
||||||
QVariant device_;
|
QVariant device_;
|
||||||
|
|||||||
@@ -1,406 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* Copyright 2020-2025, Jonas Kvinge <jonas@jkvinge.net>
|
|
||||||
*
|
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QThread>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QString>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QUrlQuery>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QSettings>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonValue>
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
|
|
||||||
#include "includes/shared_ptr.h"
|
|
||||||
#include "core/logging.h"
|
|
||||||
#include "core/networkaccessmanager.h"
|
|
||||||
#include "core/oauthenticator.h"
|
|
||||||
#include "jsonlyricsprovider.h"
|
|
||||||
#include "htmllyricsprovider.h"
|
|
||||||
#include "geniuslyricsprovider.h"
|
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
|
||||||
using std::make_shared;
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
constexpr char kSettingsGroup[] = "GeniusLyrics";
|
|
||||||
constexpr char kOAuthAuthorizeUrl[] = "https://api.genius.com/oauth/authorize";
|
|
||||||
constexpr char kOAuthAccessTokenUrl[] = "https://api.genius.com/oauth/token";
|
|
||||||
constexpr char kOAuthRedirectUrl[] = "http://localhost:63111/"; // Genius does not accept a random port number. This port must match the URL of the ClientID.
|
|
||||||
constexpr char kOAuthScope[] = "me";
|
|
||||||
constexpr char kUrlSearch[] = "https://api.genius.com/search/";
|
|
||||||
constexpr char kClientIDB64[] = "RUNTNXU4U1VyMU1KUU5hdTZySEZteUxXY2hkanFiY3lfc2JjdXBpNG5WMU9SNUg4dTBZelEtZTZCdFg2dl91SQ==";
|
|
||||||
constexpr char kClientSecretB64[] = "VE9pMU9vUjNtTXZ3eFR3YVN0QVRyUjVoUlhVWDI1Ylp5X240eEt1M0ZkYlNwRG5JUnd0LXFFbHdGZkZkRWY2VzJ1S011UnQzM3c2Y3hqY0tVZ3NGN2c=";
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
GeniusLyricsProvider::GeniusLyricsProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent)
|
|
||||||
: JsonLyricsProvider(u"Genius"_s, true, true, network, parent),
|
|
||||||
oauth_(new OAuthenticator(network, this)) {
|
|
||||||
|
|
||||||
oauth_->set_settings_group(QLatin1String(kSettingsGroup));
|
|
||||||
oauth_->set_type(OAuthenticator::Type::Authorization_Code);
|
|
||||||
oauth_->set_authorize_url(QUrl(QLatin1String(kOAuthAuthorizeUrl)));
|
|
||||||
oauth_->set_redirect_url(QUrl(QLatin1String(kOAuthRedirectUrl)));
|
|
||||||
oauth_->set_access_token_url(QUrl(QLatin1String(kOAuthAccessTokenUrl)));
|
|
||||||
oauth_->set_client_id(QString::fromLatin1(QByteArray::fromBase64(kClientIDB64)));
|
|
||||||
oauth_->set_client_secret(QString::fromLatin1(QByteArray::fromBase64(kClientSecretB64)));
|
|
||||||
oauth_->set_scope(QLatin1String(kOAuthScope));
|
|
||||||
oauth_->set_use_local_redirect_server(true);
|
|
||||||
oauth_->set_random_port(false);
|
|
||||||
|
|
||||||
QObject::connect(oauth_, &OAuthenticator::AuthenticationFinished, this, &GeniusLyricsProvider::OAuthFinished);
|
|
||||||
|
|
||||||
oauth_->LoadSession();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GeniusLyricsProvider::authenticated() const {
|
|
||||||
|
|
||||||
return oauth_->authenticated();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GeniusLyricsProvider::use_authorization_header() const {
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::Authenticate() {
|
|
||||||
|
|
||||||
oauth_->Authenticate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::ClearSession() {
|
|
||||||
|
|
||||||
oauth_->ClearSession();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray GeniusLyricsProvider::authorization_header() const {
|
|
||||||
|
|
||||||
return oauth_->authorization_header();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::OAuthFinished(const bool success, const QString &error) {
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
qLog(Debug) << "Genius: Authentication was successful.";
|
|
||||||
Q_EMIT AuthenticationComplete(true);
|
|
||||||
Q_EMIT AuthenticationSuccess();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qLog(Debug) << "Genius: Authentication failed.";
|
|
||||||
Q_EMIT AuthenticationFailure(error);
|
|
||||||
Q_EMIT AuthenticationComplete(false, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::StartSearch(const int id, const LyricsSearchRequest &request) {
|
|
||||||
|
|
||||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
|
||||||
|
|
||||||
if (!authenticated()) {
|
|
||||||
EndSearch(id, request);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GeniusLyricsSearchContextPtr search = make_shared<GeniusLyricsSearchContext>();
|
|
||||||
search->id = id;
|
|
||||||
search->request = request;
|
|
||||||
requests_search_.insert(id, search);
|
|
||||||
|
|
||||||
QUrlQuery url_query;
|
|
||||||
url_query.addQueryItem(u"q"_s, QString::fromLatin1(QUrl::toPercentEncoding(QStringLiteral("%1 %2").arg(request.artist, request.title))));
|
|
||||||
|
|
||||||
QNetworkReply *reply = CreateGetRequest(QUrl(QLatin1String(kUrlSearch)), url_query);
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, this, [this, reply, id]() { HandleSearchReply(reply, id); });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
GeniusLyricsProvider::JsonObjectResult GeniusLyricsProvider::ParseJsonObject(QNetworkReply *reply) {
|
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError && reply->error() < 200) {
|
|
||||||
return JsonObjectResult(ErrorCode::NetworkError, QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObjectResult result(ErrorCode::Success);
|
|
||||||
result.network_error = reply->error();
|
|
||||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid()) {
|
|
||||||
result.http_status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QByteArray data = reply->readAll();
|
|
||||||
if (!data.isEmpty()) {
|
|
||||||
QJsonParseError json_parse_error;
|
|
||||||
const QJsonDocument json_document = QJsonDocument::fromJson(data, &json_parse_error);
|
|
||||||
if (json_parse_error.error == QJsonParseError::NoError) {
|
|
||||||
const QJsonObject json_object = json_document.object();
|
|
||||||
if (json_object.contains("errors"_L1) && json_object["errors"_L1].isArray()) {
|
|
||||||
const QJsonArray array_errors = json_object["errors"_L1].toArray();
|
|
||||||
for (const auto &value : array_errors) {
|
|
||||||
if (!value.isObject()) continue;
|
|
||||||
const QJsonObject object_error = value.toObject();
|
|
||||||
if (!object_error.contains("category"_L1) || !object_error.contains("code"_L1) || !object_error.contains("detail"_L1)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const QString category = object_error["category"_L1].toString();
|
|
||||||
const QString code = object_error["code"_L1].toString();
|
|
||||||
const QString detail = object_error["detail"_L1].toString();
|
|
||||||
result.error_code = ErrorCode::APIError;
|
|
||||||
result.error_message = QStringLiteral("%1 (%2) (%3)").arg(category, code, detail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result.json_object = json_document.object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result.error_code = ErrorCode::ParseError;
|
|
||||||
result.error_message = json_parse_error.errorString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.error_code != ErrorCode::APIError) {
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
|
||||||
result.error_code = ErrorCode::NetworkError;
|
|
||||||
result.error_message = QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
|
||||||
}
|
|
||||||
else if (result.http_status_code != 200) {
|
|
||||||
result.error_code = ErrorCode::HttpError;
|
|
||||||
result.error_message = QStringLiteral("Received HTTP code %1").arg(result.http_status_code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::AuthenticationRequiredError) {
|
|
||||||
oauth_->ClearSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::HandleSearchReply(QNetworkReply *reply, const int id) {
|
|
||||||
|
|
||||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
|
||||||
|
|
||||||
if (!replies_.contains(reply)) return;
|
|
||||||
replies_.removeAll(reply);
|
|
||||||
QObject::disconnect(reply, nullptr, this, nullptr);
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
if (!requests_search_.contains(id)) return;
|
|
||||||
GeniusLyricsSearchContextPtr search = requests_search_.value(id);
|
|
||||||
|
|
||||||
const QScopeGuard end_search = qScopeGuard([this, search]() { EndSearch(search); });
|
|
||||||
|
|
||||||
const JsonObjectResult json_object_result = ParseJsonObject(reply);
|
|
||||||
if (!json_object_result.success()) {
|
|
||||||
Error(json_object_result.error_message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonObject &json_object = json_object_result.json_object;
|
|
||||||
if (json_object.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_object.contains("meta"_L1)) {
|
|
||||||
Error(u"Json reply is missing meta object."_s, json_object);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!json_object["meta"_L1].isObject()) {
|
|
||||||
Error(u"Json reply meta is not an object."_s, json_object);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const QJsonObject object_meta = json_object["meta"_L1].toObject();
|
|
||||||
if (!object_meta.contains("status"_L1)) {
|
|
||||||
Error(u"Json reply meta object is missing status."_s, object_meta);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const int status = object_meta["status"_L1].toInt();
|
|
||||||
if (status != 200) {
|
|
||||||
if (object_meta.contains("message"_L1)) {
|
|
||||||
Error(QStringLiteral("Received error %1: %2.").arg(status).arg(object_meta["message"_L1].toString()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Error(QStringLiteral("Received error %1.").arg(status));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!json_object.contains("response"_L1)) {
|
|
||||||
Error(u"Json reply is missing response."_s, json_object);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!json_object["response"_L1].isObject()) {
|
|
||||||
Error(u"Json response is not an object."_s, json_object);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const QJsonObject obj_response = json_object["response"_L1].toObject();
|
|
||||||
if (!obj_response.contains("hits"_L1)) {
|
|
||||||
Error(u"Json response is missing hits."_s, obj_response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!obj_response["hits"_L1].isArray()) {
|
|
||||||
Error(u"Json hits is not an array."_s, obj_response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const QJsonArray array_hits = obj_response["hits"_L1].toArray();
|
|
||||||
|
|
||||||
for (const QJsonValue &value_hit : array_hits) {
|
|
||||||
if (!value_hit.isObject()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const QJsonObject object_hit = value_hit.toObject();
|
|
||||||
if (!object_hit.contains("result"_L1)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!object_hit["result"_L1].isObject()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const QJsonObject object_result = object_hit["result"_L1].toObject();
|
|
||||||
if (!object_result.contains("title"_L1) || !object_result.contains("primary_artist"_L1) || !object_result.contains("url"_L1) || !object_result["primary_artist"_L1].isObject()) {
|
|
||||||
Error(u"Missing one or more values in result object"_s, object_result);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const QJsonObject primary_artist = object_result["primary_artist"_L1].toObject();
|
|
||||||
if (!primary_artist.contains("name"_L1)) continue;
|
|
||||||
|
|
||||||
const QString artist = primary_artist["name"_L1].toString();
|
|
||||||
const QString title = object_result["title"_L1].toString();
|
|
||||||
|
|
||||||
// Ignore results where both the artist and title don't match.
|
|
||||||
if (!artist.startsWith(search->request.albumartist, Qt::CaseInsensitive) &&
|
|
||||||
!artist.startsWith(search->request.artist, Qt::CaseInsensitive) &&
|
|
||||||
!title.startsWith(search->request.title, Qt::CaseInsensitive)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QUrl url(object_result["url"_L1].toString());
|
|
||||||
if (!url.isValid()) continue;
|
|
||||||
if (search->requests_lyric_.contains(url)) continue;
|
|
||||||
|
|
||||||
GeniusLyricsLyricContext lyric;
|
|
||||||
lyric.artist = artist;
|
|
||||||
lyric.title = title;
|
|
||||||
lyric.url = url;
|
|
||||||
|
|
||||||
search->requests_lyric_.insert(url, lyric);
|
|
||||||
|
|
||||||
QNetworkReply *new_reply = CreateGetRequest(url);
|
|
||||||
QObject::connect(new_reply, &QNetworkReply::finished, this, [this, new_reply, search, url]() { HandleLyricReply(new_reply, search->id, url); });
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::HandleLyricReply(QNetworkReply *reply, const int search_id, const QUrl &url) {
|
|
||||||
|
|
||||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
|
||||||
|
|
||||||
if (!replies_.contains(reply)) return;
|
|
||||||
replies_.removeAll(reply);
|
|
||||||
QObject::disconnect(reply, nullptr, this, nullptr);
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
if (!requests_search_.contains(search_id)) return;
|
|
||||||
GeniusLyricsSearchContextPtr search = requests_search_.value(search_id);
|
|
||||||
|
|
||||||
if (!search->requests_lyric_.contains(url)) {
|
|
||||||
EndSearch(search);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const GeniusLyricsLyricContext lyric = search->requests_lyric_.value(url);
|
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
|
||||||
Error(QStringLiteral("%1 (%2)").arg(reply->errorString()).arg(reply->error()));
|
|
||||||
EndSearch(search, lyric);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
|
||||||
Error(QStringLiteral("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()));
|
|
||||||
EndSearch(search, lyric);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QByteArray data = reply->readAll();
|
|
||||||
if (data.isEmpty()) {
|
|
||||||
Error(u"Empty reply received from server."_s);
|
|
||||||
EndSearch(search, lyric);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString content = QString::fromUtf8(data);
|
|
||||||
QString lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(u"<div[^>]*>"_s), QRegularExpression(u"<\\/div>"_s), QRegularExpression(u"<div data-lyrics-container=[^>]+>"_s), true);
|
|
||||||
if (lyrics.isEmpty()) {
|
|
||||||
lyrics = HtmlLyricsProvider::ParseLyricsFromHTML(content, QRegularExpression(u"<div[^>]*>"_s), QRegularExpression(u"<\\/div>"_s), QRegularExpression(u"<div class=\"lyrics\">"_s), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lyrics.isEmpty()) {
|
|
||||||
LyricsSearchResult result(lyrics);
|
|
||||||
result.artist = lyric.artist;
|
|
||||||
result.title = lyric.title;
|
|
||||||
search->results.append(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
EndSearch(search, lyric);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::EndSearch(GeniusLyricsSearchContextPtr search, const GeniusLyricsLyricContext &lyric) {
|
|
||||||
|
|
||||||
if (search->requests_lyric_.contains(lyric.url)) {
|
|
||||||
search->requests_lyric_.remove(lyric.url);
|
|
||||||
}
|
|
||||||
if (search->requests_lyric_.count() == 0) {
|
|
||||||
requests_search_.remove(search->id);
|
|
||||||
EndSearch(search->id, search->request, search->results);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void GeniusLyricsProvider::EndSearch(const int id, const LyricsSearchRequest &request, const LyricsSearchResults &results) {
|
|
||||||
|
|
||||||
if (results.isEmpty()) {
|
|
||||||
qLog(Debug) << "GeniusLyrics: No lyrics for" << request.artist << request.title;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qLog(Debug) << "GeniusLyrics: Got lyrics for" << request.artist << request.title;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT SearchFinished(id, results);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* Copyright 2020-2025, Jonas Kvinge <jonas@jkvinge.net>
|
|
||||||
*
|
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GENIUSLYRICSPROVIDER_H
|
|
||||||
#define GENIUSLYRICSPROVIDER_H
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <QString>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QMutex>
|
|
||||||
|
|
||||||
#include "includes/shared_ptr.h"
|
|
||||||
#include "jsonlyricsprovider.h"
|
|
||||||
#include "lyricssearchrequest.h"
|
|
||||||
#include "lyricssearchresult.h"
|
|
||||||
|
|
||||||
class QNetworkReply;
|
|
||||||
class NetworkAccessManager;
|
|
||||||
class OAuthenticator;
|
|
||||||
|
|
||||||
class GeniusLyricsProvider : public JsonLyricsProvider {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit GeniusLyricsProvider(const SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
void Authenticate() override;
|
|
||||||
void ClearSession() override;
|
|
||||||
|
|
||||||
virtual bool authenticated() const override;
|
|
||||||
virtual bool use_authorization_header() const override;
|
|
||||||
virtual QByteArray authorization_header() const override;
|
|
||||||
|
|
||||||
protected Q_SLOTS:
|
|
||||||
void StartSearch(const int id, const LyricsSearchRequest &request) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct GeniusLyricsLyricContext {
|
|
||||||
explicit GeniusLyricsLyricContext() {}
|
|
||||||
QString artist;
|
|
||||||
QString title;
|
|
||||||
QUrl url;
|
|
||||||
};
|
|
||||||
struct GeniusLyricsSearchContext {
|
|
||||||
explicit GeniusLyricsSearchContext() : id(-1) {}
|
|
||||||
int id;
|
|
||||||
LyricsSearchRequest request;
|
|
||||||
QMap<QUrl, GeniusLyricsLyricContext> requests_lyric_;
|
|
||||||
LyricsSearchResults results;
|
|
||||||
};
|
|
||||||
|
|
||||||
using GeniusLyricsSearchContextPtr = SharedPtr<GeniusLyricsSearchContext>;
|
|
||||||
|
|
||||||
private:
|
|
||||||
JsonObjectResult ParseJsonObject(QNetworkReply *reply);
|
|
||||||
void EndSearch(GeniusLyricsSearchContextPtr search, const GeniusLyricsLyricContext &lyric = GeniusLyricsLyricContext());
|
|
||||||
void EndSearch(const int id, const LyricsSearchRequest &request, const LyricsSearchResults &results = LyricsSearchResults());
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void OAuthFinished(const bool success, const QString &error);
|
|
||||||
void HandleSearchReply(QNetworkReply *reply, const int id);
|
|
||||||
void HandleLyricReply(QNetworkReply *reply, const int search_id, const QUrl &url);
|
|
||||||
|
|
||||||
private:
|
|
||||||
OAuthenticator *oauth_;
|
|
||||||
mutable QMutex mutex_access_token_;
|
|
||||||
QMap<int, SharedPtr<GeniusLyricsSearchContext>> requests_search_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // GENIUSLYRICSPROVIDER_H
|
|
||||||
@@ -57,11 +57,20 @@
|
|||||||
#include "covermanager/currentalbumcoverloader.h"
|
#include "covermanager/currentalbumcoverloader.h"
|
||||||
#include "covermanager/albumcoverloaderresult.h"
|
#include "covermanager/albumcoverloaderresult.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mpris2_player.h"
|
#include "mpris2_player.h"
|
||||||
#include "mpris2_playlists.h"
|
#include "mpris2_playlists.h"
|
||||||
#include "mpris2_root.h"
|
#include "mpris2_root.h"
|
||||||
#include "mpris2_tracklist.h"
|
#include "mpris2_tracklist.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
QDBusArgument &operator<<(QDBusArgument &arg, const MprisPlaylist &playlist) {
|
QDBusArgument &operator<<(QDBusArgument &arg, const MprisPlaylist &playlist) {
|
||||||
|
|||||||
@@ -60,12 +60,21 @@ using MprisPlaylistList = QList<MprisPlaylist>;
|
|||||||
Q_DECLARE_METATYPE(MprisPlaylist)
|
Q_DECLARE_METATYPE(MprisPlaylist)
|
||||||
Q_DECLARE_METATYPE(MprisPlaylistList)
|
Q_DECLARE_METATYPE(MprisPlaylistList)
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct MaybePlaylist {
|
struct MaybePlaylist {
|
||||||
bool valid;
|
bool valid;
|
||||||
MprisPlaylist playlist;
|
MprisPlaylist playlist;
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(MaybePlaylist)
|
Q_DECLARE_METATYPE(MaybePlaylist)
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
QDBusArgument &operator<<(QDBusArgument &arg, const MprisPlaylist &playlist);
|
QDBusArgument &operator<<(QDBusArgument &arg, const MprisPlaylist &playlist);
|
||||||
const QDBusArgument &operator>>(const QDBusArgument &arg, MprisPlaylist &playlist);
|
const QDBusArgument &operator>>(const QDBusArgument &arg, MprisPlaylist &playlist);
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ void LastFMImport::ImportData(const bool lastplayed, const bool playcount) {
|
|||||||
|
|
||||||
void LastFMImport::FlushRequests() {
|
void LastFMImport::FlushRequests() {
|
||||||
|
|
||||||
if (!recent_tracks_requests_.isEmpty()) {
|
if (!recent_tracks_requests_.isEmpty() && (!playcount_ || (playcount_total_ > 0 || top_tracks_requests_.isEmpty()))) {
|
||||||
SendGetRecentTracksRequest(recent_tracks_requests_.dequeue());
|
SendGetRecentTracksRequest(recent_tracks_requests_.dequeue());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -519,8 +519,7 @@ void LastFMImport::GetTopTracksRequestFinished(QNetworkReply *reply, const int p
|
|||||||
|
|
||||||
void LastFMImport::UpdateTotalCheck() {
|
void LastFMImport::UpdateTotalCheck() {
|
||||||
|
|
||||||
if ((!playcount_ || playcount_total_ > 0) && (!lastplayed_ || lastplayed_total_ > 0))
|
Q_EMIT UpdateTotal(lastplayed_total_, playcount_total_);
|
||||||
Q_EMIT UpdateTotal(lastplayed_total_, playcount_total_);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ void BackendSettingsPage::Load() {
|
|||||||
|
|
||||||
ui_->checkbox_bs2b->setChecked(s.value(kBS2B, false).toBool());
|
ui_->checkbox_bs2b->setChecked(s.value(kBS2B, false).toBool());
|
||||||
|
|
||||||
|
ui_->checkbox_playbin3->setChecked(s.value(kPlaybin3, true).toBool());
|
||||||
|
|
||||||
ui_->checkbox_http2->setChecked(s.value(kHTTP2, false).toBool());
|
ui_->checkbox_http2->setChecked(s.value(kHTTP2, false).toBool());
|
||||||
ui_->checkbox_strict_ssl->setChecked(s.value(kStrictSSL, false).toBool());
|
ui_->checkbox_strict_ssl->setChecked(s.value(kStrictSSL, false).toBool());
|
||||||
|
|
||||||
@@ -440,6 +442,8 @@ void BackendSettingsPage::Save() {
|
|||||||
|
|
||||||
s.setValue(kBS2B, ui_->checkbox_bs2b->isChecked());
|
s.setValue(kBS2B, ui_->checkbox_bs2b->isChecked());
|
||||||
|
|
||||||
|
s.setValue(kPlaybin3, ui_->checkbox_playbin3->isChecked());
|
||||||
|
|
||||||
s.setValue(kHTTP2, ui_->checkbox_http2->isChecked());
|
s.setValue(kHTTP2, ui_->checkbox_http2->isChecked());
|
||||||
s.setValue(kStrictSSL, ui_->checkbox_strict_ssl->isChecked());
|
s.setValue(kStrictSSL, ui_->checkbox_strict_ssl->isChecked());
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_alsaplugin">
|
<spacer name="spacer_alsaplugin">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_exclusive_mode">
|
<spacer name="spacer_exclusive_mode">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -265,7 +265,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_channels">
|
<spacer name="spacer_channels">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -285,6 +285,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkbox_playbin3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use playbin3 when available</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkbox_http2">
|
<widget class="QCheckBox" name="checkbox_http2">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
@@ -379,7 +386,7 @@
|
|||||||
<item row="2" column="2">
|
<item row="2" column="2">
|
||||||
<spacer name="spacer_buffer_3">
|
<spacer name="spacer_buffer_3">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -392,7 +399,7 @@
|
|||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<spacer name="spacer_buffer_2">
|
<spacer name="spacer_buffer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -405,7 +412,7 @@
|
|||||||
<item row="0" column="2">
|
<item row="0" column="2">
|
||||||
<spacer name="spacer_buffer_1">
|
<spacer name="spacer_buffer_1">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -429,7 +436,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_buffer_defaults">
|
<spacer name="spacer_buffer_defaults">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -545,7 +552,7 @@
|
|||||||
<number>600</number>
|
<number>600</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sticky_center" stdset="0">
|
<property name="sticky_center" stdset="0">
|
||||||
<number>600</number>
|
<number>600</number>
|
||||||
@@ -578,7 +585,7 @@
|
|||||||
<number>600</number>
|
<number>600</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sticky_center" stdset="0">
|
<property name="sticky_center" stdset="0">
|
||||||
<number>600</number>
|
<number>600</number>
|
||||||
@@ -664,7 +671,7 @@
|
|||||||
<number>-230</number>
|
<number>-230</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sticky_center" stdset="0">
|
<property name="sticky_center" stdset="0">
|
||||||
<number>-230</number>
|
<number>-230</number>
|
||||||
@@ -769,7 +776,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_fading_1">
|
<spacer name="spacer_fading_1">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -820,7 +827,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_fading_duration_1">
|
<spacer name="spacer_fading_duration_1">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -838,7 +845,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<spacer name="spacer_bottom">
|
<spacer name="spacer_bottom">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@@ -873,6 +880,7 @@
|
|||||||
<tabstop>checkbox_channels</tabstop>
|
<tabstop>checkbox_channels</tabstop>
|
||||||
<tabstop>spinbox_channels</tabstop>
|
<tabstop>spinbox_channels</tabstop>
|
||||||
<tabstop>checkbox_bs2b</tabstop>
|
<tabstop>checkbox_bs2b</tabstop>
|
||||||
|
<tabstop>checkbox_playbin3</tabstop>
|
||||||
<tabstop>checkbox_http2</tabstop>
|
<tabstop>checkbox_http2</tabstop>
|
||||||
<tabstop>checkbox_strict_ssl</tabstop>
|
<tabstop>checkbox_strict_ssl</tabstop>
|
||||||
<tabstop>spinbox_bufferduration</tabstop>
|
<tabstop>spinbox_bufferduration</tabstop>
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ void CoversSettingsPage::Load() {
|
|||||||
for (CoverProvider *provider : std::as_const(cover_providers_sorted)) {
|
for (CoverProvider *provider : std::as_const(cover_providers_sorted)) {
|
||||||
QListWidgetItem *item = new QListWidgetItem(ui_->providers);
|
QListWidgetItem *item = new QListWidgetItem(ui_->providers);
|
||||||
item->setText(provider->name());
|
item->setText(provider->name());
|
||||||
item->setCheckState(provider->is_enabled() ? Qt::Checked : Qt::Unchecked);
|
item->setCheckState(provider->enabled() ? Qt::Checked : Qt::Unchecked);
|
||||||
item->setForeground(provider->is_enabled() ? palette().color(QPalette::Active, QPalette::Text) : palette().color(QPalette::Disabled, QPalette::Text));
|
item->setForeground(provider->enabled() ? palette().color(QPalette::Active, QPalette::Text) : palette().color(QPalette::Disabled, QPalette::Text));
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings s;
|
Settings s;
|
||||||
|
|||||||
@@ -158,7 +158,12 @@ JsonBaseRequest::JsonObjectResult SubsonicBaseRequest::ParseJsonObject(QNetworkR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.json_object = json_document.object();
|
if (json_object.contains("subsonic-response"_L1) && json_object["subsonic-response"_L1].isObject()) {
|
||||||
|
result.json_object = json_object["subsonic-response"_L1].toObject();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.json_object = json_object;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ constexpr char kID3v2_OriginalReleaseTime[] = "TDOR";
|
|||||||
constexpr char kID3v2_OriginalReleaseYear[] = "TORY";
|
constexpr char kID3v2_OriginalReleaseYear[] = "TORY";
|
||||||
constexpr char kID3v2_UnsychronizedLyrics[] = "USLT";
|
constexpr char kID3v2_UnsychronizedLyrics[] = "USLT";
|
||||||
constexpr char kID3v2_CoverArt[] = "APIC";
|
constexpr char kID3v2_CoverArt[] = "APIC";
|
||||||
constexpr char kID3v2_CommercialFrame[] = "COMM";
|
|
||||||
constexpr char kID3v2_FMPS_Playcount[] = "FMPS_Playcount";
|
constexpr char kID3v2_FMPS_Playcount[] = "FMPS_Playcount";
|
||||||
constexpr char kID3v2_FMPS_Rating[] = "FMPS_Rating";
|
constexpr char kID3v2_FMPS_Rating[] = "FMPS_Rating";
|
||||||
constexpr char kID3v2_Unique_File_Identifier[] = "UFID";
|
constexpr char kID3v2_Unique_File_Identifier[] = "UFID";
|
||||||
@@ -337,6 +336,7 @@ TagReaderResult TagReaderTagLib::Read(SharedPtr<TagLib::FileRef> fileref, Song *
|
|||||||
song->set_genre(tag->genre());
|
song->set_genre(tag->genre());
|
||||||
song->set_year(static_cast<int>(tag->year()));
|
song->set_year(static_cast<int>(tag->year()));
|
||||||
song->set_track(static_cast<int>(tag->track()));
|
song->set_track(static_cast<int>(tag->track()));
|
||||||
|
song->set_comment(tag->comment());
|
||||||
song->set_valid(true);
|
song->set_valid(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,16 +616,6 @@ void TagReaderTagLib::ParseID3v2Tags(TagLib::ID3v2::Tag *tag, QString *disc, QSt
|
|||||||
|
|
||||||
if (map.contains(kID3v2_CoverArt) && song->url().isLocalFile()) song->set_art_embedded(true);
|
if (map.contains(kID3v2_CoverArt) && song->url().isLocalFile()) song->set_art_embedded(true);
|
||||||
|
|
||||||
// Find a suitable comment tag. For now we ignore iTunNORM comments.
|
|
||||||
for (uint i = 0; i < map[kID3v2_CommercialFrame].size(); ++i) {
|
|
||||||
const TagLib::ID3v2::CommentsFrame *frame = dynamic_cast<const TagLib::ID3v2::CommentsFrame*>(map[kID3v2_CommercialFrame][i]);
|
|
||||||
|
|
||||||
if (frame && TagLibStringToQString(frame->description()) != "iTunNORM"_L1) {
|
|
||||||
song->set_comment(TagLibStringToQString(frame->text()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TagLib::ID3v2::UserTextIdentificationFrame *frame_fmps_playcount = TagLib::ID3v2::UserTextIdentificationFrame::find(tag, kID3v2_FMPS_Playcount)) {
|
if (TagLib::ID3v2::UserTextIdentificationFrame *frame_fmps_playcount = TagLib::ID3v2::UserTextIdentificationFrame::find(tag, kID3v2_FMPS_Playcount)) {
|
||||||
TagLib::StringList frame_field_list = frame_fmps_playcount->fieldList();
|
TagLib::StringList frame_field_list = frame_fmps_playcount->fieldList();
|
||||||
if (frame_field_list.size() > 1) {
|
if (frame_field_list.size() > 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user