testing arrpc server

This commit is contained in:
Malte Jürgens 2023-03-02 16:43:42 +01:00
parent b5435acdd8
commit 3540774c82
No known key found for this signature in database
GPG key ID: D29FBD5F93C0CFC3
8 changed files with 5696 additions and 4 deletions

5635
assets/arrpc.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,8 @@
<RCC>
<qresource>
<file>assets/userscript.js</file>
<file>assets/bridge_mod.js</file>
<file>assets/arrpc_bridge_mod.js</file>
<file>assets/arrpc.js</file>
<file>assets/de.shorsh.discord-screenaudio.png</file>
</qresource>
</RCC>

36
scripts/build_arrpc.sh Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/bash
set -e
cd "$(dirname "$0")/../submodules"
echo_status() {
echo
echo
echo "-> $1..."
}
if [ ! -d "arrpc" ]; then
echo_status "Cloning arRPC"
git clone https://github.com/OpenAsar/arrpc.git
cd arrpc
else
echo_status "Fetching arRPC changes"
cd arrpc
git fetch
fi
echo_status "Checking out latest commit"
git reset --hard HEAD
git checkout main
echo_status "Installing dependencies"
pnpm i -D @vercel/ncc
echo_status "Patching arRPC"
sed -i 's/"type": "module",//' package.json
echo_status "Building arRPC"
pnpm exec ncc build src/index.js
echo_status "Copying built file"
cp -v ./dist/index.js ../../assets/arrpc.js

View file

@ -9,6 +9,7 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QNetworkReply>
#include <QTemporaryFile>
#include <QTimer>
#include <QWebChannel>
#include <QWebEngineScript>
@ -35,11 +36,9 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
injectFile(&DiscordPage::injectScript, "userscript.js",
":/assets/userscript.js");
injectFile(&DiscordPage::injectScript, "bridge_mod.js",
":/assets/bridge_mod.js");
setupUserStyles();
setupArrpc();
}
void DiscordPage::setupPermissions() {
@ -294,3 +293,19 @@ void DiscordPage::javaScriptConsoleMessage(
}
UserScript *DiscordPage::userScript() { return &m_userScript; }
void DiscordPage::setupArrpc() {
QFile nodejs("/usr/bin/node");
if (nodejs.exists()) {
auto arrpcSource = QTemporaryFile::createNativeFile(":/assets/arrpc.js");
qDebug(mainLog).noquote()
<< "NodeJS found, starting arRPC located at" << arrpcSource->fileName();
m_arrpcProcess.setProcessChannelMode(QProcess::ForwardedChannels);
m_arrpcProcess.setProgram(nodejs.fileName());
m_arrpcProcess.setArguments(QStringList{arrpcSource->fileName()});
m_arrpcProcess.start();
injectFile(&DiscordPage::injectScript, "arrpc_bridge_mod.js",
":/assets/arrpc_bridge_mod.js");
}
}

View file

@ -5,6 +5,7 @@
#include <QDir>
#include <QFile>
#include <QNetworkAccessManager>
#include <QProcess>
#include <QStandardPaths>
#include <QWebEngineFullScreenRequest>
#include <QWebEnginePage>
@ -22,10 +23,12 @@ private:
QFile *m_userStylesFile;
QString m_userStylesContent;
QNetworkAccessManager m_networkAccessManager;
QProcess m_arrpcProcess;
const QDir m_configLocation =
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
void setupPermissions();
void setupUserStyles();
void setupArrpc();
void fetchUserStyles();
bool acceptNavigationRequest(const QUrl &url,
QWebEnginePage::NavigationType type,

1
submodules/arrpc Submodule

@ -0,0 +1 @@
Subproject commit 32b20feb2c994942a9de72b183ab0f4881c725c3

1
submodules/channel Submodule

@ -0,0 +1 @@
Subproject commit 6977815409b4c3c02d74a7aee3fc29f01d632feb