improve logging
This commit is contained in:
parent
8bd4d1896a
commit
fdb6145bbd
|
@ -1 +1,2 @@
|
||||||
/build
|
/build
|
||||||
|
.vscode
|
||||||
|
|
|
@ -30,6 +30,7 @@ set(discord-screenaudio_SRC
|
||||||
src/virtmic.cpp
|
src/virtmic.cpp
|
||||||
src/discordpage.cpp
|
src/discordpage.cpp
|
||||||
src/streamdialog.cpp
|
src/streamdialog.cpp
|
||||||
|
src/log.cpp
|
||||||
resources.qrc
|
resources.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,12 @@ const getAudioDevice = async (nameOfAudioDevice) => {
|
||||||
let devices = await navigator.mediaDevices.enumerateDevices();
|
let devices = await navigator.mediaDevices.enumerateDevices();
|
||||||
audioDevice = devices.find(({ label }) => label === nameOfAudioDevice);
|
audioDevice = devices.find(({ label }) => label === nameOfAudioDevice);
|
||||||
if (!audioDevice)
|
if (!audioDevice)
|
||||||
console.log(`Did not find '${nameOfAudioDevice}', trying again in 100ms`);
|
console.log(
|
||||||
|
`dsa: Did not find '${nameOfAudioDevice}', trying again in 100ms`
|
||||||
|
);
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
}
|
}
|
||||||
console.log(`Found '${nameOfAudioDevice}'`);
|
console.log(`dsa: Found '${nameOfAudioDevice}'`);
|
||||||
return audioDevice;
|
return audioDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "discordpage.h"
|
#include "discordpage.h"
|
||||||
|
#include "log.h"
|
||||||
#include "virtmic.h"
|
#include "virtmic.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -43,7 +44,7 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordPage::injectScript(QString source) {
|
void DiscordPage::injectScript(QString source) {
|
||||||
qDebug() << "[main ] Injecting " << source;
|
qDebug(mainLog) << "Injecting " << source;
|
||||||
|
|
||||||
QFile userscript(source);
|
QFile userscript(source);
|
||||||
|
|
||||||
|
@ -87,8 +88,8 @@ void DiscordPage::featurePermissionRequested(const QUrl &securityOrigin,
|
||||||
|
|
||||||
if (feature == QWebEnginePage::Feature::MediaAudioCapture) {
|
if (feature == QWebEnginePage::Feature::MediaAudioCapture) {
|
||||||
if (m_virtmicProcess.state() == QProcess::NotRunning) {
|
if (m_virtmicProcess.state() == QProcess::NotRunning) {
|
||||||
qDebug() << "[virtmic] Starting Virtmic with no target to make sure "
|
qDebug(virtmicLog) << "Starting Virtmic with no target to make sure "
|
||||||
"Discord can find all the audio devices";
|
"Discord can find all the audio devices";
|
||||||
m_virtmicProcess.start(QApplication::arguments()[0],
|
m_virtmicProcess.start(QApplication::arguments()[0],
|
||||||
{"--virtmic", "None"});
|
{"--virtmic", "None"});
|
||||||
}
|
}
|
||||||
|
@ -119,7 +120,7 @@ QWebEnginePage *DiscordPage::createWindow(QWebEnginePage::WebWindowType type) {
|
||||||
|
|
||||||
void DiscordPage::stopVirtmic() {
|
void DiscordPage::stopVirtmic() {
|
||||||
if (m_virtmicProcess.state() == QProcess::Running) {
|
if (m_virtmicProcess.state() == QProcess::Running) {
|
||||||
qDebug() << "[virtmic] Stopping Virtmic";
|
qDebug(virtmicLog) << "Stopping Virtmic";
|
||||||
m_virtmicProcess.kill();
|
m_virtmicProcess.kill();
|
||||||
m_virtmicProcess.waitForFinished();
|
m_virtmicProcess.waitForFinished();
|
||||||
}
|
}
|
||||||
|
@ -127,7 +128,7 @@ void DiscordPage::stopVirtmic() {
|
||||||
|
|
||||||
void DiscordPage::startVirtmic(QString target) {
|
void DiscordPage::startVirtmic(QString target) {
|
||||||
if (target != "None") {
|
if (target != "None") {
|
||||||
qDebug() << "[virtmic] Starting Virtmic with target" << target;
|
qDebug(virtmicLog) << "Starting Virtmic with target" << target;
|
||||||
m_virtmicProcess.start(QApplication::arguments()[0], {"--virtmic", target});
|
m_virtmicProcess.start(QApplication::arguments()[0], {"--virtmic", target});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,8 +144,10 @@ void DiscordPage::javaScriptConsoleMessage(
|
||||||
m_streamDialog.updateTargets();
|
m_streamDialog.updateTargets();
|
||||||
} else if (message == "!discord-screenaudio-stream-stopped") {
|
} else if (message == "!discord-screenaudio-stream-stopped") {
|
||||||
stopVirtmic();
|
stopVirtmic();
|
||||||
|
} else if (message.startsWith("dsa: ")) {
|
||||||
|
qDebug(userscriptLog) << message.mid(5).toUtf8().constData();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "[discord]" << message;
|
qDebug(discordLog) << message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(mainLog, "main");
|
||||||
|
Q_LOGGING_CATEGORY(discordLog, "discord");
|
||||||
|
Q_LOGGING_CATEGORY(userscriptLog, "userscript");
|
||||||
|
Q_LOGGING_CATEGORY(virtmicLog, "virtmic");
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(mainLog);
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(discordLog);
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(userscriptLog);
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(virtmicLog);
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
@ -12,6 +13,8 @@ int main(int argc, char *argv[]) {
|
||||||
QApplication::setApplicationVersion(DISCORD_SCEENAUDIO_VERSION_FULL);
|
QApplication::setApplicationVersion(DISCORD_SCEENAUDIO_VERSION_FULL);
|
||||||
QApplication::setDesktopFileName("de.shorsh.discord-screenaudio");
|
QApplication::setDesktopFileName("de.shorsh.discord-screenaudio");
|
||||||
|
|
||||||
|
qSetMessagePattern("[%{category}] %{message}");
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(
|
parser.setApplicationDescription(
|
||||||
"Custom Discord client with the ability to stream audio on Linux");
|
"Custom Discord client with the ability to stream audio on Linux");
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "virtmic.h"
|
#include "virtmic.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include <rohrkabel/loop/main.hpp>
|
#include <rohrkabel/loop/main.hpp>
|
||||||
#include <rohrkabel/registry/registry.hpp>
|
#include <rohrkabel/registry/registry.hpp>
|
||||||
|
@ -66,18 +67,18 @@ void start(QString _target) {
|
||||||
auto &parent = nodes.at(parent_id);
|
auto &parent = nodes.at(parent_id);
|
||||||
|
|
||||||
if (parent.props["node.name"].find(target) != std::string::npos) {
|
if (parent.props["node.name"].find(target) != std::string::npos) {
|
||||||
std::cout << "[virtmic] "
|
auto fl = port.info().props["audio.channel"] == "FL";
|
||||||
<< "Link : " << target << ":" << port_id << " -> ";
|
links.emplace(
|
||||||
|
port_id,
|
||||||
if (port.info().props["audio.channel"] == "FL") {
|
core.create<pipewire::link_factory>(
|
||||||
links.emplace(port_id, core.create<pipewire::link_factory>(
|
{fl ? virt_fl->info().id : virt_fr->info().id, port_id}));
|
||||||
{virt_fl->info().id, port_id}));
|
qDebug(virtmicLog) << QString("Link: %1:%2 -> %3")
|
||||||
std::cout << "[virtmic] " << virt_fl->info().id << std::endl;
|
.arg(QString::fromStdString(target))
|
||||||
} else {
|
.arg(port_id)
|
||||||
links.emplace(port_id, core.create<pipewire::link_factory>(
|
.arg(fl ? virt_fl->info().id
|
||||||
{virt_fr->info().id, port_id}));
|
: virt_fr->info().id)
|
||||||
std::cout << "[virtmic] " << virt_fr->info().id << std::endl;
|
.toUtf8()
|
||||||
}
|
.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -105,9 +106,11 @@ void start(QString _target) {
|
||||||
[&](const pipewire::global &global) {
|
[&](const pipewire::global &global) {
|
||||||
if (global.type == pipewire::node::type) {
|
if (global.type == pipewire::node::type) {
|
||||||
auto node = reg.bind<pipewire::node>(global.id);
|
auto node = reg.bind<pipewire::node>(global.id);
|
||||||
std::cout << "[virtmic] "
|
qDebug(virtmicLog) << QString("Added: %1")
|
||||||
<< "Added : " << node.info().props["node.name"]
|
.arg(QString::fromStdString(
|
||||||
<< std::endl;
|
node.info().props["node.name"]))
|
||||||
|
.toUtf8()
|
||||||
|
.data();
|
||||||
|
|
||||||
if (!nodes.count(global.id)) {
|
if (!nodes.count(global.id)) {
|
||||||
nodes.emplace(global.id, node.info());
|
nodes.emplace(global.id, node.info());
|
||||||
|
@ -141,8 +144,11 @@ void start(QString _target) {
|
||||||
[&](const std::uint32_t id) {
|
[&](const std::uint32_t id) {
|
||||||
if (nodes.count(id)) {
|
if (nodes.count(id)) {
|
||||||
auto info = nodes.at(id);
|
auto info = nodes.at(id);
|
||||||
std::cout << "[virtmic] "
|
qDebug(virtmicLog) << QString("Removed: %1")
|
||||||
<< "Removed: " << info.props["node.name"] << std::endl;
|
.arg(QString::fromStdString(
|
||||||
|
info.props["node.name"].data()))
|
||||||
|
.toUtf8()
|
||||||
|
.data();
|
||||||
nodes.erase(id);
|
nodes.erase(id);
|
||||||
}
|
}
|
||||||
if (ports.count(id)) {
|
if (ports.count(id)) {
|
||||||
|
|
Loading…
Reference in New Issue