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